I updated hydrated_bloc from 6.1.0 to the latest 7.0.1 and I got a warning in:
HydratedBloc.storage = await HydratedStorage.build(); The parameter 'storageDirectory' is required.
When I changed to what the new documentation suggested
HydratedBloc.storage = await HydratedStorage.build(
storageDirectory: await getTemporaryDirectory(),); The function 'getTemporaryDirectory' isn't defined.
I also tried:
HydratedBloc.storage = await HydratedStorage.build(storageDirectory: await getApplicationDocumentsDirectory(),); The function 'getApplicationDocumentsDirectory' isn't defined
Both getTemporaryDirectory
and getApplicationDocumentsDirectory
are part of the path_provider package, so, you have to import it in your main.dart file
Yes you need path Provider Flutter package, you might also experience this error "StorageNotFound (Storage was accessed before it was initialized), or The setter 'storage' isn't defined for the type 'HydratedBloc' in Android Studio
instead define it as below: `
void main() async {
WidgetsFlutterBinding.ensureInitialized();
final storage = await HydratedStorage.build(
storageDirectory: await getApplicationDocumentsDirectory(),
);
HydratedBlocOverrides.runZoned(
() => runApp(MyApp(
appRouter: AppRouter(),
connectivity: Connectivity(),
)),
storage: storage,
);
}
` You can get the full code here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With