当前位置:网站首页>Shutter input box assembly
Shutter input box assembly
2022-06-21 20:40:00 【xiangxiongfly915】
List of articles
Flutter Input box components
Basic attributes
autofocus: Get focus automatically .
obscureText: Password input box .
showCursor & cursorWidth & cursorRadius & cursorColor: Whether the cursor displays 、 Cursor width 、 Round corners 、 Color .
textAlign: Horizontal alignment of text .
textAlignVertical: Vertical alignment of text .
style: Text style .
maxLength: Input box maximum length .
inputFormatters: Format the contents of the input box , Value allows you to enter data in the specified format .
- FilteringTextInputFormatter.allow(RegExp("[a-zA-Z]")): Only a-zA-Z.
- FilteringTextInputFormatter.digitsOnly: Number only 1-9.
decoration:TextField Decoration of components , The type is InputDecoration, You can set the text 、 Tip text 、 Patterns, etc .
- labelText:label Text .
- labelStyle:label Text style
- hintText: Prompt text when the input box is empty .
- hintStyle:hint Text style .
- icon: The icon in front of the input box
- prefixIcon: The icon in front of the input box .
- prefix: Input the front components in the box .
- contentPadding: padding .
controller: Used to control the input box , Listen for changes in the input box 、 Set default text 、 Check the contents of the input box .
onChange: Listen for changes in the input box .
onTap: Callback when clicking the input box .
onSubmitted: Call back when you click the Enter key on the soft keyboard .
keyboardType: Control the type of soft keyboard input
- text: Universal keyboard .
- multiline: Multiline text , Support line break , Need to cooperate with maxLines Use .
- number: The keypad .
- phone: The phone keyboard , Compared with the number keyboard “*” and “#”.
- datetime: Date time keyboard .
- emailAddress: Mail keyboard .
- url:url Input keyboard .
- visiblePassword: Letter and number keyboards .
textInputAction: Soft keyboard enter icon .
Easy to use

final TextEditingController _usernameController = TextEditingController();
final TextEditingController _descController = TextEditingController();
var descriptionCount = "";
@override
void initState() {
// Monitoring content changes
_usernameController.addListener(() {
print(" Content monitoring 1:${_usernameController.text}");
});
// Set the default value
_descController.text = "helloworld";
// Set selection text
_descController.selection = TextSelection(
baseOffset: 0,
extentOffset: _descController.text.length,
);
super.initState();
}
@override
void dispose() {
_usernameController.dispose();
_descController.dispose();
super.dispose();
}
TextField(
controller: _usernameController,
inputFormatters: [
FilteringTextInputFormatter.allow(RegExp("[a-zA-Z]")),
],
decoration: const InputDecoration(
labelText: " user name ",
hintText: " Please enter a user name ( Only English characters are allowed )",
prefixIcon: Icon(Icons.person),
),
onChanged: (value) {
print(" Content monitoring 2:$value");
},
),
TextField(
inputFormatters: [
FilteringTextInputFormatter.allow(RegExp("[a-zA-Z0-9.]")),
],
decoration: const InputDecoration(
labelText: " mailbox ",
hintText: " Please enter your email account ",
prefixIcon: Icon(Icons.mail),
),
keyboardType: TextInputType.emailAddress,
),
TextField(
inputFormatters: [
FilteringTextInputFormatter.digitsOnly,
],
decoration: const InputDecoration(
labelText: " password ",
hintText: " Please input a password ( Allow input only 6 Bit is the number above )",
prefixIcon: Icon(Icons.lock),
),
keyboardType: TextInputType.number,
obscureText: true,
),
TextField(
autofocus: true,
maxLines: 3,
maxLength: 32,
controller: _descController,
onChanged: (value) {
setState(() {
descriptionCount = value;
});
},
decoration: InputDecoration(
labelText: " describe ",
hintText: " Please enter a description ",
prefixIcon: const Icon(Icons.description),
counterText: "${descriptionCount.length}/32",
),
keyboardType: TextInputType.multiline,
)
Focus control
Focus control can be achieved by FocusNode and FocusScopeNode To control . In general , Simple by FoucusNode management , It represents the focus control area , You can go through... In this range FocusScopeNode Move focus between input boxes 、 Set default focus etc .

FocusNode focusNode1 = FocusNode();
FocusNode focusNode2 = FocusNode();
FocusScopeNode? focusScopeNode;
@override
void dispose() {
focusNode1.dispose();
focusNode2.dispose();
focusScopeNode?.dispose();
super.dispose();
}
TextField(
autofocus: true,
focusNode: focusNode1,
decoration: const InputDecoration(
labelText: "input1",
),
),
TextField(
autofocus: true,
focusNode: focusNode2,
decoration: const InputDecoration(
labelText: "input2",
),
),
ElevatedButton(
onPressed: () {
// Mode one
FocusScope.of(context).requestFocus(focusNode1);
},
child: const Text("input1 Get focus "),
),
ElevatedButton(
onPressed: () {
// Mode two
focusScopeNode ??= FocusScope.of(context);
focusScopeNode?.requestFocus(focusNode2);
},
child: const Text("input2 Get focus "),
),
ElevatedButton(
onPressed: () {
// Mode one
focusNode1.unfocus();
focusNode2.unfocus();
// Mode two
// focusScopeNode?.unfocus();
},
child: const Text(" Hidden keyboard "),
),
Custom style 1

Padding(
padding: EdgeInsets.all(10),
child: TextField(
textAlign: TextAlign.center,
decoration: InputDecoration(
fillColor: Color(0x30cccccc),
filled: true,
hintText: "QQ/ mailbox / cell-phone number ",
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(100)),
borderSide: BorderSide(color: Colors.grey),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(100)),
borderSide: BorderSide(color: Colors.black),
),
),
),
)
Custom style 2

final FocusNode focusNode1 = FocusNode();
final FocusNode focusNode2 = FocusNode();
bool _hasFocus1 = false;
bool _hasFocus2 = false;
@override
void initState() {
super.initState();
focusNode1.addListener(() {
if (_hasFocus1 != focusNode1.hasFocus) {
setState(() {
_hasFocus1 = focusNode1.hasFocus;
});
}
});
focusNode2.addListener(() {
if (_hasFocus2 != focusNode2.hasFocus) {
setState(() {
_hasFocus2 = focusNode2.hasFocus;
});
}
});
}
@override
void dispose() {
focusNode1.dispose();
focusNode2.dispose();
super.dispose();
}
Padding(
padding: const EdgeInsets.all(10),
child: Column(
children: [
Container(
child: TextField(
focusNode: focusNode1,
cursorColor: Colors.black,
decoration: InputDecoration(
labelText: " user name ",
labelStyle: TextStyle(
color: _hasFocus1 ? Colors.black : Colors.grey,
),
hintText: " Please enter a user name ",
prefixIcon: Icon(
Icons.people,
color: _hasFocus1 ? Colors.red : Colors.grey,
),
border: InputBorder.none,
),
),
decoration: BoxDecoration(
border: Border.all(
color: _hasFocus1 ? Colors.red : Colors.grey,
width: 1,
),
borderRadius: const BorderRadius.all(Radius.circular(10)),
),
),
const SizedBox(
height: 5,
),
Container(
child: TextField(
focusNode: focusNode2,
cursorColor: Colors.black,
decoration: InputDecoration(
labelText: " password ",
labelStyle: TextStyle(
color: _hasFocus2 ? Colors.black : Colors.grey,
),
hintText: " Please input a password ",
prefixIcon: Icon(
Icons.lock,
color: _hasFocus2 ? Colors.red : Colors.grey,
),
border: InputBorder.none,
),
obscureText: true,
),
decoration: BoxDecoration(
border: Border.all(
color: _hasFocus2 ? Colors.red : Colors.grey,
width: 1,
),
borderRadius: BorderRadius.circular(10),
),
),
],
),
)
边栏推荐
- 通过flinksql 的方式使其部分字段更新可以么?
- How to distinguish between machine learning and pattern recognition?
- TC3608H高效率 1.2MHz DC-DC 升压器 IC
- 如何使用Memcached实现Django项目缓存
- XR34082A高效率升压DC/DC调整器IC
- 某大厂第二轮裁员来袭,套路满满
- The highest monthly salary is 17k. As long as there is a field of hope in your heart, hard work will usher in a green land~
- What statements are added to MySQL
- Visualization of operation and maintenance monitoring data - let the data speak [Huahui data]
- Anfulai embedded weekly report (issue 270): June 13, 2022 to June 19, 2022
猜你喜欢

起飞,年薪40万+

产品创新 | 物极必反,回归真实生活的创新社交APP

TC3608H高效率 1.2MHz DC-DC 升压器 IC

软件测试办公工具推荐-桌面日历

Implementation principle and application practice of Flink CDC mongodb connector

Comment MySQL additionne les colonnes

FS9935 高效率恒流限流 WLED 驱动IC

Cocoapods安装(Xcode8.0之后,无限卡在Setting up CocoaPods master repo)

第十七届全国大学 RT-Thread创新专项奖

自然语言处理如何实现聊天机器人?
随机推荐
Flink-connector-mysql-cdc-2.2.0, the full snapshot generation phase, is based on the table
黄金哪些值得注意的技术:资金管理的重要性
What are the knowledge points of SQL statements
I remember that procedure cannot be written in maxcomputer. If you want to use Oracle procedure
细节、MYSQL_DATE_FORMAT()_函数_详解(记得收藏)
LN2220 2A过流5V1A高效率升压IC芯片 DC/DC 电压调整器
How to redeem financial products after the opening date?
How MySQL sums columns
软件测试办公工具推荐-桌面日历
[wechat applet failed to change appid] wechat applet failed to modify appid all the time and reported an error. Tourist appid solution
The highest monthly salary is 17k. As long as there is a field of hope in your heart, hard work will usher in a green land~
IAR major upgrade, support vs code, St release the first sensor with processing unit
Analysis of ${} string splicing in JS
How to distinguish between machine learning and pattern recognition?
The 17th National University RT thread innovation special award
拼多多618手机品牌官旗销量同比增长124%,4000+高价位手机同比增长156%
TX9118 同步升压IC
互联网协议入门详解--五层模型
YB5212A充电IC充电芯片sop8
第十七届全国大学 RT-Thread创新专项奖