How to pass json Object from one page to another page in flutter ?
Just while routing i will able to pass parameters in routing path
but i need to pass some custom json object and display in other page ?
Steps to Pass Data to Stateful Widget in Flutter To pass data to stateful widget, first of all, create two pages. Now from the first page open the second page and pass the data. Inside the second page, access the variable using the widget. For example widget.
In navigator you can pass data or object which you want to send to other class. For example, // Data need to sent second screen class Person { final String name; final String age; Person(this.name, this. age); } // Navigate to second screen with data Navigator.
You can pass the object in the constructor
Navigator.push(
context,
new MaterialPageRoute(
builder: (__) => new HomeScreen(myObject:object)));
...
class HomeScreen extends StatefulWidget {
var myObject;
HomeScreen({
this.myObject
});
@override
_HomeScreenState createState() => new _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
@override
Widget build(BuildContext context) {
return new Container(
child: new Text(widget.myObject.toString()),
);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With