flutter - HydratedBloc expects a type HydratedStorageDirectory but getApplicationDocumentsDirectory returns a type of Directory

admin2025-04-17  4

I am new to Flutter and currently trying to learn Bloc and HydratedBloc. I am trying to initialize the storage using getApplicationDocumentDirectory() and use it for the storageDirectory parameter in HydratedStorage.build but I keep getting a type mismatch error. Any help or clarification would be greatly appreciated!

Here is what I have so far: HydratedBloc.storage = await HydratedStorage.build( storageDirectory: await getApplicationDocumentsDirectory(), );

I have tried going throught the documentation on hydrated_bloc on pub.dev, and it seems like this error should not be occuring. Here is a relevant snippet from those docs: final storage = await HydratedStorage.build( storageDirectory: await getApplicationDocumentsDirectory(), );

I am new to Flutter and currently trying to learn Bloc and HydratedBloc. I am trying to initialize the storage using getApplicationDocumentDirectory() and use it for the storageDirectory parameter in HydratedStorage.build but I keep getting a type mismatch error. Any help or clarification would be greatly appreciated!

Here is what I have so far: HydratedBloc.storage = await HydratedStorage.build( storageDirectory: await getApplicationDocumentsDirectory(), );

I have tried going throught the documentation on hydrated_bloc on pub.dev, and it seems like this error should not be occuring. Here is a relevant snippet from those docs: final storage = await HydratedStorage.build( storageDirectory: await getApplicationDocumentsDirectory(), );

Share Improve this question asked Jan 30 at 18:05 AlexAlex 32 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

That is probably some outdated documentation. The current way seems to be to surround the getApplicationDocumentsDirectory with a HydratedStorageDirectory constructor.

HydratedBloc.storage = await HydratedStorage.build(
  storageDirectory: HydratedStorageDirectory(
    (await getApplicationDocumentsDirectory()).path,
  ),
);
转载请注明原文地址:http://anycun.com/QandA/1744899752a89203.html