routers.dart
2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import 'package:Parlando/poem/components/nav_bar_page.dart';
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:Parlando/account/account_router.dart';
import 'package:Parlando/category/category_router.dart';
import 'package:Parlando/category/page/categories_page.dart';
import 'package:Parlando/membership/membership_router.dart';
import 'package:Parlando/timeline/timeline_router.dart';
import 'package:Parlando/home/home_page.dart';
import 'package:Parlando/home/webview_page.dart';
import 'package:Parlando/login/login_router.dart';
import 'package:Parlando/poem/poem_router.dart';
import 'package:Parlando/setting/setting_router.dart';
import 'i_router.dart';
import 'not_found_page.dart';
class Routes {
static String navBarPage = '/nav/bar/page';
static String home = '/home';
static String webViewPage = '/webView';
static final List<IRouterProvider> _listRouter = [];
static final FluroRouter router = FluroRouter();
static void initRoutes() {
/// 指定路由跳转错误返回页
router.notFoundHandler = Handler(
handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
debugPrint('未找到目标页');
return const NotFoundPage();
});
router.define(navBarPage,
handler: Handler(
handlerFunc:
(BuildContext? context, Map<String, List<String>> params) =>
const NavBarPage(initialPage: 'HomePage')));
router.define(home,
handler: Handler(
handlerFunc:
(BuildContext? context, Map<String, List<String>> params) =>
const Home()));
router.define(webViewPage, handler: Handler(handlerFunc: (_, params) {
final String title = params['title']?.first ?? '';
final String url = params['url']?.first ?? '';
return WebViewPage(title: title, url: url);
}));
_listRouter.clear();
/// 各自路由由各自模块管理,统一在此添加初始化
_listRouter.add(LoginRouter());
_listRouter.add(TimelineRouter());
_listRouter.add(PoemRouter());
_listRouter.add(AccountRouter());
_listRouter.add(SettingRouter());
_listRouter.add(CategoryRouter());
_listRouter.add(MembershipRouter());
/// 初始化路由
void initRouter(IRouterProvider routerProvider) {
routerProvider.initRouter(router);
}
_listRouter.forEach(initRouter);
}
}