我在做一个flutter app。我已经在应用程序中设置了路由器,并命名路由。在我的主页上,它显示为localhost:1234/#/home。道路是正确的。但是从那里,当导航回到前一页时,它仍然显示相同的路径localhost:1234/#/home。这路径url是不改变对导航回来.如果有人有主意?我的路由器文件如下:
/* ADD REPOSITORY TO APP ROUTER */
/* ADD REPOSITORY TO APP ROUTER */
Repository repository;
AppRouter() {
repository = new Repository(apiService: ApiService());
}
Route generateRoute(RouteSettings settings) {
switch (settings.name) {
case "/":
return MaterialPageRoute(
settings: RouteSettings(name: '/'),
builder: (_) => MultiBlocProvider(providers: [
BlocProvider<HomeCubit>(
create: (BuildContext context) {
return HomeCubit(repository: repository);
},
),
BlocProvider<SearchCubit>(
create: (BuildContext context) =>
SearchCubit(repository: repository),
),
BlocProvider<UserCubit>(
create: (BuildContext context) {
return UserCubit(repository: repository);
},
)
], child:userToken==null?SplashScreen():NavScreen()
// SplashScreen()
));
case "/getstarted":
return MaterialPageRoute(
settings: RouteSettings(name: '/getstarted'),
builder: (_) => BlocProvider(
create: (BuildContext context) =>
ProfileCubit(repository: repository),
child: OnboardingScreen()));
//return MaterialPageRoute(builder: (_) => VideoDetailScreen());
case "/register":
return MaterialPageRoute(
settings: RouteSettings(name: '/register'),
builder: (_) => MultiBlocProvider(providers: [
BlocProvider<HomeCubit>(
create: (BuildContext context) {
return HomeCubit(repository: repository);
},
),
BlocProvider<SearchCubit>(
create: (BuildContext context) =>
SearchCubit(repository: repository),
),
BlocProvider<UserCubit>(
create: (BuildContext context) =>
UserCubit(repository: repository),
)
], child: RegisterScreen()));
case '/home':
return MaterialPageRoute(
settings: RouteSettings(name: '/home'),
builder: (_) => BlocProvider(
create: (BuildContext context) =>
HomeCubit(repository: repository),
child: NavScreen()));
case '/signin':
return MaterialPageRoute(
builder: (_) => BlocProvider(
create: (BuildContext context) =>
UserCubit(repository: repository),
child: SigninScreen()),
settings: RouteSettings(name: '/signin'));
default:
return MaterialPageRoute(builder: (_) {
return Scaffold(
body: Center(
child: Text('Error! No route Found...',
style: TextStyle(color: Colors.white,fontWeight:FontWeight.bold),),
),
);
}
);
}
}
}
3条答案
按热度按时间rxztt3cl1#
Page url not changing in flutter, but the page content changes fine
ecr0jaav2#
您必须使用Flutter Navigator 2.0来实现动态和深度链接,即在页面更改时更改URL并获得浏览器的返回和重新加载按钮的功能。
最简单的方法是使用go_router Flutter包,它具有非常简单的设置和文档。
在这里,您可以定义您的路径,该路径随页面更改而更改。
alen0pnh3#
试试这个:
对我很有效