使用 Fluro (Flutter web) 导航
Navigation with Fluro (Flutter web)
我正在尝试导航到页面。正在尝试创建一些路线。
我遇到的问题是:
- 当路线改变时,它会从 URL
中消失
- 当我尝试在浏览器中后退或前进时,它没有做任何事情。
我正在尝试将 Fluro package. I'm also trying to compare their example 与我的 Fluro package. I'm also trying to compare their example 一起使用,但我没有发现有什么区别。
main.dart:
void main() {
runApp(AppComponent());
}
class AppComponent extends StatefulWidget {
@override
State createState() {
return _AppComponentState();
}
}
class _AppComponentState extends State<AppComponent> {
_AppComponentState() {
final router = FluroRouter();
Routes.configureRoutes(router);
Application.router = router;
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'NexTeam',
debugShowCheckedModeBanner: false,
initialRoute: kHomeRoute,
onGenerateRoute: Application.router.generator,
);
}
}
class Application {
static FluroRouter router;
}
router.dart:
class Routes {
final router = FluroRouter();
static Handler _loginHandler = Handler(handlerFunc: (BuildContext context, Map<String, dynamic> params) => LoginPage());
static Handler _registerHandler = Handler(handlerFunc: (BuildContext context, Map<String, dynamic> params) => RegisterPage());
static Handler _homeHandler = Handler(handlerFunc: (BuildContext context, Map<String, dynamic> params) => HomePage());
static Handler _profileHandler = Handler(handlerFunc: (BuildContext context, Map<String, dynamic> params) => ProfilePage());
static Handler _notificationsHandler = Handler(handlerFunc: (BuildContext context, Map<String, dynamic> params) => NotificationsPage());
static Handler _chatHandler = Handler(handlerFunc: (BuildContext context, Map<String, dynamic> params) => ChatPage());
static void configureRoutes(FluroRouter router) {
router.define(kLoginRoute, handler: _loginHandler);
router.define(kRegisterRoute, handler: _registerHandler);
router.define(kHomeRoute, handler: _homeHandler);
router.define(kProfileRoute, handler: _profileHandler);
router.define(kNotificationsRoute, handler: _notificationsHandler);
router.define(kChatRoute, handler: _chatHandler);
}
}
导航功能:
Application.router.navigateTo(context, kNotificationsRoute);
我仍然不知道为什么,但问题是我的所有页面都以 MaterialApp
开头,解决方案是使用 Material
.
我正在尝试导航到页面。正在尝试创建一些路线。
我遇到的问题是:
- 当路线改变时,它会从 URL 中消失
- 当我尝试在浏览器中后退或前进时,它没有做任何事情。
我正在尝试将 Fluro package. I'm also trying to compare their example 与我的 Fluro package. I'm also trying to compare their example 一起使用,但我没有发现有什么区别。 main.dart:
void main() {
runApp(AppComponent());
}
class AppComponent extends StatefulWidget {
@override
State createState() {
return _AppComponentState();
}
}
class _AppComponentState extends State<AppComponent> {
_AppComponentState() {
final router = FluroRouter();
Routes.configureRoutes(router);
Application.router = router;
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'NexTeam',
debugShowCheckedModeBanner: false,
initialRoute: kHomeRoute,
onGenerateRoute: Application.router.generator,
);
}
}
class Application {
static FluroRouter router;
}
router.dart:
class Routes {
final router = FluroRouter();
static Handler _loginHandler = Handler(handlerFunc: (BuildContext context, Map<String, dynamic> params) => LoginPage());
static Handler _registerHandler = Handler(handlerFunc: (BuildContext context, Map<String, dynamic> params) => RegisterPage());
static Handler _homeHandler = Handler(handlerFunc: (BuildContext context, Map<String, dynamic> params) => HomePage());
static Handler _profileHandler = Handler(handlerFunc: (BuildContext context, Map<String, dynamic> params) => ProfilePage());
static Handler _notificationsHandler = Handler(handlerFunc: (BuildContext context, Map<String, dynamic> params) => NotificationsPage());
static Handler _chatHandler = Handler(handlerFunc: (BuildContext context, Map<String, dynamic> params) => ChatPage());
static void configureRoutes(FluroRouter router) {
router.define(kLoginRoute, handler: _loginHandler);
router.define(kRegisterRoute, handler: _registerHandler);
router.define(kHomeRoute, handler: _homeHandler);
router.define(kProfileRoute, handler: _profileHandler);
router.define(kNotificationsRoute, handler: _notificationsHandler);
router.define(kChatRoute, handler: _chatHandler);
}
}
导航功能:
Application.router.navigateTo(context, kNotificationsRoute);
我仍然不知道为什么,但问题是我的所有页面都以 MaterialApp
开头,解决方案是使用 Material
.