I want to show filter list in a container but it is opening as a new screen in flutter

Viewed 38

This code is working, but I am not getting the output I want. I want to show this screen in a container but it's not working. It's not opening in a container but instead directly opening as a different page.

I am using the flutter filter_list: ^1.0.2 plugin in this code.

I want to show this search bar with a list in a container on the same page.

List<SelectProjectData?> _selectProjectData = [];

openFilterDelegate() async {
    await FilterListDelegate.show<SelectProjectData?>(
      context: context,
      list:  _selectProjectData,
      selectedListData: _selectedProjectData,
      onItemSearch: (user, query) {
        return user!.projectName!.toLowerCase().contains(query.toLowerCase());
      },
      tileLabel: (user) => user!.projectName,
      emptySearchChild: const Center(child: Text('Data not found')),
      // enableOnlySingleSelection: true,
      searchFieldHint: 'Search Here..',
      onApplyButtonClick: (list) {
        setState(() {
          _selectedProjectData = list!;
        });
      },
    );
  }

Try to call this in the column:- here you can find the code

Container(
      margin: EdgeInsets.all(10),
      padding: EdgeInsets.all(20),
      color: AppColor.WHITE,

      child:
     
      Column(
        children: [
          openFilterDelegate(),
     
        ],
      ),
    );

The final result is this:-

enter image description here

1 Answers

Based on https://pub.dev/packages/filter_list, you want to use the FilterWidget instead of the FilterDelegate. FilterDelegate opens a new window every time. FilterWidget is a widget that you can put inside a container just like any other widget.

Container(
      margin: EdgeInsets.all(10),
      padding: EdgeInsets.all(20),
      color: AppColor.WHITE,

      child:
     
      Column(
        children: [
          FilterWidget(
            <set up widget here>
          ),
        ],
      ),
);

Related