【问题标题】:Unhandled Exception: MissingPluginException(No implementation found for method X on channel plugins.flutter.io/Y)未处理的异常:MissingPluginException(在通道 plugins.flutter.io/Y 上找不到方法 X 的实现)
【发布时间】:2021-12-29 17:25:05
【问题描述】:

我已按照here 的步骤将我的颤振项目迁移到空安全。

从那时起,我时不时地在以下多个软件包中遇到此错误。

Unhandled Exception: MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences)

上面是shared_preferences,但是path_providerfirebase_analytics会抛出类似的错误。

这是我的pubspec.yaml

name: news_app
description: A news app

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.10+22

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  curved_navigation_bar: ^1.0.1
  http: ^0.13.4
  webview_flutter: ^2.8.0
  firebase_core: ^1.10.6
  firebase_auth: ^3.3.4
  flutter_cache_manager: ^3.3.0
  flutter_widget_from_html_core: ^0.8.4
  flutter_widget_from_html: ^0.8.0
  flutter_html: ^2.1.5
  page_view_indicators: ^2.0.0
  splashscreen: ^1.3.5
  intl: ^0.17.0
  jiffy: ^5.0.0
  dio: ^4.0.4
  dio_http_cache: ^0.3.0
  shared_preferences: ^2.0.6
  connectivity: ^3.0.6
  share: ^2.0.4
  sqflite: ^2.0.1
  path_provider: ^2.0.2
  timeago: ^3.1.0
  auto_size_text: ^3.0.0
  flutter_tts: ^3.3.2
  firebase_messaging: ^11.2.4
  firebase_analytics: ^9.0.4
  flutter_local_notifications: ^9.1.5
  chewie: ^1.2.2
  flutter_svg: ^0.22.0
  provider: ^5.0.0
  webview_flutter_plus: ^0.2.3+1
  firebase_admob: ^0.11.2
  scroll_app_bar: ^2.0.0
  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.4

dev_dependencies:
  flutter_test:
    sdk: flutter

  flutter_launcher_icons: ^0.9.2

flutter_icons:
  image_path: "assets/logo.jpg"
  android: true
  ios: true

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:
  fonts:
    - family: sourcePro
      fonts:
        - asset: assets/SourceSansPro-Light.ttf
    - family: serifPro
      fonts:
        - asset: assets/SourceSerifPro-Light.otf
    - family: metaSerifPro
      fonts:
        - asset: assets/FFMetaSerifPro-Light.ttf
  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true
  assets:
    - assets/logo.jpeg
    - assets/tbs_logo_transparent.png
    - assets/logo.png
    - assets/logo.jpg
  # To add assets to your application, add an assets section, like this:
  # assets:
  #  - images/a_dot_burr.jpeg
  #  - images/a_dot_ham.jpeg

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/assets-and-images/#resolution-aware.

  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/assets-and-images/#from-packages

  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages

这是flutter doctor的结果

[✓] Flutter (Channel stable, 2.5.3, on Ubuntu 16.04.7 LTS 4.15.0-142-generic, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] VS Code (version 1.63.2)
[✓] Connected device (3 available)

我尝试了以下措施,这些措施是从其他帖子和 github 问题中找到的。

  1. 我尝试切换到不同的flutter 频道。
  2. 还尝试更改上述软件包的版本。
  3. 尝试使用flutter clean 删除缓存。
  4. 我卸载了应用,重新安装了,还是一样。
  5. 重新安装所有包。
  6. 使缓存失效后重新启动 Android Studio。

这些都不起作用。在迁移到 null 安全性之前,一切正常。

【问题讨论】:

    标签: android ios firebase flutter mobile


    【解决方案1】:

    我可以建议您另一种方式。不要将现有项目迁移到空安全,而是创建新项目(具有空安全)并从旧项目复制 lib 文件夹。然后将您从旧的pubspec.yaml 文件安装到新的pubspec.yaml 文件中添加软件包(确保您拥有最新版本。)。 (以及资产和字体,如果有的话)。如果您添加的软件包需要针对 iOS 和 Android 平台的额外集成,请执行此操作。我以这种我正在更新的方式停留在旧版本的 lutter(即非空安全)项目中。

    【讨论】:

    • 谢谢你的建议,我没想到。但不幸的是,即使在新项目中,同样的包也很麻烦,很奇怪。 :-|
    猜你喜欢
    • 2021-07-10
    • 2020-05-29
    • 1970-01-01
    • 2022-01-25
    • 2021-12-31
    • 2018-11-14
    • 2021-09-28
    • 1970-01-01
    • 2020-10-22
    相关资源
    最近更新 更多