大佬教程收集整理的这篇文章主要介绍了flutter – 在TextFormField上捕捉点击事件,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用GestureDetector将TextFormField作为子元素执行,但点击它时没有任何东西触发:
@override Widget build(BuildContext context) { return new Scaffold( key: _scaffoldKey,appBar: new AppBar(title: const Text('Recherche de sorties')),body: new DropdownButtonHideUnderline( child: new Form( key: _formKey,autovalidate: _autovalidate,child: new ListView( padding: const EdgeInsets.symmetric(horizontal: 16.0),children: <Widget>[ new DatePicker( labelText: 'Date',selectedDate: widget.request.dateDebut,initialDate: widget.request.dateDebut,firstDate: new DateTime.Now().add(new Duration(days: -1)),lastDate: new DateTime.Now().add(new Duration(days: 365 * 4)),selectDate: (DateTime value) { setState(() { widget.request.dateDebut = value; }); },datePickerMode: DatePickerMode.day,icon: const Icon(Icons.date_range),),new InputDecorator( decoration: const InputDecoration( labelText: 'Rayon',hintText: '-- Choisissez un rayon --',icon: const Icon(Icons.settings_backup_restore),isEmpty: widget.request.rayon == null,child: new DropdownButton<String>( value: widget.request.rayon.toString(),isDense: true,onChanged: (String newValue) { setState(() { widget.request.rayon = int.parse(newValue); }); },items: _rayons.keys.map((int key) { return new DropdownMenuItem<String>( value: key.toString(),child: new Text(_rayons[key]),); }).toList(),new GestureDetector( onTap: () async { print("Container clicked"); Prediction p = await showGooglePlacesAutocomplete( context: context,apiKey: Consts.googlePlacesApiKey,mode: Mode.fullscreen,language: "fr",components: [new Component(Component.country,"fr")]); if (p != null) { (_scaffoldKey.currentState).showSnackBar( new SnackBar(content: new Text(p.description))); } },child: new TextFormField( // controller: controller,decoration: const InputDecoration( icon: const Icon(Icons.room),hintText: 'Où êtes vous ?',labelText: 'Localisation',new Container( padding: const EdgeInsets.all(20.0),alignment: Alignment.center,child: new Align( alignment: const Alignment(0.0,-0.2),child: new ButtonBar( mainAxisSize: MainAxisSize.min,children: <Widget>[ new RaisedButton( child: const Text('ANNULER'),onPressed: _fermerCritereRecherche,new RaisedButton( child: const Text('VALIDER'),onPressed: _valider,],)),]),); }
如果我更换:
new GestureDetector( onTap: () async { print("Container clicked"); Prediction p = await showGooglePlacesAutocomplete( context: context,"fr")]); if (p != null) { (_scaffoldKey.currentState).showSnackBar( new SnackBar(content: new Text(p.description))); } },child: new TextFormField( // controller: controller,decoration: const InputDecoration( icon: const Icon(Icons.room),
通过一个简单的容器,它正在工作:
new GestureDetector( onTap: () async { print("Container clicked"); Prediction p = await showGooglePlacesAutocomplete( context: context,child: new Container( width: 80.0,height: 80.0,margin: new EdgeInsets.all(10.0),color: Colors.black),
您有任何想法如何使GestureDetector与TextFormField一起使用吗?也许与控制器,但我尝试没有任何成功
提前致谢
child: new InputDecorator( decoration: const InputDecoration( labelText: 'Localisation',icon: const Icon(Icons.room),child: widget.request.localisationLibelle != null ? new Text(widget.request.localisationLibelle) : new Text("-- Choisissez un lieu --"),
我没有使用TextFormField来捕捉GestureDetector位置的点击,而是使用InputDecorator小部件的简单子Text.
以上是大佬教程为你收集整理的flutter – 在TextFormField上捕捉点击事件全部内容,希望文章能够帮你解决flutter – 在TextFormField上捕捉点击事件所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。