Flutter

flutter入门到放弃3

2023-08-22  本文已影响0人  xiaotimel

页面跳转

MaterialApp 指定Map路线名称,与Android中注册AndroidManifest.xml类似

void main() {
  runApp(MaterialApp(
    home: const MyAppHome(), // Becomes the route named '/'.
    routes: <String, WidgetBuilder>{
      '/a': (context) => const MyPage(title: 'page A'),
      '/b': (context) => const MyPage(title: 'page B'),
      '/c': (context) => const MyPage(title: 'page C'),
    },
  ));
}

导入第三方包

在项目中找到pubspec.yaml文件,里面包含

异步操作

Future<void> loadData() async {

  var dataURL = Uri.parse('[https://jsonplaceholder.typicode.com/posts');](https://jsonplaceholder.typicode.com/posts');)

  http.Response response = await http.get(dataURL);

  setState(() {

    widgets = jsonDecode(response.body);

  });

}
上一篇下一篇

猜你喜欢

热点阅读