flutter – 在TextFormField上捕捉点击事件

flutter – 在TextFormField上捕捉点击事件,第1张

概述我试图将TextFormField上的tap事件捕获到flutter Form中. 我使用GestureDetector将TextFormField作为子元素执行,但点击它时没有任何东西触发: @override Widget build(BuildContext context) { return new Scaffold( key: _scaffoldKey, 我试图将TextFormFIEld上的tap事件捕获到Flutter Form中.

我使用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一起使用吗?也许与控制器,但我尝试没有任何成功
提前致谢

解决方法 我通过使用inputDecorator(来自Flutter gallery)找到了一个解决方案:

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上捕捉点击事件所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1001855.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存