Flutter TextField实现双向绑定

  • Post author:
  • Post category:其他


TextField(

style: const TextStyle(color: Color(0xFFA7ABBB),fontSize: 15),

inputFormatters: [DecimalInputFormat(decimalRange: 4)],

keyboardType: TextInputType.numberWithOptions(signed: true),


controller: TextEditingController.fromValue(TextEditingValue(

text: item[‘number’],

selection: TextSelection.fromPosition(TextPosition(

affinity: TextAffinity.downstream,

offset: item[‘number’].length)

))

),


decoration: InputDecoration(

counterText: ”,

filled: true,

fillColor: Color(0xFF1A1A1A),

hintStyle: const TextStyle(color: Color(0xFFA7ABBB),fontSize: 15),

hintText: ‘请输入数量’,

contentPadding: EdgeInsets.symmetric(horizontal: 15,vertical: 10),

enabledBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(6),borderSide: BorderSide.none),

focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(6),borderSide: BorderSide.none),

suffixIcon: Container(alignment: Alignment.centerRight,child: Text(‘XBIT’,style: const TextStyle(color: Color(0xFFA7ABBB),fontSize: 15),),margin: EdgeInsets.only(right: 15),),

suffixIconConstraints: BoxConstraints(maxWidth: 80)

),

onChanged: (v){



item[‘number’] = v;

setState(() { });


},

)



版权声明:本文为u010152805原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。