class - How to create Flutter route for Stateful Widget? -


i'm getting navigator operation requested context not include navigator. error log flutter app. examples see "stateless" widgets think may issue or code? how can route loginpage? here code without navigator or route...

 void main() {       runapp(new myapp());     }      final googlesignin = new googlesignin();     final fb = firebasedatabase.instance.reference();     final auth = firebaseauth.instance;      class myapp extends statefulwidget {       @override       _myappstate createstate() => new _myappstate();     }      class _myappstate extends state<myapp> {       string _platformversion = 'unknown';        @override       initstate() {         super.initstate();         initplatformstate();       }        // platform messages asynchronous, initialize in async method.       initplatformstate() async {         string platformversion;         // platform messages may fail, use try/catch platformexception.         try {           platformversion = await myfavkpopflutter.platformversion;         } on platformexception {           platformversion = 'failed platform version.';         }          // if widget removed tree while asynchronous platform         // message in flight, want discard reply rather calling         // setstate update our non-existent appearance.         if (!mounted) return;          setstate(() {           _platformversion = platformversion;         });       }        void myfavaction() {         setstate(() {           print("myfav");      //      fb.child("messages").orderbyvalue().onchildadded.listen((event event) {     //        print('child added: ${event.snapshot.value}');     //      });         });       }        void searchaction() {         setstate(() {           print("search");         });       }          @override       widget build(buildcontext context) {         if (auth.currentuser == null) {           return new materialapp(             routes: <string, widgetbuilder>{             '/settings': (buildcontext context) => new loginpage(),             },             home: new scaffold(               backgroundcolor: colors.white70,               appbar: new appbar(                 title: new text(                   "myfavkpop",                   style: new textstyle(                       color: colors.black,                       fontweight: fontweight.bold,                       fontsize: 25.00),                 ),                 backgroundcolor: colors.amber,               ),               body: new container(                   child: new center(                       child: new column(                 mainaxisalignment: mainaxisalignment.center,                 children: <widget>[                   new raisedbutton(                     onpressed: myfavaction,                     color: colors.lightblue,                     elevation: 20.00,                     splashcolor: colors.amber,                     child: new text(                       "myfav kpop",                       style: new textstyle(color: colors.black, fontsize: 20.00),                     ),                   ),                   new padding(padding: new edgeinsets.all(30.00)),                   new raisedbutton(                     onpressed: searchaction,                     color: colors.lightblue,                     elevation: 20.00,                     splashcolor: colors.amber,                     child: new text(                       "myfav search",                       style: new textstyle(color: colors.black, fontsize: 20.00),                     ),                   ),                   new padding(padding: new edgeinsets.all(30.00),                   ),                   new raisedbutton(                     onpressed: searchaction,                     elevation: 20.00,                     splashcolor: colors.amber,                     color: colors.lightblue,                     child: new text(                       "myfav friends",                       style: new textstyle(color: colors.black, fontsize: 20.00),                     ),                   ),                   new padding(                     padding: new edgeinsets.all(30.00),                   ),                   new raisedbutton(                     onpressed: searchaction,                     elevation: 20.00,                     splashcolor: colors.amber,                     color: colors.lightblue,                     child: new text(                       "myfav chat",                       style: new textstyle(color: colors.black, fontsize: 20.00),                     ),                   ),                   new padding(                     padding: new edgeinsets.all(30.00),                   ),                   new raisedbutton(                     onpressed: searchaction,                     elevation: 20.00,                     splashcolor: colors.amber,                     color: colors.lightblue,                     child: new text(                       "myfav #1's",                       style: new textstyle(color: colors.black, fontsize: 20.00),                     ),                   )                 ],               ))),               floatingactionbutton: new floatingactionbutton(                   child: new text(                     "log out",                     style: new textstyle(fontweight: fontweight.bold, fontsize: 12.00),                   ),                   onpressed: () => navigator.of(context).pushnamed('/settings'),,             ),           ));         }        }     }      class loginpage extends statelesswidget {   @override   widget build(buildcontext context) {     return new scaffold(       appbar: new appbar(         title: new text("login / signup"),       ),       body: new container(         child: new center(           child: new column(             mainaxisalignment: mainaxisalignment.center,             children: <widget>[               new textfield(                 decoration: new inputdecoration(                     hinttext: "e m l    d d r e s s"),               ),               new padding(padding: new edgeinsets.all(15.00)),               new textfield(                 obscuretext: true,                 decoration:                 new inputdecoration(hinttext: "p s s w o r d"),               ),               new padding(padding: new edgeinsets.all(15.00)),               new textfield(                 decoration:                 new inputdecoration(hinttext: "u s e r n m e"),               ),               new raisedbutton(                 onpressed: null,                 child: new text("signup"),               ),               new padding(padding: new edgeinsets.all(15.00)),               new raisedbutton(                 onpressed: null,                 child: new text("login"),               ),               new padding(padding: new edgeinsets.all(15.00)),               new raisedbutton(                 onpressed: null,                 child: new text("facebook"),               ),               new padding(padding: new edgeinsets.all(5.00)),               new raisedbutton(                 onpressed: null,                 child: new text("google"),               )             ],           ),         ),         margin: new edgeinsets.all(15.00),       ),     );   } } 

**** edit here error log i'm getting...

══╡ exception caught gesture ╞═══════════════════════════════════════════════════════════════════ following assertion thrown while handling gesture: navigator operation requested context not include navigator. context used push or pop routes navigator must of widget descendant of navigator widget.

════════════════════════════════════════════════════════════════════════════════════════════════════

you stated in title problem navigating statefulwidget while in post asking how navigate statelesswidget loginpage.

anyhow, should able implement navigating same way regardless of state matter.

try follow following flow taken app working on.

//local imports //mytabs.dart define home page statefulwidget tabbarview  import 'mytabs.dart' first; 

.....

//my main function start app      void main() {       runapp( new materialapp(         home: new signin(),         routes: <string, widgetbuilder>{           "/mytabs" : (buildcontext context)=> new first.mytabs(),           //add more routes here         },        ));     } 

my app starts signin page, have created simpler 1 have show idea

class signin extends statelesswidget {   @override   widget build(buildcontext context) {   return new scaffold(     appbar: new appbar(       title: new text("sign in"),     ),     body: new iconbutton(icon: new icon(icons.arrow_forward), onpressed: (){navigator.of(context).pushnamed("/mytabs");}),   ) 

i hope of help, try follow flow in code , let me know how went.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -