【问题标题】:Navigation with Fluro (Flutter web)使用 Fluro 导航(Flutter web)
【发布时间】:2021-03-15 17:56:43
【问题描述】:

我正在尝试导航到页面。正在尝试创建一些路线。

我遇到的问题是:

  1. 当路由改变时,它会从 URL 中消失
  2. 当我尝试在浏览器中返回或前进时,它什么也没做。

我正在尝试使用Fluro package。我也在尝试将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);

【问题讨论】:

  • 我不太明白你想要什么,如果你想从你的应用导航到网页,你应该使用 url_launcher 包
  • @Timurturbil 我不想去其他网站。我想浏览我的网站。

标签: flutter flutter-web flutter-navigation


【解决方案1】:

我仍然不知道为什么,但问题是我的所有页面都以MaterialApp开头,解决方案是使用Material

【讨论】:

    猜你喜欢
    • 2018-12-24
    • 2021-02-07
    • 2020-12-25
    • 2021-09-05
    • 2020-12-10
    • 1970-01-01
    • 2021-12-31
    • 1970-01-01
    • 2021-04-09
    相关资源
    最近更新 更多