首页 > 其他 > 详细

TextField

时间:2019-04-19 14:28:24      阅读:119      评论:0      收藏:0      [点我收藏+]
TextFiled 是一个输入Widget,属性如下:
this.controller,//这个是传输数据用的
this.focusNode,
this.decoration = const InputDecoration(),这个是UI设置用的
TextInputType keyboardType,这个可以设置输入键盘是数字还是字符;
this.textInputAction,
this.textCapitalization = TextCapitalization.none,
this.style,
this.strutStyle,
this.textAlign = TextAlign.start,
this.textDirection,
this.autofocus = false,
this.obscureText = false,
this.autocorrect = true,
this.maxLines = 1,
this.minLines,
this.expands = false,
this.maxLength,
this.maxLengthEnforced = true,
this.onChanged, 这个是回调函数
this.onEditingComplete,
this.onSubmitted,
this.inputFormatters,
this.enabled,
this.cursorWidth = 2.0,
this.cursorRadius,
this.cursorColor,
this.keyboardAppearance,
this.scrollPadding = const EdgeInsets.all(20.0),
this.dragStartBehavior = DragStartBehavior.start,
this.enableInteractiveSelection,
this.onTap,
this.buildCounter,

下面是一个完整的示例:
import ‘package:flutter/material.dart‘;

import ‘package:flutter/cupertino.dart‘;

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: ExampleWidget(),
),
);
}
}
/// Opens an [AlertDialog] showing what the user typed.
class ExampleWidget extends StatefulWidget {
@override
_ExampleWidgetState createState() => new _ExampleWidgetState();
}

class _ExampleWidgetState extends State<ExampleWidget> {
final TextEditingController _controller = TextEditingController();
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new TextField(
controller: _controller,
decoration: InputDecoration(
contentPadding: EdgeInsets.all(10.0),
labelText:‘Be noticed to write something down‘,
hintText: ‘Type something‘,
),
onChanged: (text){setState(() {
print(text);
});},
),
new RaisedButton(
onPressed: () {
showDialog(
context: context,
builder: (context){
return AlertDialog(
title:Text(‘What you typed‘),
content:Text(_controller.text),
);
}
);
},
child: new Text(‘DONE‘),
),
],
);
}
}

TextField

原文:https://www.cnblogs.com/braveheart007/p/10735355.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!