4

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
Abdullah Hamadi
  • 161
  • 3
  • 10

2 Answers2

5

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

Adnan Alshami
  • 949
  • 1
  • 7
  • 22
1

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

  • (How to Use the Hydrated bloc Package Tested for 8.0.0 in dart Flutter Mobile Application, fork it on GitHub)[https://github.com/TrophyDevelopersUganda/testing_bloc/blob/Hydrated-State-mgt-mobile-app-flutter/lib/main.dart] – Trophy Developers Dec 28 '21 at 19:13