Bloc: How to work with SearchDelegate?

Created on 10 Nov 2018  路  5Comments  路  Source: felangel/bloc

Hello,
I'm trying to implement bloc with SearchDelegate.

Do you have any example?

Thanks

question

Most helpful comment

@endigo I think you should be able to do something like this.

Let me know if that helps.

All 5 comments

Hi @endigo can you please provide more details like a code sample of what you鈥檇 like to be able to accomplish?

Thanks for a response,

I have 1 screen, call a showSearch method.

class ScreenOne extends StatefulWidget {
...
}

class _ScreenOneState extends State<ScreenOne> {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: RaisedButton(
        child: Text('Show search'),
        onPress: () async {
          City selected = await showSearch<City>(context, delegate: new CityDelegate());
          print(selected.name);
        }
      )
    );
  }
}

Here is SearchDelegate

class CitySearch extends SearchDelegate<City> {
  final CityBloc _bloc = new CityBloc();
... other codes
...
... other codes

@override
  Widget buildResults(BuildContext context) {
     print(query);
     // SearchDelegate has field 'query', changes in user input.
     // Here I want to use bloc for search/filtering from datasource.

    return StreamBuilder<UnmodifiableListView<City>>(
      stream: _bloc.cities,
      builder: (BuildContext context, AsyncSnapshot<UnmodifiableListView<City>> snapshot) {
        return ListView();
      },
  }
...
}

There is no onChange method on SearchDelegate.

@endigo I think you should be able to do something like this.

Let me know if that helps.

Thank for your time. It's works.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shawnchan2014 picture shawnchan2014  路  3Comments

nerder picture nerder  路  3Comments

Reidond picture Reidond  路  3Comments

zjjt picture zjjt  路  3Comments

timtraversy picture timtraversy  路  3Comments