Skip to content

Refactor AsyncData/AsyncError with isLoading:true to AsyncLoading instead #2894

Description

@rrousselGit

During refresh, it was made so that instead of emitting an AsyncLoading, the provider would emit an AsyncData/AsyncError corresponding to the previous state; but with isLoading=true/isRefreshing=true.

This was due to an implementation detail of how AsyncValue.when/map work.
But this impacts features like whenData/asData negatively. From experience, this is confusing to folks.

We could fix that behaviour such that an AsyncLoading is always emitted, with either isRefreshing or isReloading set.

Considerations

We'd have to double check how this impacts pattern matches.

Currently folks can do:

switch ()
  AsyncData(:final value) =>,
  AsyncError(:final error) =>,
  _ =>,

which will show previous data during refreshes but not show previous data during reloads.
This wouldn't behave like this anymore with the new behavior, and would instead show data/error only once they completed.

To match this behavior, folks would have to do:

switch ()
  AsyncValue(:final value?, isReloading: false) =>,
  AsyncValue(:final error?, isReloading: false) =>,
  _ =>,

Omitting the isReloading: false would have the switch show data/error during reloads (ref.watch updates).

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions