💧 On Device Caching
Blocsync uses the excellent hydrated_bloc package to cache your bloc states on device.
SyncedBloc and LiveBloc both use HydratedMixin to cache your bloc states on device.
This means that bloc data is loaded from the on-device storage first, and then fetched from the server.
Set Up
Section titled “Set Up”import 'package:blocsync/blocsync.dart';import 'package:path_provider/path_provider.dart';
BlocSyncConfig.storage = await HydratedStorage.build( storageDirectory: kIsWeb ? HydratedStorageDirectory.web : HydratedStorageDirectory((await getTemporaryDirectory()).path), );Opting Out
Section titled “Opting Out”If you don’t want to use on-device caching, instead of extending SyncedBloc or LiveBloc, extend Bloc directly and use the paired SyncedMixin or LiveMixin instead.
SyncedMixin
Section titled “SyncedMixin”import 'package:blocsync/blocsync.dart';
class MyBloc extends Bloc<MyEvent, MyState> with SyncedMixin<MyState> { MyBloc() : super(MyState.initial()) { startSyncing(); }}LiveMixin
Section titled “LiveMixin”import 'package:blocsync/blocsync.dart';
class MyBloc extends Bloc<MyEvent, MyState> with LiveMixin<MyEvent, MyState> { MyBloc() : super(MyState.initial()) { startListening(); }}