Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hydrated_bloc: The parameter 'storageDirectory' is required

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
like image 956
Abdullah Hamadi Avatar asked Sep 21 '25 07:09

Abdullah Hamadi


2 Answers

Both getTemporaryDirectory and getApplicationDocumentsDirectory are part of the path_provider package, so, you have to import it in your main.dart file

like image 146
Adnan Alshami Avatar answered Sep 23 '25 06:09

Adnan Alshami


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

like image 36
Trophy Developers Avatar answered Sep 23 '25 07:09

Trophy Developers