diff --git a/lib/util/empty_util.dart b/lib/util/empty_util.dart index 22691df..a0f6b62 100644 --- a/lib/util/empty_util.dart +++ b/lib/util/empty_util.dart @@ -4,14 +4,14 @@ class EmptyUtil { /// 判断是否为空,object的类型可以为:String Map List static bool isEmpty(Object object) { if (null == object) return true; - if (object is String && object.isEmpty) { + if (object is String && (object.isEmpty || object.length == 0)) { return true; } - if (object is List && object.isEmpty) { + if (object is List && (object.isEmpty || object.length == 0)) { return true; } - if (object is Map && object.isEmpty) { + if (object is Map && (object.isEmpty || object.length == 0)) { return true; } return false; diff --git a/lib/util/router_util.dart b/lib/util/router_util.dart index fbd1fce..834ad4d 100644 --- a/lib/util/router_util.dart +++ b/lib/util/router_util.dart @@ -1,5 +1,6 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:provider/provider.dart'; import 'package:zhiying_comm/pages/login_page/login_page.dart'; import 'package:zhiying_comm/zhiying_comm.dart'; @@ -16,7 +17,7 @@ class RouterUtil { return Future.error('skipIdentifier 参数不存在,无法跳转页面'); } print('skipIdentifier: ${skipModel.skipIdentifier}'); - + hideKeyboard(context); if (skipModel?.requiredLogin == '1') { UserInfoModel user = await Provider.of(context, listen: false) @@ -62,4 +63,19 @@ class RouterUtil { model.url = url; RouterUtil.route(model, null, context); } + + + static void hideKeyboard(BuildContext context){ + try { + FocusScopeNode currentFocus = FocusScope.of(context); + 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); + } + } }