navigator error when i try to navigate from app bar icon click

828 views
Skip to first unread message

ajay sharma

unread,
Aug 27, 2018, 9:43:44 AM8/27/18
to Flutter Dev
navigator error when i try to navigate from app bar icon click
'Navigator operation requested with a context that does not include a Navigator '
The context used to push or pop routes from the Navigator must be that of a widget that is a descendant of a Navigator widget'
kindly help
class MyGSt extends StatelessWidget
{
@override
Widget build(BuildContext context)
{
// void _gstnHistoryData()
//{
// Navigator.popAndPushNamed(context, "/GstnHistoryData");
// }

try
{
final appTitle = 'My GST Data';

return MaterialApp
(
title: appTitle,

home: Scaffold
(
appBar: AppBar
(
leading: new Image.asset('img/logo.png', fit: BoxFit.cover),
title: Text(appTitle),

actions: <Widget>
[

new IconButton
(
icon: new Icon(Icons.history),
onPressed: ()
{
Navigator.push(context,
new MaterialPageRoute(builder: (context) => new GstnHistoryData()));
},

),

],

),

body: MyData(),

),

routes: <String, WidgetBuilder>
{
"/GstnHistoryData": (BuildContext context) => new GstnHistoryData(),
}
);


}

catch(e)
{

print(e.toString());
}
return null;
}

mahe...@prayuta.com

unread,
Aug 27, 2018, 5:46:30 PM8/27/18
to Flutter Dev
Hi There,

Please can you change the code as follows:

Navigator.push(context,
new MaterialPageRoute(builder: (context) => new GstnHistoryData()));
to

Navigator.push(context,
new MaterialPageRoute(builder: (_) => new GstnHistoryData()));

Regards,
Mahi.
Reply all
Reply to author
Forward
0 new messages