You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
735 B
Dart
47 lines
735 B
Dart
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);
|
|
}
|
|
}
|
|
}
|