remote_state 0.15.0 copy "remote_state: ^0.15.0" to clipboard
remote_state: ^0.15.0 copied to clipboard

outdated

A new Flutter package project.

remote_state #

Slaying a UI Antipattern with Angular. #

Library inspired by a blog post by Kris Jenkins about How Elm slays a UI antipattern.

What problem does this package solve? #

You are making an API request, and you want to display or do different things based on the status of the request.

Why RemoteState, not RemoteData? #

I gained secondary inspiration from a talk by Jed Watson, A Treatise on State. As much as possible, I try to categorize state correctly in my applications.

The RemoteState approach #

Instead of using a complex object we use a single data type to express all possible request states. This approach makes it impossible to create invalid states.

Usage #

Here is an example that uses StateNotifier.


class Counter extends StateNotifier<int> {
  Counter(): super(RemoteState.initial())

  void increment() {
    try {
      state = RemoteState.loading();
    
      var count = await api.increment();
    
      state = RemoteState.success(count);
    } catch (e) {
      state = RemoteState.error(e.message);
    }
  }
}