簡體   English   中英

如何檢索文本字段中輸入的值的數據

[英]How to retrieve the data of the value entered in the text field

我希望它在輸入位置后立即顯示在屏幕上,我該怎么做?

當我嘗試這種方式時,我必須使用 ctrl + s

  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}"),],
              );

您最好在 onChange function 中調用 api 以觸發文本更改並在每次文本更改時調用 API

你應該試試 TextField 的onChanged屬性:

當用戶開始更改 TextField 的值時調用:當他們插入或刪除文本時。

當通過 TextField 的 controller 以編程方式更改 TextField 的文本時,此回調不會運行。 通常不需要通知此類更改,因為它們是由應用程序本身啟動的。

要收到有關 TextField 文本 cursor 和選擇的所有更改的通知,可以使用 TextEditingController.addListener 將偵聽器添加到其 controller。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM