Skip to content

Commit

Permalink
完善iOS键盘适配
Browse files Browse the repository at this point in the history
  • Loading branch information
simplezhli committed Jul 21, 2019
1 parent 4b7a8de commit e99c2df
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
27 changes: 2 additions & 25 deletions lib/login/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:flutter_deer/common/common.dart';
import 'package:flutter_deer/res/resources.dart';
import 'package:flutter_deer/routers/fluro_navigator.dart';
import 'package:flutter_deer/store/store_router.dart';
import 'package:flutter_deer/util/utils.dart';
import 'package:flutter_deer/widgets/app_bar.dart';
import 'package:flutter_deer/widgets/my_button.dart';
import 'package:flutter_deer/widgets/text_field.dart';
Expand All @@ -28,30 +29,6 @@ class _LoginState extends State<Login> {
final FocusNode _nodeText2 = FocusNode();
bool _isClick = false;

KeyboardActionsConfig _buildConfig(BuildContext context) {
return KeyboardActionsConfig(
keyboardActionsPlatform: KeyboardActionsPlatform.IOS,
keyboardBarColor: Colors.grey[200],
nextFocus: true,
actions: [
KeyboardAction(
focusNode: _nodeText1,
closeWidget: Padding(
padding: EdgeInsets.all(5.0),
child: Text("关闭"),
),
),
KeyboardAction(
focusNode: _nodeText2,
closeWidget: Padding(
padding: EdgeInsets.all(5.0),
child: Text("关闭"),
),
),
],
);
}

@override
void initState() {
super.initState();
Expand Down Expand Up @@ -124,7 +101,7 @@ class _LoginState extends State<Login> {
Gaps.vGap10,
MyTextField(
focusNode: _nodeText2,
config: _buildConfig(context),
config: Utils.getKeyboardActionsConfig([_nodeText1, _nodeText2]),
isInputPwd: true,
controller: _passwordController,
maxLength: 16,
Expand Down
4 changes: 4 additions & 0 deletions lib/routers/fluro_navigator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ class NavigatorUtils {

static push(BuildContext context, String path,
{bool replace = false, bool clearStack = false}) {
FocusScope.of(context).requestFocus(new FocusNode());
Application.router.navigateTo(context, path, replace: replace, clearStack: clearStack, transition: TransitionType.native);
}

static pushResult(BuildContext context, String path, Function(Object) function,
{bool replace = false, bool clearStack = false}) {
FocusScope.of(context).requestFocus(new FocusNode());
Application.router.navigateTo(context, path, replace: replace, clearStack: clearStack, transition: TransitionType.native).then((result){
// 页面返回result为null
if (result == null){
Expand All @@ -27,11 +29,13 @@ class NavigatorUtils {

/// 返回
static void goBack(BuildContext context) {
FocusScope.of(context).requestFocus(new FocusNode());
Navigator.pop(context);
}

/// 带参数返回
static void goBackWithParams(BuildContext context, result) {
FocusScope.of(context).requestFocus(new FocusNode());
Navigator.pop(context, result);
}

Expand Down
17 changes: 17 additions & 0 deletions lib/util/utils.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

import 'package:flutter/material.dart';
import 'package:flutter_deer/util/toast.dart';
import 'package:keyboard_actions/keyboard_actions.dart';
import 'package:url_launcher/url_launcher.dart';

class Utils {
Expand All @@ -16,6 +17,22 @@ class Utils {
Toast.show('拨号失败!');
}
}

static KeyboardActionsConfig getKeyboardActionsConfig(List<FocusNode> list){
return KeyboardActionsConfig(
keyboardActionsPlatform: KeyboardActionsPlatform.IOS,
keyboardBarColor: Colors.grey[200],
nextFocus: true,
actions: List.generate(list.length, (i) => KeyboardAction(
focusNode: list[i],
closeWidget: const Padding(
padding: EdgeInsets.all(5.0),
child: Text("关闭"),
),
)),
);
}

}

/// 默认dialog背景色为半透明黑色,这里修改源码改为透明
Expand Down
1 change: 1 addition & 0 deletions lib/widgets/app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class _MyAppBarState extends State<MyAppBar> {
),
widget.isBack ? IconButton(
onPressed: (){
FocusScope.of(context).requestFocus(new FocusNode());
Navigator.maybePop(context);
},
padding: const EdgeInsets.all(12.0),
Expand Down
1 change: 1 addition & 0 deletions lib/widgets/search_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class _SearchBarState extends State<SearchBar> {
height: 48.0,
child: InkWell(
onTap: (){
FocusScope.of(context).requestFocus(new FocusNode());
Navigator.maybePop(context);
},
child: Padding(
Expand Down

0 comments on commit e99c2df

Please sign in to comment.