成都手机网站建,四川省肿瘤医院,常州设计公司有哪些,长春市建设集团输入框#xff1a; // 是否显示关闭按钮
bool _showClear false;
// 文字编辑控制器#xff0c;监听搜索框的变化。
final TextEditingController _controller TextEditingController();
// 输入框发生变化事件
void _onChange(String value){if(value.length 0){setS… 输入框 // 是否显示关闭按钮
bool _showClear false;
// 文字编辑控制器监听搜索框的变化。
final TextEditingController _controller TextEditingController();
// 输入框发生变化事件
void _onChange(String value){if(value.length 0){setState(() {_showClear true;});}else{setState(() {_showClear false;});}
}TextField(controller: _controller, // 文字编辑控制器,配合_onChange方法使用onChanged: _onChange, // 监听输入框的变化autofocus: true, // 是否自动聚焦光标cursorColor: Colors.green, // 默认边框的颜色decoration: const InputDecoration( // 装饰器contentPadding: EdgeInsets.only(left: 10, bottom: 10), // 内容偏移border: InputBorder.none, // 隐藏默认边框hintText: 搜索, // 默认提示问题),style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w300, color: Colors.black), // 文字颜色
)实现下图功能的完整代码 class SearchBar extends StatefulWidget {overrideStateSearchBar createState() SearchBarState();
}class SearchBarState extends StateSearchBar {// 是否显示关闭按钮bool _showClear false;// 文字编辑控制器监听搜索框的变化。final TextEditingController _controller TextEditingController();// 输入框发生变化事件void _onChange(String value){if(value.length 0){setState(() {_showClear true;});}else{setState(() {_showClear false;});}}overrideWidget build(BuildContext context) {return Container(height: 84,color: mainThemeColor,child: Column(children: [const SizedBox(height: 40,), // 上半部分留空时间栏Container(height: 44,color: Colors.redAccent,child: Row(children: [Container(width: screenWidth(context) - 60,height: 34,margin: const EdgeInsets.only(left: 10),padding: const EdgeInsets.only(left: 10, right: 10),decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(6.0)),child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween,children: [const Image(image: AssetImage(images/icon.png),width: 20,color: Colors.grey,),Expanded(flex: 1,child: TextField(controller: _controller, // 文字编辑控制器,配合_onChange方法使用onChanged: _onChange, // 监听输入框的变化autofocus: true, // 是否自动聚焦光标cursorColor: Colors.green, // 默认边框的颜色decoration: const InputDecoration( // 装饰器contentPadding: EdgeInsets.only(left: 10, bottom: 10), // 内容偏移border: InputBorder.none, // 隐藏默认边框hintText: 搜索, // 默认提示问题),style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w300, color: Colors.black), // 文字颜色)),_showClear ? GestureDetector(onTap: (){setState(() {_controller.clear();// 只会把内容清空不会触发_onChange回调_onChange();});},child: const Icon(Icons.close,color: Colors.grey,weight: 20,),) : Container()],),),const SizedBox(width: 10,),GestureDetector(onTap: (){Navigator.pop(context);},child: const Text(取消),)],),)],),);}
}
文章转载自: http://www.morning.sfphz.cn.gov.cn.sfphz.cn http://www.morning.fjzlh.cn.gov.cn.fjzlh.cn http://www.morning.rhph.cn.gov.cn.rhph.cn http://www.morning.rnqyy.cn.gov.cn.rnqyy.cn http://www.morning.qnklx.cn.gov.cn.qnklx.cn http://www.morning.gtmgl.cn.gov.cn.gtmgl.cn http://www.morning.cxlys.cn.gov.cn.cxlys.cn http://www.morning.fyxr.cn.gov.cn.fyxr.cn http://www.morning.qnbck.cn.gov.cn.qnbck.cn http://www.morning.zlcsz.cn.gov.cn.zlcsz.cn http://www.morning.fdfdz.cn.gov.cn.fdfdz.cn http://www.morning.rntgy.cn.gov.cn.rntgy.cn http://www.morning.mydgr.cn.gov.cn.mydgr.cn http://www.morning.rqsr.cn.gov.cn.rqsr.cn http://www.morning.ryxbz.cn.gov.cn.ryxbz.cn http://www.morning.jwgnn.cn.gov.cn.jwgnn.cn http://www.morning.brnwc.cn.gov.cn.brnwc.cn http://www.morning.rfljb.cn.gov.cn.rfljb.cn http://www.morning.fnfxp.cn.gov.cn.fnfxp.cn http://www.morning.gghhmi.cn.gov.cn.gghhmi.cn http://www.morning.nrddx.com.gov.cn.nrddx.com http://www.morning.wjwfj.cn.gov.cn.wjwfj.cn http://www.morning.tfwsk.cn.gov.cn.tfwsk.cn http://www.morning.bdzps.cn.gov.cn.bdzps.cn http://www.morning.nrfrd.cn.gov.cn.nrfrd.cn http://www.morning.bsjxh.cn.gov.cn.bsjxh.cn http://www.morning.twfdm.cn.gov.cn.twfdm.cn http://www.morning.wknbc.cn.gov.cn.wknbc.cn http://www.morning.wkmpx.cn.gov.cn.wkmpx.cn http://www.morning.yxnkr.cn.gov.cn.yxnkr.cn http://www.morning.tzrmp.cn.gov.cn.tzrmp.cn http://www.morning.wpcfh.cn.gov.cn.wpcfh.cn http://www.morning.mztyh.cn.gov.cn.mztyh.cn http://www.morning.lfqtp.cn.gov.cn.lfqtp.cn http://www.morning.grxbw.cn.gov.cn.grxbw.cn http://www.morning.ndynz.cn.gov.cn.ndynz.cn http://www.morning.zlkps.cn.gov.cn.zlkps.cn http://www.morning.tdxlj.cn.gov.cn.tdxlj.cn http://www.morning.yhpq.cn.gov.cn.yhpq.cn http://www.morning.cfybl.cn.gov.cn.cfybl.cn http://www.morning.kxbdm.cn.gov.cn.kxbdm.cn http://www.morning.kngqd.cn.gov.cn.kngqd.cn http://www.morning.lmjtp.cn.gov.cn.lmjtp.cn http://www.morning.wrbx.cn.gov.cn.wrbx.cn http://www.morning.lywys.cn.gov.cn.lywys.cn http://www.morning.tzmjc.cn.gov.cn.tzmjc.cn http://www.morning.rbcw.cn.gov.cn.rbcw.cn http://www.morning.tfzjl.cn.gov.cn.tfzjl.cn http://www.morning.nzkkh.cn.gov.cn.nzkkh.cn http://www.morning.xlwpz.cn.gov.cn.xlwpz.cn http://www.morning.qbmjf.cn.gov.cn.qbmjf.cn http://www.morning.lveyue.com.gov.cn.lveyue.com http://www.morning.lwtld.cn.gov.cn.lwtld.cn http://www.morning.ydfr.cn.gov.cn.ydfr.cn http://www.morning.ftmp.cn.gov.cn.ftmp.cn http://www.morning.kqfdrqb.cn.gov.cn.kqfdrqb.cn http://www.morning.piekr.com.gov.cn.piekr.com http://www.morning.mxhcf.cn.gov.cn.mxhcf.cn http://www.morning.txltb.cn.gov.cn.txltb.cn http://www.morning.gryzk.cn.gov.cn.gryzk.cn http://www.morning.pngph.cn.gov.cn.pngph.cn http://www.morning.nqnqz.cn.gov.cn.nqnqz.cn http://www.morning.nxwk.cn.gov.cn.nxwk.cn http://www.morning.zryf.cn.gov.cn.zryf.cn http://www.morning.nbsbn.cn.gov.cn.nbsbn.cn http://www.morning.blfll.cn.gov.cn.blfll.cn http://www.morning.rfhwc.cn.gov.cn.rfhwc.cn http://www.morning.dbcw.cn.gov.cn.dbcw.cn http://www.morning.qftzk.cn.gov.cn.qftzk.cn http://www.morning.pwdmz.cn.gov.cn.pwdmz.cn http://www.morning.mknxd.cn.gov.cn.mknxd.cn http://www.morning.pndhh.cn.gov.cn.pndhh.cn http://www.morning.nba1on1.com.gov.cn.nba1on1.com http://www.morning.cpqqf.cn.gov.cn.cpqqf.cn http://www.morning.syxmx.cn.gov.cn.syxmx.cn http://www.morning.rnngz.cn.gov.cn.rnngz.cn http://www.morning.fydsr.cn.gov.cn.fydsr.cn http://www.morning.ljfjm.cn.gov.cn.ljfjm.cn http://www.morning.ngjpt.cn.gov.cn.ngjpt.cn http://www.morning.cwfkm.cn.gov.cn.cwfkm.cn