基础库
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 

82 Zeilen
2.6 KiB

  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:provider/provider.dart';
  5. import 'package:zhiying_comm/pages/login_page/login_page.dart';
  6. import 'package:zhiying_comm/zhiying_comm.dart';
  7. class RouterUtil {
  8. /*公共跳转
  9. * skipModel 跳转参数
  10. * data 额外参数
  11. * */
  12. static Future route(SkipModel skipModel, Map<String, dynamic> data,
  13. BuildContext context) async {
  14. if (skipModel.skipIdentifier == null || skipModel.skipIdentifier == '') {
  15. print('skipIdentifier 参数不存在,无法跳转页面');
  16. return Future.error('skipIdentifier 参数不存在,无法跳转页面');
  17. }
  18. print('skipIdentifier: ${skipModel.skipIdentifier}');
  19. hideKeyboard(context);
  20. if (skipModel?.requiredLogin == '1') {
  21. UserInfoModel user =
  22. await Provider.of<UserInfoNotifier>(context, listen: false)
  23. .getUserInfoModel();
  24. print(user.toString());
  25. if (user?.token == null || user.token == '') {
  26. print('need login...');
  27. return RouterUtil.goLogin(context);
  28. }
  29. }
  30. Widget page = EmptyPage();
  31. if (PageFactory.hasRegisted(skipModel.skipIdentifier)) {
  32. page = PageFactory.create(skipModel.skipIdentifier, data);
  33. } else {
  34. var result = await NetUtil.post(
  35. '/api/v1/mod/${skipModel.skipIdentifier.toString()}',
  36. method: NetMethod.GET);
  37. Logger.debug(result);
  38. page = PageFactory.create('index', Map<String, dynamic>.from(result));
  39. }
  40. return Navigator.of(context)
  41. .push(CupertinoPageRoute(builder: (BuildContext context) {
  42. return page;
  43. }));
  44. }
  45. // 跳转登录
  46. static Future goLogin(BuildContext context) {
  47. return Navigator.of(context)
  48. .push(CupertinoPageRoute(builder: (BuildContext context) {
  49. return LoginPage();
  50. }));
  51. }
  52. static Future openWebview(String url, BuildContext context) {
  53. if (url == null || url == '') {
  54. Logger.error('跳转链接不能为空');
  55. return Future.error('跳转链接不能为空');
  56. }
  57. SkipModel model = SkipModel();
  58. model.skipIdentifier = 'pub.flutter.url';
  59. model.url = url;
  60. RouterUtil.route(model, null, context);
  61. }
  62. static void hideKeyboard(BuildContext context){
  63. try {
  64. FocusScopeNode currentFocus = FocusScope.of(context);
  65. if (!currentFocus.hasPrimaryFocus &&
  66. currentFocus.focusedChild != null) {
  67. FocusManager.instance.primaryFocus.unfocus();
  68. }
  69. // SystemChannels.textInput.invokeMethod('TextInput.hide');
  70. // FocusScope.of(context).requestFocus(FocusNode());
  71. }catch(e, s){
  72. Logger.error(e,s);
  73. }
  74. }
  75. }