我在我的应用程序中苦苦挣扎:
用户登录后,我导航到我HomeView
的 with pushReplaceNamed
,因此用户不应该能够弹出(通过拖动),HomeView
因为在我看来它是根视图。然而事实并非如此。即使在调用后pushReplaceNamed
用户仍然可以拖动弹出:
我只是调用:
Navigator.pushReplacementNamed(
context,
Views.home,
);
在显示应用程序的第一次启动时StartView
,我从那里导航EmailView
到LoginView
. 上面的代码在我的LoginView
. 在所有其他视图中,我简单地称为pushNamed
.
我在这里想念什么?为什么用户可以拖动弹窗HomeView
?
(我知道我可以用 禁用它WillPopScope
,但感觉不对...)
这是我的设置MaterialApp
:
Widget build(BuildContext context) {
return MaterialApp(
title: 'AppFlug',
navigatorKey: Get.key,
theme: ThemeData(
fontFamily: AppTextStyles.montserrat,
primarySwatch: ColorService.createMaterialColor(
AppColors.blue,
),
backgroundColor: AppColors.white,
scaffoldBackgroundColor: AppColors.white,
),
initialRoute:
AuthenticationService.isLoggedIn() ? Views.home : Views.start,
onGenerateRoute: AppRouter.generateRoute,
);
}
这是我的AppRouter
:
class AppRouter {
static Route<dynamic> generateRoute(RouteSettings settings) {
switch (settings.name) {
case Views.start:
return MaterialPageRoute(
builder: (context) => const StartView(),
);
case Views.email:
return MaterialPageRoute(
builder: (context) => EmailView(),
);
case Views.signUp:
String email = settings.arguments as String;
return MaterialPageRoute(
builder: (context) => SignUpView(
email: email,
),
);
case Views.login:
String email = settings.arguments as String;
return MaterialPageRoute(
builder: (context) => LoginView(
email: email,
),
);
case Views.home:
return MaterialPageRoute(
builder: (context) => HomeView(),
);
default:
return MaterialPageRoute(
builder: (_) => Scaffold(
body: Center(
child: Text(
'No route defined for ${settings.name}',
),
),
),
);
}
}
}