|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- import 'package:flutter/material.dart';
- import 'package:zhiying_comm/pages/login_page/login_page.dart';
- import 'package:zhiying_comm/zhiying_comm.dart';
- import 'package:provider/provider.dart';
-
- class RouterUtil {
- static Future route(Map<String, dynamic> model, BuildContext context) async {
- // 唯一跳转标识
- String skipIdentifier = model['skip_identifier'].toString();
- // 需要登录
- String requiredLogin = model['required_login'].toString();
- // 需要淘宝授权
- String requiredTaobaoAuth = model['required_taobao_auth'].toString();
-
- if (skipIdentifier == null || skipIdentifier == '') {
- print('skipIdentifier 参数不存在,无法跳转页面');
- return Future.error('skipIdentifier 参数不存在,无法跳转页面');
- }
- print('skipIdentifier: ${skipIdentifier}');
-
- if (requiredLogin == '1') {
- UserInfoModel user =
- await Provider.of<UserInfoNotifier>(context, listen: false)
- .getUserInfoModel();
- print(user.toString());
- if (user?.token == null || user.token == '') {
- print('need login...');
- return Navigator.of(context)
- .push(MaterialPageRoute(builder: (BuildContext context) {
- return LoginPage(model);
- }));
- }
- }
-
- Widget page = EmptyPage();
- if (PageFactory.hasRegisted(skipIdentifier)) {
- page = PageFactory.create(skipIdentifier, model);
- } else {
- Api api = Api('/api/v1/mod/${skipIdentifier.toString()}',
- method: NetMethod.GET);
- var result = await api.onRequest();
- page = PageFactory.create('index', Map<String, dynamic>.from(result));
- }
- return Navigator.of(context)
- .push(MaterialPageRoute(builder: (BuildContext context) {
- return page;
- }));
- }
- }
|