Home > Net >  How to retrieve the data of the value entered in the text field
How to retrieve the data of the value entered in the text field

Time:01-06

I want it to show on the screen as soon as I enter the location, how can I do it?

i have to use ctrl s when i try this way

  Future<void> getData() async{
   data = await client.getCurrentWeather(locatian.text.toString());
  }

  TextEditingController locatian = new TextEditingController();

        body: FutureBuilder(
          future: getData(),
          builder: (context, snapshot){
            if(snapshot.connectionState==ConnectionState.done){
              return Column(
                children: [
                  Padding(
                    padding: const EdgeInsets.all(9.0),
                    child: TextField(
                      controller: locatian,
                      decoration: InputDecoration(
                        border: OutlineInputBorder(),
                        hintText: "Sehir Giriniz",
                        prefixIcon: Icon(Icons.search),
                      ),
                    ),
                  ),
                  GuncelVeri(Icons.wb_sunny_rounded, "${data?.derece}", "${data?.sehir}"),
                  bilgiler("${data?.humidity}","${data?.feels_like}", "${data?.pressure}"),],
              );

CodePudding user response:

you better to call the api in onChange function to trigger text change and call API each time the text changed

CodePudding user response:

you should try the onChanged property of TextField:

Called when the user initiates a change to the TextField's value: when they have inserted or deleted text.

This callback doesn't run when the TextField's text is changed programmatically, via the TextField's controller. Typically it isn't necessary to be notified of such changes, since they're initiated by the app itself.

To be notified of all changes to the TextField's text, cursor, and selection, one can add a listener to its controller with TextEditingController.addListener.

  •  Tags:  
  • Related