felixmccuaig / flutter-autocomplete-textfield

An autocomplete Textfield for flutter
MIT License
181 stars 131 forks source link

Onblur Event #44

Closed onlinecheckwriter-zz closed 5 years ago

onlinecheckwriter-zz commented 5 years ago

Hello, Is it possible to reload the list from remote, When people finish writing?

For instance, you want to search starting with ab when you will finishing typing ab it should go to the server bring data and reload the listing.

loading? CircularProgressIndicator():searchTextField = AutoCompleteTextField( key: key, clearOnSubmit: false, suggestions: users, style: TextStyle(color: Colors.black, fontSize: 16.0), decoration: InputDecoration( contentPadding: EdgeInsets.fromLTRB(10.0, 30.0, 10.0, 20.0), hintText: "Search Name", suffixIcon: new Icon(Icons.search) , hintStyle: TextStyle(color: Colors.black), ), itemFilter: (item, query) {

                return item.payee_name
                    .toLowerCase()
                    .startsWith(query.toLowerCase());
              },
              itemSorter: (a, b) {
                return a.payee_name.compareTo(b.payee_name);
              },
              itemSubmitted: (item) {
                setState(() {
                  searchTextField.textField.controller.text = item.payee_name.toString();
                  _payee_id = item.id.toString();

                });
              },

              textChanged: (item) {

                String keyword= searchTextField.textField.controller.text;

               setState(() {

                  **getUsers(keyword);**

               });

void getUsers(String keyword) async { try {

  SharedPreferences prefs = await SharedPreferences.getInstance();
  final String payee_url  = PAYEE_GET_SUGGESTION_URL+prefs.get('_token')+"&keyword="+keyword;

  final response =
  await http.get(payee_url);
  if (response.statusCode == 200) {
    users = loadUsers(response.body);
    print('Users: ${users.length}');
    setState(() {
      loading = false;
    });
  } else {
    print("Error getting users.");
  }
} catch (e) {
  print("Error getting users.");
}

}

felixmccuaig commented 5 years ago

Yes, this is possible. Try calling your http request or whatever you have, and assigning a callback for it, when it calls back, set the data and setState.

felixmccuaig commented 5 years ago

I don't know what onBlur event is though or what you mean by that.