import 'package:flutter/widgets.dart';

enum _Action {
  increment,
  decrement,
}

class MyStore extends ValueNotifier<int> {
  MyStore() : super(0);

  void increment() => value++;

  void decrement() => value--;
}

class Bar {}

class Initial implements Bar {}

class Loading implements Bar {}

class Error implements Bar {
  Error(this.err);

  final Object err;
}

class Loaded implements Bar {
  Loaded(this.value);

  final int value;
}

class Foo extends ValueNotifier<Bar> {
  Foo() : super(Initial());

  Future<void> fetch() async {
    value = Loading();
    try {
      final result = await Future<int>.delayed(Duration(seconds: 1));
      value = Loaded(result);
    } catch (err) {
      value = Error(err);
    }
  }
}
