hydrated_bloc: The parameter 'storageDirectory' is required

Viewed 1006

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
2 Answers

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 StorageNotFound (Storage was accessed before it was initialized 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

Related