颤动数字键盘没有完成按钮
Posted
技术标签:
【中文标题】颤动数字键盘没有完成按钮【英文标题】:flutter number keyboard doesn't have done button 【发布时间】:2019-02-14 02:02:06 【问题描述】:我在我的 TextField 中使用 TextInputType.number。但是键盘内没有任何完成或下一步按钮。TextInputAction.done 在数字键盘上不起作用。我该怎么办?
【问题讨论】:
您使用的是哪个版本的 Flutter?textInputAction
属性是最近添加的。
我使用的是最新版本。 TextInputType.number 不支持 textInputAction。我正在尝试寻找其他解决方案。
您找到解决方案了吗?也遇到了同样的问题。
不,我没有找到任何解决方案。
您可以使用自定义方法,我刚刚在媒体上为此发布了一个故事。 medium.com/@webianks/…
【参考方案1】:
我刚刚创建了一个包,用于向当前键盘添加基本操作。
你可以看看这里:
https://pub.dartlang.org/packages/keyboard_actions
示例代码:
import 'package:flutter/material.dart';
import 'package:keyboard_actions/keyboard_actions.dart';
//...
FocusNode _nodeText1 = FocusNode();
FocusNode _nodeText2 = FocusNode();
FocusNode _nodeText3 = FocusNode();
FocusNode _nodeText4 = FocusNode();
FocusNode _nodeText5 = FocusNode();
@override
Widget build(BuildContext context)
return Scaffold(
appBar: AppBar(
title: Text("Keyboard Actions Sample"),
),
body: FormKeyboardActions(
keyboardActionsPlatform: KeyboardActionsPlatform.ALL, //optional
keyboardBarColor: Colors.grey, //optional
nextFocus: true, //optional
actions: [
KeyboardAction(
focusNode: _nodeText1,
),
KeyboardAction(
focusNode: _nodeText2,
closeWidget: IconButton(
icon: Icon(Icons.close),
onPressed: () ,
),
),
KeyboardAction(
focusNode: _nodeText3,
onTapAction: ()
showDialog(
context: context,
builder: (context)
return AlertDialog(
content: Text("Custom Action"),
actions: <Widget>[
FlatButton(
child: Text("OK"),
onPressed: () => Navigator.of(context).pop(),
)
],
);
);
,
),
KeyboardAction(
focusNode: _nodeText4,
displayCloseWidget: false,
),
KeyboardAction(
focusNode: _nodeText5,
closeWidget: Padding(
padding: EdgeInsets.all(5.0),
child: Text("CLOSE"),
),
),
],
child: Padding(
padding: const EdgeInsets.all(15.0),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
TextField(
keyboardType: TextInputType.number,
focusNode: _nodeText1,
decoration: InputDecoration(
hintText: "Input Number",
),
),
TextField(
keyboardType: TextInputType.text,
focusNode: _nodeText2,
decoration: InputDecoration(
hintText: "Input Text with Custom Close Widget",
),
),
TextField(
keyboardType: TextInputType.number,
focusNode: _nodeText3,
decoration: InputDecoration(
hintText: "Input Number with Custom Action",
),
),
TextField(
keyboardType: TextInputType.text,
focusNode: _nodeText4,
decoration: InputDecoration(
hintText: "Input Text without Close Widget",
),
),
TextField(
keyboardType: TextInputType.number,
focusNode: _nodeText5,
decoration: InputDecoration(
hintText: "Input Number with Custom Close Widget",
),
),
],
),
),
),
),
);
【讨论】:
以上是关于颤动数字键盘没有完成按钮的主要内容,如果未能解决你的问题,请参考以下文章