SABDAR SHAIK
SABDAR SHAIK

Reputation: 671

Flutter Pass Objects from one page to other page

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 ?

Upvotes: 6

Views: 13760

Answers (1)

Shady Aziza
Shady Aziza

Reputation: 53347

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()),
    );
  }
}         

Upvotes: 20

Related Questions