River_pod: Proposal: Include a debounced search to the Marvel example

Created on 2 Jul 2020  路  14Comments  路  Source: rrousselGit/river_pod

Given that async operations are quite common, I think it would be helpful to add a simple search functionality to the Marvel example that would debounce the input query.
How do you approach such functionality, if possible, in a reusable way?

Sorry if this would fit better in the state_notifier or hooks package. I felt like asking because of the Marvel project 馃槃

Congratulations on all the packages @rrousselGit !

documentation

Most helpful comment

SmartSelect_20200705-140812

I opted for a separate list for the search bar

What do you think of it?
I like it as it demonstrate having two separate states in parallel - which is done by default with Riverpod's families

The main list is obtained with:

useProvider(characters(''));

And the filtered list with:

useProvider(characters(search));

All 14 comments

Good idea!
Any other things you'd like in it?

@rrousselGit Not really, debounce is something that came to my head because I use it all the time on my projects (although relying on rxdart).

The existing pagination example is very nice + the combination with freezed for the API responses.
I can't think of other common use cases at the moment.

How about a Retry on errors? As far as I can see the error would only be shown, without a way to get rid of it? Not sure how this fits into the pagination

Actually the pagination is outdated and can be simplified. Families weren't implemented at the time of writing.
I'll also include a "auto cancel HTTP requests if the request is no-longer needed by the UI" and some navigation.

Saving state to disk and recreate the state when come back later :)
I wish there was a sync way to do it :(

You could technically use File.writeSync

Do you want to though... Haha

Uhhhhhh :D

class Foo extends StateNotifier<FooState> {
   Foo(): super(FooState.fromJson(file.readAsStringSync()) ?? Foo())
}

I'm honestly considering making a wrapper around a DB, such that we'd have:

final provider = StreamProvider((ref) async* {
  final json = await ref.deserialize();
  yield Value.fromJson(json);
}, name: "ID", serialize: (value) => value.toJson());

off topic, but this sounds a bit like why I made https://github.com/hpoul/simple_json_persistence#usage-in-flutter-streambuilder which basically produces a json backed ValueStream.. only that you'd have call save to update the state, instead of calling the setter..

I updated the marvel example a bit.

I'm not done yet, but it's a pretty big simplification of how the pagination was done before

Looking good. Can't wait to see how you solve reloading the character page on error :)

Ah good idea too

So:

  • debounce on search (currently we have a search, just not denounced)
  • retry
  • pull to refresh
  • offline
  • cancel HTTP requests when no-longer-used
  • data normalization
  • deep-link to a character

That should keep me occupied for this weekend

SmartSelect_20200705-140812

I opted for a separate list for the search bar

What do you think of it?
I like it as it demonstrate having two separate states in parallel - which is done by default with Riverpod's families

The main list is obtained with:

useProvider(characters(''));

And the filtered list with:

useProvider(characters(search));

Closing for now. The current example does include a denounced search.

I will implement the remaining points in different examples.

Was this page helpful?
0 / 5 - 0 ratings