【发布时间】:2022-10-14 06:47:03
【问题描述】:
我在 Material App 中定义了所需的路线,一切正常,我必须添加另一个按钮,这应该会导致授权页面,现在我收到了这个错误:
The following assertion was thrown while handling a gesture:
Could not find a generator for route RouteSettings("/changeUsers", null) in the _WidgetsAppState.
Make sure your root app widget has provided a way to generate
this route.
Generators for routes are searched for in the following order:
1. For the "/" route, the "home" property, if non-null, is used.
2. Otherwise, the "routes" table is used, if it has an entry for the route.
3. Otherwise, onGenerateRoute is called. It should return a non-null value for any valid route not handled by "home" and "routes".
4. Finally if all else fails onUnknownRoute is called.
我的代码如下所示:
return MaterialApp(
debugShowCheckedModeBanner: false,
initialRoute: '/',
routes: {
'/': (context) => const AuthorizationPage(),
'/adminLogin': (context) => const AuthInsertLogging(),
'/mainPageUsers': (context) => const TabBarBottomUsers(),
'/mainPageAdmin': (context) => const TabBarBottom(),
"/logout": (_) => new AuthorizationPage(),
'/changeUsers': (_) => AuthorizationPage(),
},
);
}
这是我试图制作路线的按钮:
child: ElevatedButton(
onPressed: () {
Navigator.pushNamed(context, '/changeUsers');
},
child: Text(
'Change User',
style: GoogleFonts.montserrat(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.w500,
letterSpacing: 2),
),
【问题讨论】: