I have a set of routes that I have defined in the routes.dart
and these routes are linked in the main.dart
file as below.
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
StreamProvider<ConnectivityStatus>(
create: (_) => ConnectionService().connectionStatusController.stream,
),
...
ChangeNotifierProvider<AuthNotifier>(
create: (_) => AuthNotifier(),
),
],
child: MaterialApp(
debugShowCheckedModeBanner: false,
routes: Routes.routes,
home: SplashScreen(),
),
);
}
Routes.dart
file:
class Routes {
Routes._();
static const chat = '/chat';
static final routes = <String, WidgetBuilder>{
chat: (BuildContext ctx) => CircleChat(),
};
}
I have a button that is triggering the above route but throwing error.
FlatButton(
Navigator.of(context).pushReplacementNamed(Routes.chat);
)
Error -
The following assertion was thrown while handling a gesture: Could not find a generator for route RouteSettings("chat", null) in the _CustomTabViewState. Generators for routes are searched for in the following order:
- For the "/" route, the "builder" property, if non-null, is used.
- Otherwise, the "routes" table is used, if it has an entry for the route.
- Otherwise, onGenerateRoute is called. It should return a non-null value for any valid route not handled by "builder" and "routes".
- Finally if all else fails onUnknownRoute is called. Unfortunately, onUnknownRoute was not set.
When the exception was thrown, this was the stack: #0 _CustomTabViewState._onUnknownRoute.
P.S. - For a similar error I went through this and this, but I didn't find the explanation, that why it is not working when all semantics are correct.