网恋3要素 : 看微信是否实名、对方是否留手机号码、是否经常与对方视频
pubspec.yaml 文件里面配置图片依赖
# For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec # The following section is specific to Flutter. flutter: # The following line ensures that the Material Icons font is # included with your application, so that you can use the icons in # the material Icons class. uses-material-design: true assets: # assets-generator-begin # assets/img/* - assets/img/ic_delete.png
class InputPage extends StatefulWidget { @override _RestartWidgetState createState() => _RestartWidgetState(); } class _RestartWidgetState extends State<InputPage> { //定义一个controller TextEditingController _unameController = TextEditingController(); @override Widget build(BuildContext context) { return Scaffold( body: Container( margin: EdgeInsets.only(left: 10.0, right: 10.0), child: Row( children: [ Expanded( flex: 1, child: Container( child: TextField( autofocus: true, decoration: null, onChanged: (v) { print('编辑框的值:$v'); }, controller: _unameController, //设置controller ), ), ), GestureDetector( onTap: () { _unameController.clear(); }, child: Container( alignment: Alignment.center, width: 40.0, height: 40.0, child: Image.asset(R.assetsImgIcDelete), decoration: BoxDecoration( color: Colors.white, border: Border.all(color: Colors.purple, width: 2.0), borderRadius: BorderRadius.all(Radius.circular(10.0))), ), ), ], ), decoration: BoxDecoration( color: Colors.blue, border: Border.all(color: Colors.purple, width: 2.0), borderRadius: BorderRadius.all(Radius.circular(10.0))), ), appBar: AppBar( backgroundColor: Color(0xffFFFFFF), titleSpacing: 0.0, title: Text( 'TextField', style: TextStyle(color: Colors.blue), ), elevation: 0.0, centerTitle: true, ), ); } }
属性 decoration
TextField( autofocus: true, decoration: InputDecoration( labelText: "密码", hintText: "您的登录密码", prefixIcon: Icon(Icons.lock), border: InputBorder.none, ), onChanged: (v) { print('编辑框的值:$v'); }, controller: _unameController, //设置controller ),
prefixIcon: Image.asset(R.assetsImgIcPassword),TextField( autofocus: true, decoration: InputDecoration( labelText: "密码", hintText: "您的登录密码", prefixIcon: Image.asset(R.assetsImgIcPassword), border: InputBorder.none, ), onChanged: (v) { print('编辑框的值:$v'); }, controller: _unameController, //设置controller ),
执行结果
I/flutter ( 734): 编辑框的值:编辑 I/flutter ( 734): 编辑框的值:编辑框 I/flutter ( 734): 编辑框的值:编辑框执行 I/flutter ( 734): 编辑框的值:编辑框执行输入 I/flutter ( 734): 编辑框的值:编辑框执行输入操作