在我的 flutter 应用程序中分离不同模块的路由的最佳方法是什么
现在我正在使用生成的路由。我有一个类将所有路由返回到 onGenerateRoute。我的应用程序中有几个模块,我已将它们分开。可访问的模块取决于用户的类型。我尝试为每个模块创建不同的路由文件,并可以从主路由文件访问它们。我正在使用块状态管理。 (我的路线文件开始变得非常混乱。)
Right now Im using generated routing. I have a class that returns all my routes to the onGenerateRoute. I have several modules in my app, which i have seperated. Accessible modules depend on the type of user. Im trying to create a different routes file for each module and have access to them from the main routes file. I am using bloc state management. (my routes file is starting to get really cluttered.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我完成此操作的一种方法是通过嵌套导航并使用多个导航器小部件,每个小部件管理一组路线(如果您使用的是Navigator 1.0)。
例如;在主路由对象中,您可以拥有到每个模块小部件的路由: 用户和管理员:
然后在每个小部件(定义单独的模块)中,您可以有一个嵌套的导航器小部件,它列出每个模块的路由(某些“伪”代码来了解想法):
这样您就可以对路线进行分组,并根据用户的类型或角色将用户引导至相应的路线。这是一种方法。
One way I've done it is via nested navigation and using multiple Navigator widgets, each of which manages a group of routes (this is if you're using Navigator 1.0).
For example; in the main routes object, you can have the routes to each module widget: User and Admin:
Then inside each of these widgets (which define your separate modules) you can have a nested Navigator widget that lays out the routes for each module (some "pseudo" code to get the idea):
That way you can group your routes and direct users to the corresponding routes based on their type or role. This is one way to do it.
您应该做的是为每个模块创建一个路由器,并将这些路由器注册到主路由器中。
在主路由器中,您注册模块路由器。
以下是我的做法:
应用程序路由器:
主/现有路由器:
子路由器接口:
子路由器:
AppRouter().onGenerateRoute 被注册为材质应用程序的 onGenerateRoute 方法。
您可以检查 github 存储库以获取工作示例
https://github.com/mastersam07/sphr-
What you should do is create a router for each module and register these routers in the main router.
In your main router, you register the module routers.
Here's how I did mine:
App Router:
Main/Existing Router:
Sub router interface:
Sub router:
AppRouter().onGenerateRoute is registered as the onGenerateRoute method of the material app.
You could check the github repo for a working sample
https://github.com/mastersam07/s-p-h-r-