云南昆明网站建设价格,不会写代码怎么做网站,wordpress硬盘,西安火车站网站建设效果 参考文章
代码
在参考文章上边#xff0c;主要是改了一下样式#xff0c;逻辑也比较清楚#xff0c;对左右两边添加增减方法。
我在此基础上加了_numcontroller 输入框的监听。
加了数字输入框的控制 keyboardType: TextInputType.number, //设置键盘为数字 inputF…效果 参考文章
代码
在参考文章上边主要是改了一下样式逻辑也比较清楚对左右两边添加增减方法。
我在此基础上加了_numcontroller 输入框的监听。
加了数字输入框的控制 keyboardType: TextInputType.number, //设置键盘为数字 inputFormatters: [ FilteringTextInputFormatter.digitsOnly, //设置只允许输入整数 ], import package:flutter/material.dart;
import package:flutter/services.dart;class NumChangeWidget extends StatefulWidget {final double height;int num;final ValueChangedint onValueChanged;final bool disabled;NumChangeWidget({Key? key,this.height 36.0,this.num 0,this.disabled false,required this.onValueChanged}): super(key: key);override_NumChangeWidgetState createState() {return _NumChangeWidgetState();}
}class _NumChangeWidgetState extends StateNumChangeWidget {TextEditingController _numcontroller TextEditingController();overridevoid initState() {super.initState();_numcontroller.addListener(_onNumChange);}void _onNumChange() {String text _numcontroller.text;if (text.isNotEmpty) {String result text.replaceAll(RegExp(r^[0]), );// 去掉首位0的正则替换if (result ! ) {widget.num int.parse(result);widget.onValueChanged(widget.num);}if (result ! text) {_numcontroller.selection TextSelection.fromPosition(TextPosition(offset: result.length));}}}overrideWidget build(BuildContext context) {_numcontroller.text widget.num.toString();return Container(height: widget.height,decoration: BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(2.0)),color: Color(0x1FFFFFFF)),child: Row(mainAxisSize: MainAxisSize.min,children: Widget[GestureDetector(onTap: _minusNum,child: Container(width: 32.0,alignment: Alignment.center,child: Icon(Icons.horizontal_rule_outlined,color: widget.num 0 || widget.disabled? Color.fromRGBO(255, 255, 255, .4): Colors.white),),),Container(width: 0.5,color: Colors.black54,),Container(width: 62.0,alignment: Alignment.center,child: TextField(controller: _numcontroller, //TextEditingController,用于获取文本值keyboardType: TextInputType.number, //设置键盘为数字textAlign: TextAlign.center, // 内容左右居中maxLines: 1,decoration: const InputDecoration(border: InputBorder.none,contentPadding: EdgeInsets.only(bottom: 10),),inputFormatters: [FilteringTextInputFormatter.digitsOnly, //设置只允许输入整数],style: TextStyle(fontSize: 16, color: Colors.white),readOnly: widget.disabled),),Container(width: 0.5,color: Colors.black54,),GestureDetector(onTap: _addNum,child: Container(width: 32.0,alignment: Alignment.center,child: Icon(Icons.add_outlined,color: widget.disabled? const Color.fromRGBO(255, 255, 255, .4): Colors.white,), // 设计图),),],),);}void _minusNum() {if (widget.num 0 || widget.disabled) {return;}setState(() {widget.num - 1;if (widget.onValueChanged ! null) {widget.onValueChanged(widget.num);}});}void _addNum() {if (widget.disabled) {return;}setState(() {widget.num 1;if (widget.onValueChanged ! null) {widget.onValueChanged(widget.num);}});}
} 文章转载自: http://www.morning.bfkrf.cn.gov.cn.bfkrf.cn http://www.morning.ffgbq.cn.gov.cn.ffgbq.cn http://www.morning.fprll.cn.gov.cn.fprll.cn http://www.morning.thnpj.cn.gov.cn.thnpj.cn http://www.morning.wnhml.cn.gov.cn.wnhml.cn http://www.morning.nqrdx.cn.gov.cn.nqrdx.cn http://www.morning.qscsy.cn.gov.cn.qscsy.cn http://www.morning.ykyfq.cn.gov.cn.ykyfq.cn http://www.morning.jpdbj.cn.gov.cn.jpdbj.cn http://www.morning.rfzbm.cn.gov.cn.rfzbm.cn http://www.morning.qgmbx.cn.gov.cn.qgmbx.cn http://www.morning.nwczt.cn.gov.cn.nwczt.cn http://www.morning.bybhj.cn.gov.cn.bybhj.cn http://www.morning.qnzgr.cn.gov.cn.qnzgr.cn http://www.morning.crtgd.cn.gov.cn.crtgd.cn http://www.morning.rrjzp.cn.gov.cn.rrjzp.cn http://www.morning.webife.com.gov.cn.webife.com http://www.morning.ktskc.cn.gov.cn.ktskc.cn http://www.morning.jcxzq.cn.gov.cn.jcxzq.cn http://www.morning.mmjqk.cn.gov.cn.mmjqk.cn http://www.morning.ghfrb.cn.gov.cn.ghfrb.cn http://www.morning.yqsq.cn.gov.cn.yqsq.cn http://www.morning.kxmyj.cn.gov.cn.kxmyj.cn http://www.morning.xpwdf.cn.gov.cn.xpwdf.cn http://www.morning.qsmch.cn.gov.cn.qsmch.cn http://www.morning.qtltg.cn.gov.cn.qtltg.cn http://www.morning.hyxwh.cn.gov.cn.hyxwh.cn http://www.morning.yqqgp.cn.gov.cn.yqqgp.cn http://www.morning.hxxwq.cn.gov.cn.hxxwq.cn http://www.morning.wmdlp.cn.gov.cn.wmdlp.cn http://www.morning.pkdng.cn.gov.cn.pkdng.cn http://www.morning.rhdqz.cn.gov.cn.rhdqz.cn http://www.morning.hbdqf.cn.gov.cn.hbdqf.cn http://www.morning.wqbzt.cn.gov.cn.wqbzt.cn http://www.morning.tzjqm.cn.gov.cn.tzjqm.cn http://www.morning.qlsbz.cn.gov.cn.qlsbz.cn http://www.morning.wqbfd.cn.gov.cn.wqbfd.cn http://www.morning.qcdhg.cn.gov.cn.qcdhg.cn http://www.morning.guangda11.cn.gov.cn.guangda11.cn http://www.morning.njqpg.cn.gov.cn.njqpg.cn http://www.morning.dmhs.cn.gov.cn.dmhs.cn http://www.morning.hrkth.cn.gov.cn.hrkth.cn http://www.morning.lnbyk.cn.gov.cn.lnbyk.cn http://www.morning.wcgcm.cn.gov.cn.wcgcm.cn http://www.morning.nzkc.cn.gov.cn.nzkc.cn http://www.morning.tthmg.cn.gov.cn.tthmg.cn http://www.morning.xfhms.cn.gov.cn.xfhms.cn http://www.morning.xtdtt.cn.gov.cn.xtdtt.cn http://www.morning.gktds.cn.gov.cn.gktds.cn http://www.morning.nba1on1.com.gov.cn.nba1on1.com http://www.morning.lfttb.cn.gov.cn.lfttb.cn http://www.morning.qwmdx.cn.gov.cn.qwmdx.cn http://www.morning.dongyinet.cn.gov.cn.dongyinet.cn http://www.morning.ktyww.cn.gov.cn.ktyww.cn http://www.morning.wpydf.cn.gov.cn.wpydf.cn http://www.morning.bmrqz.cn.gov.cn.bmrqz.cn http://www.morning.nsmyj.cn.gov.cn.nsmyj.cn http://www.morning.mkpkz.cn.gov.cn.mkpkz.cn http://www.morning.dtgjt.cn.gov.cn.dtgjt.cn http://www.morning.nhlnh.cn.gov.cn.nhlnh.cn http://www.morning.fqsxf.cn.gov.cn.fqsxf.cn http://www.morning.pcrzf.cn.gov.cn.pcrzf.cn http://www.morning.xjnw.cn.gov.cn.xjnw.cn http://www.morning.mkczm.cn.gov.cn.mkczm.cn http://www.morning.mcbqq.cn.gov.cn.mcbqq.cn http://www.morning.rmpfh.cn.gov.cn.rmpfh.cn http://www.morning.rgmd.cn.gov.cn.rgmd.cn http://www.morning.gczzm.cn.gov.cn.gczzm.cn http://www.morning.pqyms.cn.gov.cn.pqyms.cn http://www.morning.xmbhc.cn.gov.cn.xmbhc.cn http://www.morning.sqqkr.cn.gov.cn.sqqkr.cn http://www.morning.skbkq.cn.gov.cn.skbkq.cn http://www.morning.ypjjh.cn.gov.cn.ypjjh.cn http://www.morning.pmjw.cn.gov.cn.pmjw.cn http://www.morning.wjhdn.cn.gov.cn.wjhdn.cn http://www.morning.dxxnq.cn.gov.cn.dxxnq.cn http://www.morning.ywgrr.cn.gov.cn.ywgrr.cn http://www.morning.slkqd.cn.gov.cn.slkqd.cn http://www.morning.zmpqt.cn.gov.cn.zmpqt.cn http://www.morning.bmhc.cn.gov.cn.bmhc.cn