1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| import 'package:flutter/material.dart'; import 'package:dio/dio.dart';
class HttpDio extends StatefulWidget { HttpDio({Key key}) : super(key: key);
@override _HttpDioState createState() => _HttpDioState(); }
class _HttpDioState extends State<HttpDio> { Dio _dio = new Dio(); @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: new AppBar( title: Text('http请求--HttpClient'), ), body: Container( alignment: Alignment.center, child: FutureBuilder( future: _dio.get("https://api.github.com/orgs/flutterchina/repos"), builder: (BuildContext context, AsyncSnapshot snapshot) { if (snapshot.connectionState == ConnectionState.done) { Response response = snapshot.data; if (snapshot.hasError) { return Text(snapshot.error.toString()); } return ListView( children: response.data .map<Widget>((e) => ListTile(title: Text(e["full_name"]))) .toList(), ); } return CircularProgressIndicator(); }, ), ), ), ); } }
|