How to navigate the data one page to another page in flutter ?

 When the case is you show the data from firebase database and want to navigate that data another page then first you know about the


Navigator widget

there are lots of cases on how to use navigators like when declaring the routes or direct call the class.

In our case, we use a navigator to switch another class directly and send the data.


First like on button pressed we send the data to another class so,

onPressed(){
Navigator.push(context, MaterialPageRoute
(builder: (BuildContext context)=>
Test(title: snapshot.data[index].title,
}


In this case, on pressed send title that fetches from the firebase database snapshot for Test class
then when we want this title on  Test() class then

class Test extends StatefulWidget {
  Test({Key key, this.title , this.description}) : super(key: key);
  final String title;
  @override  _Test createState() => _Test();
}

class _Test extends State<Test> {
  @override  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: <Widget>[
          SizedBox(height: 100,),
          Container(height: 100,
           child: Text(widget.title)
          ),
       ),
        ],
      ),
    );
  }
}
here you clear how to use the title in whole class wherever you want.








Comments