基础库
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
pirms 4 gadiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import 'dart:io';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_alibc/alibc_const_key.dart';
  5. import 'package:flutter_alibc/flutter_alibc.dart';
  6. import 'package:jdsdk/jdsdk.dart';
  7. import 'package:provider/provider.dart';
  8. import 'package:url_launcher/url_launcher.dart';
  9. import 'package:zhiying_comm/pages/login_page/account/login_account_page.dart';
  10. import 'package:zhiying_comm/pages/login_page/login_page.dart';
  11. import 'package:zhiying_comm/util/dialog/loading/loading.dart';
  12. import 'package:zhiying_comm/util/event_util/event_util.dart';
  13. import 'package:zhiying_comm/util/event_util/login_success_event.dart';
  14. import 'package:zhiying_comm/util/pdd_auth/pdd_auth.dart';
  15. import 'package:zhiying_comm/util/shared_prefe_util.dart';
  16. import 'package:zhiying_comm/zhiying_comm.dart';
  17. class RouterUtil {
  18. /*公共跳转
  19. * skipModel 跳转参数
  20. * data 额外参数
  21. * */
  22. static Future route(SkipModel skipModel, Map<String, dynamic> data, BuildContext context) async {
  23. if (skipModel.skipIdentifier == null || skipModel.skipIdentifier == '') {
  24. print('skipIdentifier 参数不存在,无法跳转页面');
  25. return Future.error('skipIdentifier 参数不存在,无法跳转页面');
  26. }
  27. // is_jump等于0不跳转
  28. if (!EmptyUtil.isEmpty(skipModel.isJump) && skipModel.isJump == '0') {
  29. return;
  30. }
  31. print('skipIdentifier: ${skipModel.skipIdentifier}');
  32. hideKeyboard(context);
  33. if (skipModel?.requiredLogin == '1') {
  34. UserInfoModel user = await Provider.of<UserInfoNotifier>(context, listen: false).getUserInfoModel();
  35. print(user.toString());
  36. if (user?.token == null || user.token == '') {
  37. print('need login...');
  38. return RouterUtil.goLogin(context);
  39. }
  40. }
  41. if (skipModel?.requiredTaobaoAuth == '1') {
  42. UserInfoModel user = await Provider.of<UserInfoNotifier>(context, listen: false).getUserInfoModel();
  43. if (!user?.isTBAuth ?? false) {
  44. TaobaoAuth.auth(context);
  45. return;
  46. }
  47. }
  48. if (skipModel?.skipIdentifier == 'pub.flutter.url') {
  49. if (skipModel?.url?.contains("sourceType=jd") ?? false) {
  50. Loading.show(context);
  51. Dio dio = Dio();
  52. var responds = await dio.get(skipModel.url);
  53. var detailUrl = responds?.realUri?.toString();
  54. Logger.debug(detailUrl ?? "");
  55. Loading.dismiss();
  56. if (await canLaunch(detailUrl)) {
  57. Jdsdk.openUrl(url: detailUrl);
  58. return;
  59. }
  60. }
  61. RouterUtil.openWebview(skipModel?.url, context);
  62. return;
  63. }
  64. if (skipModel?.skipIdentifier == 'pub.flutter.taobao_url') {
  65. print("淘宝链接" + skipModel.url);
  66. Loading.show(context);
  67. Dio dio = Dio();
  68. var responds = await dio.get(skipModel.url);
  69. var detailUrl = responds?.realUri?.toString();
  70. Logger.debug(detailUrl ?? "");
  71. Loading.dismiss();
  72. FlutterAlibc.openByUrl(url: detailUrl, schemeType: AlibcSchemeType.AlibcSchemeTaoBao);
  73. return;
  74. }
  75. Widget page = EmptyPage();
  76. if (PageFactory.hasRegisted(skipModel.skipIdentifier)) {
  77. page = PageFactory.create(skipModel.skipIdentifier, data);
  78. } else {
  79. if (Application.hasStringMethod(skipModel.skipIdentifier.toString())) {
  80. Application.doStringMethod(skipModel.skipIdentifier.toString());
  81. return null;
  82. }
  83. var result = await NetUtil.post('/api/v1/mod/${skipModel.skipIdentifier.toString()}', method: NetMethod.GET);
  84. Logger.debug(result);
  85. page = PageFactory.create('index', Map<String, dynamic>.from(result));
  86. }
  87. return Navigator.of(context).push(CupertinoPageRoute(builder: (BuildContext context) {
  88. return page;
  89. }));
  90. }
  91. // 跳转登录
  92. static Future goLogin(BuildContext context) async {
  93. String isIosReview = await SharedPreferencesUtil.getStringValue(GlobalConfig.IS_IOS_REVIEW, defaultVal: '0');
  94. return Navigator.of(context).push(CupertinoPageRoute(builder: (BuildContext context) {
  95. // 苹果审核登录样式
  96. if (Platform.isIOS && isIosReview == '1') {
  97. return LoginAccountPage(null);
  98. }
  99. return LoginPage();
  100. }));
  101. }
  102. // 打开网页
  103. static Future openWebview(String url, BuildContext context) {
  104. if (url == null || url == '') {
  105. Logger.error('跳转链接不能为空');
  106. return Future.error('跳转链接不能为空');
  107. }
  108. SkipModel model = SkipModel();
  109. model.skipIdentifier = 'pub.flutter.url';
  110. model.url = url;
  111. if (model.url.contains("official/redirect_url")) {
  112. model.url = model.url + "&zuid=" + (UserInfoNotifier?.staitcUserInfo?.userId ?? "");
  113. }
  114. Application.doStringParamsMethod("openUrl", data: {"url": model.url});
  115. return null;
  116. //
  117. // RouterUtil.route(model, model.toJson(), context);
  118. }
  119. // 回到首页
  120. static Future goBackHomePage(BuildContext context, {bool needUpdateAuth = true}) async {
  121. if (needUpdateAuth) {
  122. await TaobaoAuth.initAuth(context);
  123. EventUtil.instance.fire(LoginSuccessEvent());
  124. }
  125. Navigator.popUntil(context, ModalRoute.withName('/homePage'));
  126. }
  127. // 隐藏键盘
  128. static void hideKeyboard(BuildContext context) {
  129. try {
  130. FocusScopeNode currentFocus = FocusScope.of(context);
  131. if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
  132. FocusManager.instance.primaryFocus.unfocus();
  133. }
  134. // SystemChannels.textInput.invokeMethod('TextInput.hide');
  135. // FocusScope.of(context).requestFocus(FocusNode());
  136. } catch (e, s) {
  137. Logger.error(e, s);
  138. }
  139. }
  140. }