Flutter TextField自定义

网恋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): 编辑框的值:编辑框执行输入操作

 

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

️ 邪神

你自己看着办,你喜欢打赏我就赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值