简体   繁体   中英

How to pass Json data to another screen in flutter

List results;      
setState(() {
          var resBody = json.decode(res.body);
          print('Response body: ${resBody}');
          results = resBody;
        });
        Navigator.push(
            context,
            MaterialPageRoute(
              builder: (context) => SecondScreen(jsondata: results,),
            ));

results is a jsondata and pass it to the second screen as jsondata

In secondscreen how to retrieve jsondata ?

This may help you. Let me know

class SecondScreen extends StatefulWidget {

  final List jsondata;

  SecondScreen({Key key, this.jsondata}) : super(key: key);

  @override
  _SecondScreenState createState() => _SecondScreenState();
}

class _SecondScreenState extends State<SecondScreen> {

    // use jsondata here in widget here like this,
**widget.jsondata**

}

您可以将JsonData“状态”存储在模型类中,并在另一个屏幕中使用它。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM