Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Pass Objects from one page to other page

Tags:

flutter

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 ?

like image 313
SABDAR SHAIK Avatar asked Mar 11 '18 06:03

SABDAR SHAIK


People also ask

How do I pass values from one widget to another in flutter?

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.

How do you pass an object from one class to another in flutter?

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.


1 Answers

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()),
    );
  }
}         
like image 104
Shady Aziza Avatar answered Oct 27 '22 16:10

Shady Aziza