Преглед на файлове

1.添加标识到方法调用

tags/0.0.10
“yanghuaxuan” преди 3 години
родител
ревизия
1d72b45f7f
променени са 3 файла, в които са добавени 47 реда и са изтрити 22 реда
  1. +23
    -0
      lib/util/application.dart
  2. +23
    -22
      lib/util/router_util.dart
  3. +1
    -0
      lib/zhiying_comm.dart

+ 23
- 0
lib/util/application.dart Целия файл

@@ -4,6 +4,9 @@ class Application {
// 初始化方法
static List<InitMethod> _initMethods = List();

///有标签的方法用于没有页面的第三模块调用
static Map<String, InitMethod> _initStringMethods = Map();

static Future init() async {
for (InitMethod method in _initMethods) {
await method();
@@ -15,4 +18,24 @@ class Application {
static addMethod(InitMethod method) {
_initMethods.add(method);
}

static addStringMethod({String type, InitMethod method}) {
if(type==null||method==null){
return;
}
_initStringMethods[type] = method;
}

static bool hasStringMethod(String type){
return _initStringMethods.containsKey(type);
}

static doStringMethod(String type){
if(_initStringMethods.containsKey(type)){
print("存在方法"+type);
_initStringMethods[type]();
}else{
print("不存在方法"+type);
}
}
}

+ 23
- 22
lib/util/router_util.dart Целия файл

@@ -15,22 +15,24 @@ class RouterUtil {
* skipModel 跳转参数
* data 额外参数
* */
static Future route(SkipModel skipModel, Map<String, dynamic> data,
BuildContext context) async {
static Future route(SkipModel skipModel, Map<String, dynamic> data, BuildContext context) async {
// skipModel.skipIdentifier="pub.flutter.credit_card";
// if (Application.hasStringMethod(skipModel.skipIdentifier.toString())) {
// Application.doStringMethod(skipModel.skipIdentifier.toString());
// return null;
// }
if (skipModel.skipIdentifier == null || skipModel.skipIdentifier == '') {
print('skipIdentifier 参数不存在,无法跳转页面');
return Future.error('skipIdentifier 参数不存在,无法跳转页面');
}
// is_jump等于0不跳转
if(!EmptyUtil.isEmpty(skipModel.isJump) && skipModel.isJump == '0') {
if (!EmptyUtil.isEmpty(skipModel.isJump) && skipModel.isJump == '0') {
return;
}
print('skipIdentifier: ${skipModel.skipIdentifier}');
hideKeyboard(context);
if (skipModel?.requiredLogin == '1') {
UserInfoModel user =
await Provider.of<UserInfoNotifier>(context, listen: false)
.getUserInfoModel();
UserInfoModel user = await Provider.of<UserInfoNotifier>(context, listen: false).getUserInfoModel();
print(user.toString());
if (user?.token == null || user.token == '') {
print('need login...');
@@ -42,25 +44,25 @@ class RouterUtil {
if (PageFactory.hasRegisted(skipModel.skipIdentifier)) {
page = PageFactory.create(skipModel.skipIdentifier, data);
} else {
var result = await NetUtil.post(
'/api/v1/mod/${skipModel.skipIdentifier.toString()}',
method: NetMethod.GET);
if (Application.hasStringMethod(skipModel.skipIdentifier.toString())) {
Application.doStringMethod(skipModel.skipIdentifier.toString());
return null;
}
var result = await NetUtil.post('/api/v1/mod/${skipModel.skipIdentifier.toString()}', method: NetMethod.GET);
Logger.debug(result);
page = PageFactory.create('index', Map<String, dynamic>.from(result));
}
return Navigator.of(context)
.push(CupertinoPageRoute(builder: (BuildContext context) {
return Navigator.of(context).push(CupertinoPageRoute(builder: (BuildContext context) {
return page;
}));
}

// 跳转登录
static Future goLogin(BuildContext context) async{
static Future goLogin(BuildContext context) async {
String isIosReview = await SharedPreferencesUtil.getStringValue(GlobalConfig.IS_IOS_REVIEW, defaultVal: '0');
return Navigator.of(context)
.push(CupertinoPageRoute(builder: (BuildContext context) {
return Navigator.of(context).push(CupertinoPageRoute(builder: (BuildContext context) {
// 苹果审核登录样式
if(Platform.isIOS && isIosReview == '1'){
if (Platform.isIOS && isIosReview == '1') {
return LoginAccountPage(null);
}
return LoginPage();
@@ -80,8 +82,8 @@ class RouterUtil {
}

// 回到首页
static Future goBackHomePage(BuildContext context, {bool needUpdateAuth = true}) async{
if(needUpdateAuth) {
static Future goBackHomePage(BuildContext context, {bool needUpdateAuth = true}) async {
if (needUpdateAuth) {
await TaobaoAuth.initAuth(context);
EventUtil.instance.fire(LoginSuccessEvent());
}
@@ -89,17 +91,16 @@ class RouterUtil {
}

// 隐藏键盘
static void hideKeyboard(BuildContext context){
static void hideKeyboard(BuildContext context) {
try {
FocusScopeNode currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus &&
currentFocus.focusedChild != null) {
if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
FocusManager.instance.primaryFocus.unfocus();
}
// SystemChannels.textInput.invokeMethod('TextInput.hide');
// FocusScope.of(context).requestFocus(FocusNode());
}catch(e, s){
Logger.error(e,s);
} catch (e, s) {
Logger.error(e, s);
}
}
}

+ 1
- 0
lib/zhiying_comm.dart Целия файл

@@ -53,3 +53,4 @@ export 'package:permission_handler/permission_handler.dart';
export 'package:zhiying_comm/util/shared_prefe_util.dart';
export 'package:fluttertoast/fluttertoast.dart';
export 'package:zhiying_comm/util/launcher_wx_mini_program.dart';
export 'package:zhiying_comm/util/application.dart';

Зареждане…
Отказ
Запис