The method 'getApplicationDocumentsDirectory' isn't defined for the type '_MyAppState'

Viewed 2728

so a part of my code is


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

And i keep getting the error:

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'

What should i do? help me please!

2 Answers

You have to install path provider package by running flutter pub add path_provider in your terminal. If you already installed it. check whether you are importing it to your file.

Import this...

import 'package:path_provider/path_provider.dart';
Related