问题
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 ?
回答1:
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**
}
回答2:
You can store JsonData “state” in a model class and use it in the other screen.
来源:https://stackoverflow.com/questions/55956470/how-to-pass-json-data-to-another-screen-in-flutter