I found the below error's explanation in this link: Navigator operation requested with a context that does not include a Navigator I tried to apply to my problem but I couldn't solve the problem.
When I click the button in the NavigationBar class, I got this error:
The following assertion was thrown while handling a gesture: 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.
void main() async {
await Firebase.initializeApp();
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
AppRouter appRouter = AppRouter(
routes: AppRoutes.routes,
notFoundHandler: AppRoutes.routeNotFoundHandler,
);
appRouter.setupRoutes();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'abc',
theme: ThemeData(
primarySwatch: Colors.blue,
),
builder: (_, child) => AppView(
child: child,
),
onGenerateRoute: AppRouter.router.generator,
);
}
}
class AppView extends StatelessWidget {
final Widget child;
const AppView({@required this.child});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [NavigationBar(), Expanded(child: child)],
),
);
}
}
class NavigationBar extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
child: MaterialButton(
child: Text(
"Home",
),
onPressed: () {
AppRouter.router
.navigateTo(context, AppRoutes.saticilarRoute.route);
},
),
),
//TODO
],
),
);
}
}