dart - Drawer Avoid Infinite Activity Creation -


i use drawer each activity:

final mydrawer _drawer = new mydrawer();  class mydrawer extends statefulwidget {   @override   _mydrawerstate createstate() => new _mydrawerstate(); }  class _mydrawerstate extends state<mydrawer> {   @override   widget build(buildcontext context) {     return new drawer(       child: new listview(           children: <widget> [             new drawerheader(               child: new text("header"),             ),             new listtile(               leading: new icon(icons.home),               title: new text("home"),               ontap: () {                 navigator.popandpushnamed(context, "/");               },              ),             new listtile(                 leading: new icon(icons.android),                 title: new text("another page"),                 ontap: () {                   navigator.popandpushnamed(context, anotherpage.routename);                 },              ),new listtile(                 leading: new icon(icons.email),                 title: new text("third page"),                 ontap: () {                   navigator.popandpushnamed(context, thirdpage.routename);                 }             )           ]       ),     );   } } 

each page statefull widget , share same drawer:

drawer: _drawer 

i looking way have 1 instance activity instead create new activity each time menu item clicked, tried:

thirdpage.routename: (buildcontext context) =>         _thirdpage == null ? _thirdpage = new thirdpage(title: "third page") : _thirdpage 

and possible adapt drawer instance based on current activity?


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -