Flutter remote data acquisition interface UI refresh


Import
'Package: Flutter / material.dart' ; Import 'Package: HTTP / http.dart' AS HTTP; void main () => RunApp (the MyApp ()); class the MyApp the extends StatelessWidget { @override the Widget Build (BuildContext context) { // the TODO: Implement build // need to build a component material return MaterialApp ( title: 'remote data acquisition and analyzing the model' , Home: MyPage (), ); } } class MyPage the extends StatefulWidget { // must be rewritten the method returns to State @override State<StatefulWidget> createState() { // TODO: implement createState return MyState(); } } class MyState extends State<MyPage> { String ddddd = "ffffffff"; // @override // void setState(fn) { // // TODO: implement setState // super.setState(fn); // // } //必须重写build方法 - 返回一个部件 @override Widget build(BuildContext context) { // TODO: implement build return Scaffold( appbar: the AppBar ( title: the Text ( 'data transfer model' ), ), body: the Column ( Children: <the Widget> [ Container ( Child: GestureDetector ( Child: the Text (ddddd), // onTap in: fetchPost, // refresh interface // onTap in: fetchPost, // there is a need for a method, rather than a return value of the method onTap in: () { fetchPost () the then ((value) {. the setState (() { ddddd = value; }); } ); }, )) ], ), ); } } // Returns String, text displayed on the text member // call interface data acquisition server Future <String> fetchPost () {the async Final Response = the await http.get ( "HTTPS: / /wanandroid.com/wxarticle/chapters/json " ); Final Result = response.body; Print (Result); return Result; }

A simple demo

Guess you like

Origin www.cnblogs.com/gloryhope/p/11307056.html