dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
url_launcher: ^5.0.1
http: ^0.12.0+1
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'http請求範例',
home: new Scaffold(
appBar: new AppBar(
title: new Text('http請求範例'),
),
body: new Center(
child: new RaisedButton(
onPressed: (){
var url='https://schoolweb.tn.edu.tw';
http.get(url).then((response){
print("狀態:${response.statusCode}");
print("正文:${response.body}");
});
},
child: new Text('發起http請求'),
),
),
),
);
}
}
執行結果可以從編輯器下方的「偵錯主控台」觀看(並不會呈現在主機上)