
http | Dart Package
A composable, multi-platform, Future-based API for HTTP requests.
pub.dev
pubspec.yaml
dependencies:
http: ^0.12.2
main.dart
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: HttpApp(),
);
}
}
class HttpApp extends StatefulWidget {
@override
_HttpAppState createState() => _HttpAppState();
}
class _HttpAppState extends State<HttpApp> {
String result;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('앱바')),
body: Center(
child: Text('$result'),
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.file_download),
onPressed: () async {
var url = 'http://www.google.com';
var response = await http.get(url);
setState(() {
result = response.body;
});
},
),
);
}
}
'코딩(개발) > Flutter' 카테고리의 다른 글
| DatePicker (0) | 2021.02.09 |
|---|---|
| webview (0) | 2021.02.04 |
| AlertDialog (0) | 2021.02.04 |
| 탭 컨트롤러 (0) | 2021.02.04 |
| 앱 화면 기본 구성 (0) | 2021.02.03 |
댓글