'error in implementing search feature in Listview builder

I'm trying to implement search functionality in the list view builder But I don't have an idea to implement it.

this is model class

class Contacts {
  String? id;
  String? name;
  String? display_name;

  Contacts({this.id, this.name, this.display_name});

  factory Contacts.fromJson(Map<String?, dynamic> json) {
    return Contacts(
        id: json['id'], name: json['name'], display_name: json['display_name']);
  }
  Map toJson() => {'id': id, 'name': name, "display_name": display_name};
}

this is the future class

late Future<List<Contacts>> c;
void onInit() async {
    
    c = getContacts();

  }
Future<List<Contacts>> getContacts() async {
    print("<<<<<GETTING CONTACTS>>>>>>");
    // SERVER API URL

    Uri url = Uri.parse('http://localhost:8000/get-contacts');

    // Store all data with Param Name.
    var data = {'sender': id};

    //json encode
    String? body = json.encode(data);

    // Starting Web API Call.
    var response = await http.post(url,
        headers: <String, String>{
          'Content-Type': 'application/json; charset=UTF-8',
        },
        body: body);

    // If Web call Success than Hide the CircularProgressIndicator.
    if (response.statusCode == 200) {
      final datas = json.decode(response.body).cast<Map<String, dynamic>>();
      contacts = datas.map<Contacts>((json) {
        return Contacts.fromJson(json);
      }).toList();
      print(contacts);
      return contacts;
    } else {
      return contacts = [];
    }
  }

this is view class

FutureBuilder<List<Contacts>>(
                      future: controller.c,
                      builder: (context, snapshot) {
                        
                        if (!snapshot.hasData) {
                          return Center(
                            child: CircularProgressIndicator(),
                          );
                        } else {
                          return ListView.builder(
                            itemCount: snapshot.data?.length,
                            itemBuilder: (context, index) {
                              return Card(
                                child: CheckboxListTile(
                                  title: Text(
                                      snapshot.data![index].name ?? "name"),
                                  value: controller.isChecked[index],
                                  onChanged: (val) {
                                    setState(
                                      () {
                                        print(snapshot.data![index]);
                                        controller.selectContact(
                                            index, val, snapshot.data![index]);
                                      },
                                    );
                                  },
                                ),
                              );
                            },
                          );
                        }
                      }),

anyone, please help me to filter the records from the snapshot data. I successfully implemented it in listview but not in listviewBuildr



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source