2017-12-21 11 views
0

TextFormField에서 tap 이벤트를 흔들린 양식으로 잡으려고합니다.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, 
       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', 
      ), 
     ), 
     ), 

을 그것이 단순한 컨테이너에 의해 거기에 클릭이 때

나는 아이로 TextFormField으로 그렇게 할 수있는 GestureDetector를 사용하지만 아무것도 발사되지 않습니다 작업 :

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 Container(
      width: 80.0, 
      height: 80.0, 
      margin: new EdgeInsets.all(10.0), 
      color: Colors.black), 
     ), 

GestureDetector를 텍스트와 함께 사용하는 방법에 대한 아이디어가 있습니까? FormField? 내가 어떤 성공하지 않고 사전에 감사를 시도 어쩌면하지만 컨트롤러와

답변

2

나는 (플러터 갤러리에서)를 InputDecorator를 사용하여 솔루션을 발견 :

  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 위젯의 텍스트입니다.