Flutter: 从屏幕返回数据

class HomeScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Home Screen'),
      ),
      body: Center(
        child: FlatButton(
          onPressed: () async {
            final result = await Navigator.push(
              context,
              MaterialPageRoute(
                  builder: (context) => Scaffold(
                        body: Center(
                          child: FlatButton(
                            child: Text('返回'),
                            onPressed: () {
                              Navigator.pop(context, 'Yep!');
                            },
                          ),
                        ),
                      )),
            );

            print(result);
          },
          child: Text('跳转'),
        ),
      ),
    );
  }
}

猜你喜欢

转载自www.cnblogs.com/ajanuw/p/11029265.html
今日推荐