hydrated_bloc:需要参数'storageDirectory'
hydrated_bloc: The parameter 'storageDirectory' is required
我将 hydrated_bloc 从 6.1.0 更新到最新的 7.0.1,我在以下位置收到警告:
HydratedBloc.storage = await HydratedStorage.build(); The parameter 'storageDirectory' is required.
当我更改为新文档建议的内容时
HydratedBloc.storage = await HydratedStorage.build(
storageDirectory: await getTemporaryDirectory(),); The function 'getTemporaryDirectory' isn't defined.
我也试过:
HydratedBloc.storage = await HydratedStorage.build(storageDirectory: await getApplicationDocumentsDirectory(),); The function 'getApplicationDocumentsDirectory' isn't defined
getTemporaryDirectory
和 getApplicationDocumentsDirectory
都是 path_provider 包的一部分,因此,您必须将其导入 main.dart 文件
是的,您需要路径 Provider Flutter package,您可能还会遇到此错误“StorageNotFound(存储在初始化之前已被访问),或者未定义 setter 'storage' Android Studio 中的类型 'HydratedBloc'
而是将其定义如下:`
void main() async {
WidgetsFlutterBinding.ensureInitialized();
final storage = await HydratedStorage.build(
storageDirectory: await getApplicationDocumentsDirectory(),
);
HydratedBlocOverrides.runZoned(
() => runApp(MyApp(
appRouter: AppRouter(),
connectivity: Connectivity(),
)),
storage: storage,
);
}
`
你可以获得the full code here
我将 hydrated_bloc 从 6.1.0 更新到最新的 7.0.1,我在以下位置收到警告:
HydratedBloc.storage = await HydratedStorage.build(); The parameter 'storageDirectory' is required.
当我更改为新文档建议的内容时
HydratedBloc.storage = await HydratedStorage.build(
storageDirectory: await getTemporaryDirectory(),); The function 'getTemporaryDirectory' isn't defined.
我也试过:
HydratedBloc.storage = await HydratedStorage.build(storageDirectory: await getApplicationDocumentsDirectory(),); The function 'getApplicationDocumentsDirectory' isn't defined
getTemporaryDirectory
和 getApplicationDocumentsDirectory
都是 path_provider 包的一部分,因此,您必须将其导入 main.dart 文件
是的,您需要路径 Provider Flutter package,您可能还会遇到此错误“StorageNotFound(存储在初始化之前已被访问),或者未定义 setter 'storage' Android Studio 中的类型 'HydratedBloc'
void main() async {
WidgetsFlutterBinding.ensureInitialized();
final storage = await HydratedStorage.build(
storageDirectory: await getApplicationDocumentsDirectory(),
);
HydratedBlocOverrides.runZoned(
() => runApp(MyApp(
appRouter: AppRouter(),
connectivity: Connectivity(),
)),
storage: storage,
);
}
` 你可以获得the full code here