Как исправить MissingPluginException (Реализация для метода getApplicationDocumentsDirectory не найдена в подключаемых модулях канала.flutter.io/path_provider)

Мне нужно использовать path_provider внутри ForegroundService пакета. Кстати, у Foreground Service есть Isolate, поэтому мне нужно использовать path_provider внутри Isolate. Однако, когда я использую его, у меня возникает следующее исключение:

MissingPluginException (Реализация для метода getApplicationDocumentsDirectory в плагинах канала не найдена. Flutter.io/path_provider)

Мой код:

void maybeStartFGS() async {
    ///if the app was killed+relaunched, this function will be executed again
    ///but if the foreground service stayed alive,
    ///this does not need to be re-done

    if (!(await ForegroundService.foregroundServiceIsStarted())) {
      await ForegroundService.setServiceIntervalSeconds(5);

      //necessity of editMode is dubious (see function comments)

      await ForegroundService.notification.startEditMode();
      await ForegroundService.notification
          .setTitle("Example Title: ${DateTime.now()}");
      await ForegroundService.notification
          .setText("Example Text: ${DateTime.now()}");

      await ForegroundService.notification.finishEditMode();

      await ForegroundService.startForegroundService(foregroundServiceFunction);
      await ForegroundService.getWakeLock();
    }

    ///this exists solely in the main app/isolate,
    ///so needs to be redone after every app kill+relaunch
    await ForegroundService.setupIsolateCommunication((data) {
      debugPrint("main received: $data");
     // _beacon.Brodcast();
      //_scanningBeacon.initScanBeacon();
    });
  }

  void foregroundServiceFunction() {

     debugPrint("The current time is: ${DateTime.now()}");
Future<List> readCounter() async {

    try {
      final file = await _localFile;
      print('file$file');
    // Read the file.
   List  reada = await  jsonDecode(file.readAsStringSync());
   print('reada$reada');
    return reada;
    } catch (e) {
print(e.toString());
    return null;
    }
    }
    ForegroundService.notification.setText("The time was: ${DateTime.now()}");

    if (!ForegroundService.isIsolateCommunicationSetup) {
      ForegroundService.setupIsolateCommunication((data) {
        debugPrint("bg isolate received: $data");

      });
    }
    ForegroundService.sendToPort("message from bg isolate");
  }

person mohmmed ali    schedule 27.06.2020    source источник


Ответы (2)


Снова запустите flutter clean и flutter run. Это должно решить проблему.

person idris Bello    schedule 07.02.2021

У меня также была такая же проблема с пакетом path_provider, похожая на то, с чем вы столкнулись прямо сейчас, я сделал следующие шаги, чтобы исправить это:

  1. Удалить / раскомментировать пакет path_provider в pubspec.yaml
  2. флаттер паб работает на терминале
  3. Неверный кеш и перезапустить студию Android
  4. Раскомментируйте или снова добавьте пакет path_provider в pubspec.yaml.
  5. снова запустить flutter pub на терминале.

Проблема исправлена.

person Akhmad Rizki Triandani    schedule 08.02.2021