美文网首页
flutter 自定义帐号输入控件

flutter 自定义帐号输入控件

作者: 不敌菜鸡的万分之一 | 来源:发表于2019-12-11 18:16 被阅读0次

自定义组合控件

  1. LoginInputText代码如下:
import 'package:flutter/material.dart';

class LoginInputText extends StatelessWidget {
  final Icon icon;
  final imageName;
  final text;
  final hintText;
  final double width;
  final double height;
  final Color color;
  final double size;
  final double hintSize;
  final bool obscureText;
  final textValue;
  final TextEditingController controller;

  const LoginInputText({
    Key key,
    this.icon,
    this.text,
    this.width = 200.0,
    this.height = 44.0,
    this.color,
    this.size = 14.0,
    this.imageName,
    this.hintText = '',
    this.hintSize = 14.0,
    this.obscureText = false,
    this.textValue,
    this.controller,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return new Container(
      width: width,
      height: height,
      decoration: new BoxDecoration(
        color: color,
      ),
      child: new Row(
        children: <Widget>[
          new Image.asset(
            imageName,
            width: 24.0,
            height: 24.0,
          ),
          //new Icon(Icons.assessment),
          new Container(
            width: 10.0,
          ),
          new Text(text),
          new Container(
            width: 5.0,
          ),
          new Expanded(
            child: new TextField(
              keyboardType: TextInputType.text,
              decoration: InputDecoration(
                hintText: hintText,
                hintStyle: new TextStyle(
                  fontSize: hintSize,
                ),
                border: InputBorder.none,
              ),
              obscureText: obscureText,
              autofocus: false,
              controller: controller,
              /*onChanged: (value) {
                controller.text = value;
                print('onChanged:$value');
              },*/
            ),
          ),
        ],
      ),
    );
  }
}
  1. 使用方式如下
TextEditingController _name = TextEditingController();
TextEditingController _pass = TextEditingController();
new LoginInputText(
            width: 250.0,
            height: 44.0,
            text: '帐号: ',
            //color: Colors.yellow,
            imageName: 'images/me.png',
            hintText: '请输入用户名',
            controller: _name,
          ),
new LoginInputText(
            width: 250.0,
            height: 44.0,
            text: '密码: ',
            //color: Colors.yellow,
            imageName: 'images/icon_password.png',
            hintText: '请输入密码',
            obscureText: true,
            controller: _pass,
          ),

好记性不如烂笔头_记录学习中的坑

相关文章

网友评论

      本文标题:flutter 自定义帐号输入控件

      本文链接:https://www.haomeiwen.com/subject/qnlagctx.html