首页 > 解决方案 > 使用 GetIt 和 Injectable 注册路径提供程序时出现问题

问题描述

我正在尝试将 path_provider 注册为依赖项,但它现在可以正常工作。

  @preResolve
  Future<Directory> get appDirectory => getExternalStorageDirectory();

但错误说A value of type 'Future<Directory?>' can't be returned from the function 'appDirectory' because it has a return type of 'Future<Directory>'

所以我这样改了

  @preResolve
  Future<Directory?> get appDirectory => getExternalStorageDirectory();

在此之后,我得到一个运行时错误

Error: Type argument 'Directory?' doesn't conform to the bound 'Object' of the type variable 'T' on 'GetItHelper.lazySingletonAsync'.

我该如何解决这个问题?

标签: flutterdartdependency-injectionflutter-dependenciesinjectable

解决方案


推荐阅读