persisted_bloc_stream 6.0.2 copy "persisted_bloc_stream: ^6.0.2" to clipboard
persisted_bloc_stream: ^6.0.2 copied to clipboard

Adds persistence to the `bloc_stream` package.

persisted_bloc_stream #

PersistedBlocStream is an extension of BlocStream, that adds persistence for offline caching etc.

Usage #

class CounterBlocActions {
  static Future<void> increment(int i, _, StreamController<int> c) async {
    yield i + 1;
    c.add(i + 1);
  }

  static Future<void> decrement(int i, _, StreamController<int> c) async {
    c.add(i - 1);
  }
}

class CounterBloc extends PersistedBlocStream<int> {
  CounterBloc() : super(0);

  @override
  int fromJson(json) => json;

  @override
  dynamic toJson(int value) => value;
}

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  PersistedBlocStream.storage = await HiveStorage.build();
  runApp(MyApp());
}