我正在构建一个应用程序来检查用户是否登录并相应地选择主页或登录页面。如果登录,用户会看到一个侧面菜单,菜单中的第一个选项会自动选择。现在,如果第一个菜单项是搜索,那么 url 应该显示 www.abcd.com\search,但是,这没有发生,并且 url 仍然是www.abcd.com
void main() {
WidgetsFlutterBinding.ensureInitialized();
setUrlStrategy(PathUrlStrategy());
runApp(
MultiProvider(
providers: [
ChangeNotifierProvider(create: (_) => Auth()),
],
child: MaterialApp(
debugShowCheckedModeBanner: false,
navigatorKey: NavigatorKeys.mainNavigationKey,
onGenerateRoute: RouteConfiguration.onGenerateRoute,
theme: ThemeData(
elevatedButtonTheme: ElevatedButtonThemeData(
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all<Color>(kPrimaryColor),
),
),
scaffoldBackgroundColor: Colors.white,
textTheme: const TextTheme(
button: TextStyle(
color: Colors.white, fontWeight: FontWeight.bold))),
home: const MyApp()),
),
);
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return Consumer<Auth>(builder: (_, authObj, child) {
// print('is loading ${authObj.isLoading}');
return authObj.isLoading
? const Center(child: CircularProgressIndicator())
: authObj.isLoggedIn
? const HomePage()
: const LandingPage();
});
}
}
主页.dart
class HomePage extends StatelessWidget {
const HomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
// return const Search();
return Navigator(
initialRoute: '/search',
key: NavigatorKeys.sideNavigationKey,
onGenerateRoute: RouteConfiguration.onGenerateRoute,
);
}
}