Flutter buttons in drawer give error when tapped instead of navigating to the proper page












0















I am trying to have some buttons in a drawer that the user can top on and be taken to another page/widget. However, it gives me an error and doesn't work. I'm not really sure what the issue is considering I'm doing this in another project and it works, additionally I checked the cookbook on Flutter's docs for how to do navigation and it also looks fine based on that.



Here is my drawer code which is inside a Scaffold widget:



Drawer(
child: Column(
children: <Widget>[
AppBar(
automaticallyImplyLeading: false,
title: Text('Looped In'),
),
ListTile(
leading: Icon(Icons.info),
title: Text('About'),
onTap: () {
Navigator.of(context).pushNamed('/about');
},
),
],
),
),


Here is the error traceback that I'm getting



flutter: The following assertion was thrown while handling a gesture:
flutter: Navigator operation requested with a context that does not include a Navigator.
flutter: The context used to push or pop routes from the Navigator must be that of a widget that is a
flutter: descendant of a Navigator widget.
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #0 Navigator.of.<anonymous closure> (package:flutter/src/widgets/navigator.dart:1273:9)
flutter: #1 Navigator.of (package:flutter/src/widgets/navigator.dart:1280:6)
flutter: #2 MyAppState.build.<anonymous closure> (file:///Users/garrettlove/Documents/learn/Flutter/loopt_in/lib/main.dart:59:29)
flutter: #3 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:507:14)
flutter: #4 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:562:30)
flutter: #5 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
flutter: #6 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:242:9)
flutter: #7 TapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:204:7)
flutter: #8 GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27)
flutter: #9 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:147:20)
flutter: #10 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:121:22)
flutter: #11 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:101:7)
flutter: #12 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:64:7)
flutter: #13 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:48:7)
flutter: #14 _invoke1 (dart:ui/hooks.dart:153:13)
flutter: #15 _dispatchPointerDataPacket (dart:ui/hooks.dart:107:5)
flutter:
flutter: Handler: onTap
flutter: Recognizer:
flutter: TapGestureRecognizer#2d408(debugOwner: GestureDetector, state: ready, won arena, finalPosition:
flutter: Offset(98.5, 222.5), sent tap down)


EDIT
Here is everything I have:



import 'package:flutter/material.dart';

import './pages/home.dart';
import './pages/categories.dart';
import './pages/about.dart';
import './pages/contact.dart';

void main() => runApp(new MyApp());

class MyApp extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return MyAppState();
}
}

class MyAppState extends State<MyApp> {
int _selectedTab = 0;
final _pageOptions = [
HomePage(),
CatPage(),
];

Widget _buildDrawer(BuildContext context) {
return Drawer(
child: Column(
children: <Widget>[
AppBar(
automaticallyImplyLeading: false,
backgroundColor: Color.fromRGBO(135, 142, 136, 1.0),
title: Text('Looped In'),
),
ListTile(
leading: Icon(Icons.info, color: Color.fromRGBO(247, 203, 21, 1.0),),
title: Text('About'),
onTap: () {
//Navigator.of(context).pushNamed('/about');
Navigator.of(context).push(MaterialPageRoute(builder: (context) => AboutPage()));
},
),
],
),
);
}

@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
accentColor: Color.fromRGBO(245, 93, 62, 1.0),
primaryTextTheme: TextTheme(
title: TextStyle(color: Colors.white),
),
),
routes: <String, WidgetBuilder>{
'/home': (BuildContext context) => HomePage(),
'/about': (BuildContext context) => AboutPage(),
'/contact': (BuildContext context) => ContactPage(),
},
home: Scaffold(
drawer: _buildDrawer(context),
appBar: AppBar(
title: Text('Looped In'),
backgroundColor: Color.fromRGBO(
135,
142,
136,
1.0,
),
),
body: Container(
padding: EdgeInsets.symmetric(horizontal: 10.0),
child: _pageOptions[_selectedTab],
),
bottomNavigationBar: BottomNavigationBar(
currentIndex: _selectedTab,
onTap: (int index) {
setState(() {
_selectedTab = index;
});
},
fixedColor: Color.fromRGBO(118, 190, 208, 1.0),
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text('Everything'),
),
BottomNavigationBarItem(
icon: Icon(Icons.category),
title: Text('Categories'),
),
],
),
),
);
}
}









share|improve this question





























    0















    I am trying to have some buttons in a drawer that the user can top on and be taken to another page/widget. However, it gives me an error and doesn't work. I'm not really sure what the issue is considering I'm doing this in another project and it works, additionally I checked the cookbook on Flutter's docs for how to do navigation and it also looks fine based on that.



    Here is my drawer code which is inside a Scaffold widget:



    Drawer(
    child: Column(
    children: <Widget>[
    AppBar(
    automaticallyImplyLeading: false,
    title: Text('Looped In'),
    ),
    ListTile(
    leading: Icon(Icons.info),
    title: Text('About'),
    onTap: () {
    Navigator.of(context).pushNamed('/about');
    },
    ),
    ],
    ),
    ),


    Here is the error traceback that I'm getting



    flutter: The following assertion was thrown while handling a gesture:
    flutter: Navigator operation requested with a context that does not include a Navigator.
    flutter: The context used to push or pop routes from the Navigator must be that of a widget that is a
    flutter: descendant of a Navigator widget.
    flutter:
    flutter: When the exception was thrown, this was the stack:
    flutter: #0 Navigator.of.<anonymous closure> (package:flutter/src/widgets/navigator.dart:1273:9)
    flutter: #1 Navigator.of (package:flutter/src/widgets/navigator.dart:1280:6)
    flutter: #2 MyAppState.build.<anonymous closure> (file:///Users/garrettlove/Documents/learn/Flutter/loopt_in/lib/main.dart:59:29)
    flutter: #3 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:507:14)
    flutter: #4 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:562:30)
    flutter: #5 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
    flutter: #6 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:242:9)
    flutter: #7 TapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:204:7)
    flutter: #8 GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27)
    flutter: #9 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:147:20)
    flutter: #10 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:121:22)
    flutter: #11 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:101:7)
    flutter: #12 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:64:7)
    flutter: #13 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:48:7)
    flutter: #14 _invoke1 (dart:ui/hooks.dart:153:13)
    flutter: #15 _dispatchPointerDataPacket (dart:ui/hooks.dart:107:5)
    flutter:
    flutter: Handler: onTap
    flutter: Recognizer:
    flutter: TapGestureRecognizer#2d408(debugOwner: GestureDetector, state: ready, won arena, finalPosition:
    flutter: Offset(98.5, 222.5), sent tap down)


    EDIT
    Here is everything I have:



    import 'package:flutter/material.dart';

    import './pages/home.dart';
    import './pages/categories.dart';
    import './pages/about.dart';
    import './pages/contact.dart';

    void main() => runApp(new MyApp());

    class MyApp extends StatefulWidget {
    @override
    State<StatefulWidget> createState() {
    return MyAppState();
    }
    }

    class MyAppState extends State<MyApp> {
    int _selectedTab = 0;
    final _pageOptions = [
    HomePage(),
    CatPage(),
    ];

    Widget _buildDrawer(BuildContext context) {
    return Drawer(
    child: Column(
    children: <Widget>[
    AppBar(
    automaticallyImplyLeading: false,
    backgroundColor: Color.fromRGBO(135, 142, 136, 1.0),
    title: Text('Looped In'),
    ),
    ListTile(
    leading: Icon(Icons.info, color: Color.fromRGBO(247, 203, 21, 1.0),),
    title: Text('About'),
    onTap: () {
    //Navigator.of(context).pushNamed('/about');
    Navigator.of(context).push(MaterialPageRoute(builder: (context) => AboutPage()));
    },
    ),
    ],
    ),
    );
    }

    @override
    Widget build(BuildContext context) {
    return MaterialApp(
    theme: ThemeData(
    accentColor: Color.fromRGBO(245, 93, 62, 1.0),
    primaryTextTheme: TextTheme(
    title: TextStyle(color: Colors.white),
    ),
    ),
    routes: <String, WidgetBuilder>{
    '/home': (BuildContext context) => HomePage(),
    '/about': (BuildContext context) => AboutPage(),
    '/contact': (BuildContext context) => ContactPage(),
    },
    home: Scaffold(
    drawer: _buildDrawer(context),
    appBar: AppBar(
    title: Text('Looped In'),
    backgroundColor: Color.fromRGBO(
    135,
    142,
    136,
    1.0,
    ),
    ),
    body: Container(
    padding: EdgeInsets.symmetric(horizontal: 10.0),
    child: _pageOptions[_selectedTab],
    ),
    bottomNavigationBar: BottomNavigationBar(
    currentIndex: _selectedTab,
    onTap: (int index) {
    setState(() {
    _selectedTab = index;
    });
    },
    fixedColor: Color.fromRGBO(118, 190, 208, 1.0),
    items: [
    BottomNavigationBarItem(
    icon: Icon(Icons.home),
    title: Text('Everything'),
    ),
    BottomNavigationBarItem(
    icon: Icon(Icons.category),
    title: Text('Categories'),
    ),
    ],
    ),
    ),
    );
    }
    }









    share|improve this question



























      0












      0








      0








      I am trying to have some buttons in a drawer that the user can top on and be taken to another page/widget. However, it gives me an error and doesn't work. I'm not really sure what the issue is considering I'm doing this in another project and it works, additionally I checked the cookbook on Flutter's docs for how to do navigation and it also looks fine based on that.



      Here is my drawer code which is inside a Scaffold widget:



      Drawer(
      child: Column(
      children: <Widget>[
      AppBar(
      automaticallyImplyLeading: false,
      title: Text('Looped In'),
      ),
      ListTile(
      leading: Icon(Icons.info),
      title: Text('About'),
      onTap: () {
      Navigator.of(context).pushNamed('/about');
      },
      ),
      ],
      ),
      ),


      Here is the error traceback that I'm getting



      flutter: The following assertion was thrown while handling a gesture:
      flutter: Navigator operation requested with a context that does not include a Navigator.
      flutter: The context used to push or pop routes from the Navigator must be that of a widget that is a
      flutter: descendant of a Navigator widget.
      flutter:
      flutter: When the exception was thrown, this was the stack:
      flutter: #0 Navigator.of.<anonymous closure> (package:flutter/src/widgets/navigator.dart:1273:9)
      flutter: #1 Navigator.of (package:flutter/src/widgets/navigator.dart:1280:6)
      flutter: #2 MyAppState.build.<anonymous closure> (file:///Users/garrettlove/Documents/learn/Flutter/loopt_in/lib/main.dart:59:29)
      flutter: #3 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:507:14)
      flutter: #4 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:562:30)
      flutter: #5 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
      flutter: #6 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:242:9)
      flutter: #7 TapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:204:7)
      flutter: #8 GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27)
      flutter: #9 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:147:20)
      flutter: #10 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:121:22)
      flutter: #11 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:101:7)
      flutter: #12 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:64:7)
      flutter: #13 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:48:7)
      flutter: #14 _invoke1 (dart:ui/hooks.dart:153:13)
      flutter: #15 _dispatchPointerDataPacket (dart:ui/hooks.dart:107:5)
      flutter:
      flutter: Handler: onTap
      flutter: Recognizer:
      flutter: TapGestureRecognizer#2d408(debugOwner: GestureDetector, state: ready, won arena, finalPosition:
      flutter: Offset(98.5, 222.5), sent tap down)


      EDIT
      Here is everything I have:



      import 'package:flutter/material.dart';

      import './pages/home.dart';
      import './pages/categories.dart';
      import './pages/about.dart';
      import './pages/contact.dart';

      void main() => runApp(new MyApp());

      class MyApp extends StatefulWidget {
      @override
      State<StatefulWidget> createState() {
      return MyAppState();
      }
      }

      class MyAppState extends State<MyApp> {
      int _selectedTab = 0;
      final _pageOptions = [
      HomePage(),
      CatPage(),
      ];

      Widget _buildDrawer(BuildContext context) {
      return Drawer(
      child: Column(
      children: <Widget>[
      AppBar(
      automaticallyImplyLeading: false,
      backgroundColor: Color.fromRGBO(135, 142, 136, 1.0),
      title: Text('Looped In'),
      ),
      ListTile(
      leading: Icon(Icons.info, color: Color.fromRGBO(247, 203, 21, 1.0),),
      title: Text('About'),
      onTap: () {
      //Navigator.of(context).pushNamed('/about');
      Navigator.of(context).push(MaterialPageRoute(builder: (context) => AboutPage()));
      },
      ),
      ],
      ),
      );
      }

      @override
      Widget build(BuildContext context) {
      return MaterialApp(
      theme: ThemeData(
      accentColor: Color.fromRGBO(245, 93, 62, 1.0),
      primaryTextTheme: TextTheme(
      title: TextStyle(color: Colors.white),
      ),
      ),
      routes: <String, WidgetBuilder>{
      '/home': (BuildContext context) => HomePage(),
      '/about': (BuildContext context) => AboutPage(),
      '/contact': (BuildContext context) => ContactPage(),
      },
      home: Scaffold(
      drawer: _buildDrawer(context),
      appBar: AppBar(
      title: Text('Looped In'),
      backgroundColor: Color.fromRGBO(
      135,
      142,
      136,
      1.0,
      ),
      ),
      body: Container(
      padding: EdgeInsets.symmetric(horizontal: 10.0),
      child: _pageOptions[_selectedTab],
      ),
      bottomNavigationBar: BottomNavigationBar(
      currentIndex: _selectedTab,
      onTap: (int index) {
      setState(() {
      _selectedTab = index;
      });
      },
      fixedColor: Color.fromRGBO(118, 190, 208, 1.0),
      items: [
      BottomNavigationBarItem(
      icon: Icon(Icons.home),
      title: Text('Everything'),
      ),
      BottomNavigationBarItem(
      icon: Icon(Icons.category),
      title: Text('Categories'),
      ),
      ],
      ),
      ),
      );
      }
      }









      share|improve this question
















      I am trying to have some buttons in a drawer that the user can top on and be taken to another page/widget. However, it gives me an error and doesn't work. I'm not really sure what the issue is considering I'm doing this in another project and it works, additionally I checked the cookbook on Flutter's docs for how to do navigation and it also looks fine based on that.



      Here is my drawer code which is inside a Scaffold widget:



      Drawer(
      child: Column(
      children: <Widget>[
      AppBar(
      automaticallyImplyLeading: false,
      title: Text('Looped In'),
      ),
      ListTile(
      leading: Icon(Icons.info),
      title: Text('About'),
      onTap: () {
      Navigator.of(context).pushNamed('/about');
      },
      ),
      ],
      ),
      ),


      Here is the error traceback that I'm getting



      flutter: The following assertion was thrown while handling a gesture:
      flutter: Navigator operation requested with a context that does not include a Navigator.
      flutter: The context used to push or pop routes from the Navigator must be that of a widget that is a
      flutter: descendant of a Navigator widget.
      flutter:
      flutter: When the exception was thrown, this was the stack:
      flutter: #0 Navigator.of.<anonymous closure> (package:flutter/src/widgets/navigator.dart:1273:9)
      flutter: #1 Navigator.of (package:flutter/src/widgets/navigator.dart:1280:6)
      flutter: #2 MyAppState.build.<anonymous closure> (file:///Users/garrettlove/Documents/learn/Flutter/loopt_in/lib/main.dart:59:29)
      flutter: #3 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:507:14)
      flutter: #4 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:562:30)
      flutter: #5 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
      flutter: #6 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:242:9)
      flutter: #7 TapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:204:7)
      flutter: #8 GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27)
      flutter: #9 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:147:20)
      flutter: #10 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:121:22)
      flutter: #11 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:101:7)
      flutter: #12 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:64:7)
      flutter: #13 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:48:7)
      flutter: #14 _invoke1 (dart:ui/hooks.dart:153:13)
      flutter: #15 _dispatchPointerDataPacket (dart:ui/hooks.dart:107:5)
      flutter:
      flutter: Handler: onTap
      flutter: Recognizer:
      flutter: TapGestureRecognizer#2d408(debugOwner: GestureDetector, state: ready, won arena, finalPosition:
      flutter: Offset(98.5, 222.5), sent tap down)


      EDIT
      Here is everything I have:



      import 'package:flutter/material.dart';

      import './pages/home.dart';
      import './pages/categories.dart';
      import './pages/about.dart';
      import './pages/contact.dart';

      void main() => runApp(new MyApp());

      class MyApp extends StatefulWidget {
      @override
      State<StatefulWidget> createState() {
      return MyAppState();
      }
      }

      class MyAppState extends State<MyApp> {
      int _selectedTab = 0;
      final _pageOptions = [
      HomePage(),
      CatPage(),
      ];

      Widget _buildDrawer(BuildContext context) {
      return Drawer(
      child: Column(
      children: <Widget>[
      AppBar(
      automaticallyImplyLeading: false,
      backgroundColor: Color.fromRGBO(135, 142, 136, 1.0),
      title: Text('Looped In'),
      ),
      ListTile(
      leading: Icon(Icons.info, color: Color.fromRGBO(247, 203, 21, 1.0),),
      title: Text('About'),
      onTap: () {
      //Navigator.of(context).pushNamed('/about');
      Navigator.of(context).push(MaterialPageRoute(builder: (context) => AboutPage()));
      },
      ),
      ],
      ),
      );
      }

      @override
      Widget build(BuildContext context) {
      return MaterialApp(
      theme: ThemeData(
      accentColor: Color.fromRGBO(245, 93, 62, 1.0),
      primaryTextTheme: TextTheme(
      title: TextStyle(color: Colors.white),
      ),
      ),
      routes: <String, WidgetBuilder>{
      '/home': (BuildContext context) => HomePage(),
      '/about': (BuildContext context) => AboutPage(),
      '/contact': (BuildContext context) => ContactPage(),
      },
      home: Scaffold(
      drawer: _buildDrawer(context),
      appBar: AppBar(
      title: Text('Looped In'),
      backgroundColor: Color.fromRGBO(
      135,
      142,
      136,
      1.0,
      ),
      ),
      body: Container(
      padding: EdgeInsets.symmetric(horizontal: 10.0),
      child: _pageOptions[_selectedTab],
      ),
      bottomNavigationBar: BottomNavigationBar(
      currentIndex: _selectedTab,
      onTap: (int index) {
      setState(() {
      _selectedTab = index;
      });
      },
      fixedColor: Color.fromRGBO(118, 190, 208, 1.0),
      items: [
      BottomNavigationBarItem(
      icon: Icon(Icons.home),
      title: Text('Everything'),
      ),
      BottomNavigationBarItem(
      icon: Icon(Icons.category),
      title: Text('Categories'),
      ),
      ],
      ),
      ),
      );
      }
      }






      dart flutter






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 15 '18 at 0:07







      Garrett

















      asked Nov 14 '18 at 0:37









      GarrettGarrett

      446318




      446318
























          2 Answers
          2






          active

          oldest

          votes


















          0














          You probably need a string in "about" Screen before Widget build



          static const String routeName = "/about";


          or just use this



          onPressed: () {
          Navigator.of(context).push(MaterialPageRoute(
          builder: (context) => new AboutScreen()));
          }





          share|improve this answer
























          • Tried this, still doesn't work

            – Garrett
            Nov 14 '18 at 12:02



















          0














          You need to make sure that context that you are using for Navigator has a parent MaterialApp or this error will occur. Wrapping your Scaffold widget with MaterialApp should solve the issue.



          Also in your MaterialApp make sure to provide the route parameter with the route '/about'



          It should look something like this:



              MaterialApp(
          routes: <String, WidgetBuilder>{
          '/about': (BuildContext context) => AboutPage()
          },
          home: Scaffold(),
          );


          EDIT:



          Below you can find the solution based on your code. It works I tested. All you have to do is wrap your Scaffold with Builder like shown below:



          home: Builder(
          builder: (context) => Scaffold(
          drawer: _buildDrawer(context),
          appBar: AppBar(
          title: Text('Looped In'),
          backgroundColor: Color.fromRGBO(
          135,
          142,
          136,
          1.0,
          ),
          ),





          share|improve this answer


























          • I have it in a MaterialApp widget, and I tried adding in the extra stuff you have, still gives same error.

            – Garrett
            Nov 14 '18 at 11:59











          • Can you post what you've done.

            – Thanthu
            Nov 14 '18 at 12:04











          • Just edited the post to show everything

            – Garrett
            Nov 15 '18 at 0:14











          • I've edited the answer with the solution based on the code you posted now. It should work. Please try

            – Thanthu
            Nov 15 '18 at 5:17











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291515%2fflutter-buttons-in-drawer-give-error-when-tapped-instead-of-navigating-to-the-pr%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You probably need a string in "about" Screen before Widget build



          static const String routeName = "/about";


          or just use this



          onPressed: () {
          Navigator.of(context).push(MaterialPageRoute(
          builder: (context) => new AboutScreen()));
          }





          share|improve this answer
























          • Tried this, still doesn't work

            – Garrett
            Nov 14 '18 at 12:02
















          0














          You probably need a string in "about" Screen before Widget build



          static const String routeName = "/about";


          or just use this



          onPressed: () {
          Navigator.of(context).push(MaterialPageRoute(
          builder: (context) => new AboutScreen()));
          }





          share|improve this answer
























          • Tried this, still doesn't work

            – Garrett
            Nov 14 '18 at 12:02














          0












          0








          0







          You probably need a string in "about" Screen before Widget build



          static const String routeName = "/about";


          or just use this



          onPressed: () {
          Navigator.of(context).push(MaterialPageRoute(
          builder: (context) => new AboutScreen()));
          }





          share|improve this answer













          You probably need a string in "about" Screen before Widget build



          static const String routeName = "/about";


          or just use this



          onPressed: () {
          Navigator.of(context).push(MaterialPageRoute(
          builder: (context) => new AboutScreen()));
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 14 '18 at 1:53









          Victor TongVictor Tong

          32229




          32229













          • Tried this, still doesn't work

            – Garrett
            Nov 14 '18 at 12:02



















          • Tried this, still doesn't work

            – Garrett
            Nov 14 '18 at 12:02

















          Tried this, still doesn't work

          – Garrett
          Nov 14 '18 at 12:02





          Tried this, still doesn't work

          – Garrett
          Nov 14 '18 at 12:02













          0














          You need to make sure that context that you are using for Navigator has a parent MaterialApp or this error will occur. Wrapping your Scaffold widget with MaterialApp should solve the issue.



          Also in your MaterialApp make sure to provide the route parameter with the route '/about'



          It should look something like this:



              MaterialApp(
          routes: <String, WidgetBuilder>{
          '/about': (BuildContext context) => AboutPage()
          },
          home: Scaffold(),
          );


          EDIT:



          Below you can find the solution based on your code. It works I tested. All you have to do is wrap your Scaffold with Builder like shown below:



          home: Builder(
          builder: (context) => Scaffold(
          drawer: _buildDrawer(context),
          appBar: AppBar(
          title: Text('Looped In'),
          backgroundColor: Color.fromRGBO(
          135,
          142,
          136,
          1.0,
          ),
          ),





          share|improve this answer


























          • I have it in a MaterialApp widget, and I tried adding in the extra stuff you have, still gives same error.

            – Garrett
            Nov 14 '18 at 11:59











          • Can you post what you've done.

            – Thanthu
            Nov 14 '18 at 12:04











          • Just edited the post to show everything

            – Garrett
            Nov 15 '18 at 0:14











          • I've edited the answer with the solution based on the code you posted now. It should work. Please try

            – Thanthu
            Nov 15 '18 at 5:17
















          0














          You need to make sure that context that you are using for Navigator has a parent MaterialApp or this error will occur. Wrapping your Scaffold widget with MaterialApp should solve the issue.



          Also in your MaterialApp make sure to provide the route parameter with the route '/about'



          It should look something like this:



              MaterialApp(
          routes: <String, WidgetBuilder>{
          '/about': (BuildContext context) => AboutPage()
          },
          home: Scaffold(),
          );


          EDIT:



          Below you can find the solution based on your code. It works I tested. All you have to do is wrap your Scaffold with Builder like shown below:



          home: Builder(
          builder: (context) => Scaffold(
          drawer: _buildDrawer(context),
          appBar: AppBar(
          title: Text('Looped In'),
          backgroundColor: Color.fromRGBO(
          135,
          142,
          136,
          1.0,
          ),
          ),





          share|improve this answer


























          • I have it in a MaterialApp widget, and I tried adding in the extra stuff you have, still gives same error.

            – Garrett
            Nov 14 '18 at 11:59











          • Can you post what you've done.

            – Thanthu
            Nov 14 '18 at 12:04











          • Just edited the post to show everything

            – Garrett
            Nov 15 '18 at 0:14











          • I've edited the answer with the solution based on the code you posted now. It should work. Please try

            – Thanthu
            Nov 15 '18 at 5:17














          0












          0








          0







          You need to make sure that context that you are using for Navigator has a parent MaterialApp or this error will occur. Wrapping your Scaffold widget with MaterialApp should solve the issue.



          Also in your MaterialApp make sure to provide the route parameter with the route '/about'



          It should look something like this:



              MaterialApp(
          routes: <String, WidgetBuilder>{
          '/about': (BuildContext context) => AboutPage()
          },
          home: Scaffold(),
          );


          EDIT:



          Below you can find the solution based on your code. It works I tested. All you have to do is wrap your Scaffold with Builder like shown below:



          home: Builder(
          builder: (context) => Scaffold(
          drawer: _buildDrawer(context),
          appBar: AppBar(
          title: Text('Looped In'),
          backgroundColor: Color.fromRGBO(
          135,
          142,
          136,
          1.0,
          ),
          ),





          share|improve this answer















          You need to make sure that context that you are using for Navigator has a parent MaterialApp or this error will occur. Wrapping your Scaffold widget with MaterialApp should solve the issue.



          Also in your MaterialApp make sure to provide the route parameter with the route '/about'



          It should look something like this:



              MaterialApp(
          routes: <String, WidgetBuilder>{
          '/about': (BuildContext context) => AboutPage()
          },
          home: Scaffold(),
          );


          EDIT:



          Below you can find the solution based on your code. It works I tested. All you have to do is wrap your Scaffold with Builder like shown below:



          home: Builder(
          builder: (context) => Scaffold(
          drawer: _buildDrawer(context),
          appBar: AppBar(
          title: Text('Looped In'),
          backgroundColor: Color.fromRGBO(
          135,
          142,
          136,
          1.0,
          ),
          ),






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 15 '18 at 5:16

























          answered Nov 14 '18 at 4:48









          ThanthuThanthu

          284114




          284114













          • I have it in a MaterialApp widget, and I tried adding in the extra stuff you have, still gives same error.

            – Garrett
            Nov 14 '18 at 11:59











          • Can you post what you've done.

            – Thanthu
            Nov 14 '18 at 12:04











          • Just edited the post to show everything

            – Garrett
            Nov 15 '18 at 0:14











          • I've edited the answer with the solution based on the code you posted now. It should work. Please try

            – Thanthu
            Nov 15 '18 at 5:17



















          • I have it in a MaterialApp widget, and I tried adding in the extra stuff you have, still gives same error.

            – Garrett
            Nov 14 '18 at 11:59











          • Can you post what you've done.

            – Thanthu
            Nov 14 '18 at 12:04











          • Just edited the post to show everything

            – Garrett
            Nov 15 '18 at 0:14











          • I've edited the answer with the solution based on the code you posted now. It should work. Please try

            – Thanthu
            Nov 15 '18 at 5:17

















          I have it in a MaterialApp widget, and I tried adding in the extra stuff you have, still gives same error.

          – Garrett
          Nov 14 '18 at 11:59





          I have it in a MaterialApp widget, and I tried adding in the extra stuff you have, still gives same error.

          – Garrett
          Nov 14 '18 at 11:59













          Can you post what you've done.

          – Thanthu
          Nov 14 '18 at 12:04





          Can you post what you've done.

          – Thanthu
          Nov 14 '18 at 12:04













          Just edited the post to show everything

          – Garrett
          Nov 15 '18 at 0:14





          Just edited the post to show everything

          – Garrett
          Nov 15 '18 at 0:14













          I've edited the answer with the solution based on the code you posted now. It should work. Please try

          – Thanthu
          Nov 15 '18 at 5:17





          I've edited the answer with the solution based on the code you posted now. It should work. Please try

          – Thanthu
          Nov 15 '18 at 5:17


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291515%2fflutter-buttons-in-drawer-give-error-when-tapped-instead-of-navigating-to-the-pr%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Florida Star v. B. J. F.

          Danny Elfman

          Lugert, Oklahoma