未为类型“_MyAppState”定义方法“getApplicationDocumentsDirectory”

Nad*_*dou 7 methods dart flutter

所以我的代码的一部分是


 Future<void> _loadModel() async {
    final bytes =
        await rootBundle.load('assets/deepspeech-0.9.3-models.tflite');
    final directory = (await getApplicationDocumentsDirectory()).path;

Run Code Online (Sandbox Code Playgroud)

我不断收到错误:

The method 'getApplicationDocumentsDirectory' isn't defined for the type '_MyAppState'.
Try correcting the name to the name of an existing method, or defining a method named 'getApplicationDocumentsDirectory'
Run Code Online (Sandbox Code Playgroud)

我应该怎么办?请帮帮我!

小智 17

您必须通过在终端中运行来安装路径提供程序包。flutter pub add path_provider如果您已经安装了它。检查您是否将其导入到您的文件中。


小智 11

导入这个...

import 'package:path_provider/path_provider.dart';
Run Code Online (Sandbox Code Playgroud)