回归.升级插件后,我的应用程序不再启动.

this my flutter spec:

Flutter is already up to date on channel stable

Flutter 3.0.2 • channel stable • 100

Framework • revision cd41fdd (10 days ago) • 2022-06-08 09:52:13 -0700

Engine • revision f15f824b57 Tools • Dart 2.17.3 • DevTools 2.12.2

之前一切正常,但我遇到了以下错误:

I/flutter ( 6677): `camera_android` threw an error: Binding has not yet been initialized.
I/flutter ( 6677): The "instance" getter on the ServicesBinding binding mixin is only available once that binding has been initialized.
I/flutter ( 6677): Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After calling that method, the "instance" getter will return the binding.
I/flutter ( 6677): In a test, one can call "TestWidgetsFlutterBinding.ensureInitialized()" as the first line in the test's "main()" method to initialize the binding.
I/flutter ( 6677): If ServicesBinding is a custom binding mixin, there must also be a custom binding class, like WidgetsFlutterBinding, but that mixes in the selected binding, and that is the class that must be constructed before using the "instance" getter.. The app may not function as expected until you remove this plugin from pubspec.yaml
E/flutter ( 6677): [ERROR:flutter/shell/common/shell.cc(93)] Dart Unhandled Exception: Binding has not yet been initialized.
E/flutter ( 6677): The "instance" getter on the ServicesBinding binding mixin is only available once that binding has been initialized.
E/flutter ( 6677): Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After calling that method, the "instance" getter will return the binding.
E/flutter ( 6677): In a test, one can call "TestWidgetsFlutterBinding.ensureInitialized()" as the first line in the test's "main()" method to initialize the binding.
E/flutter ( 6677): If ServicesBinding is a custom binding mixin, there must also be a custom binding class, like WidgetsFlutterBinding, but that mixes in the selected binding, and that is the class that must be constructed before using the "instance" getter., stack trace: #0      BindingBase.checkInstance.<anonymous closure> (package:flutter/src/foundation/binding.dart:281:9)
E/flutter ( 6677): #1      BindingBase.checkInstance (package:flutter/src/foundation/binding.dart:363:6)
E/flutter ( 6677): #2      ServicesBinding.instance (package:flutter/src/services/binding.dart:48:54)
E/flutter ( 6677): #3      MethodChannel.setMethodCallHandler (package:flutter/src/services/platform_channel.dart:387:51)
E/flutter ( 6677): #4      new AndroidCamera (package:camera_android/src/android_camera.dart:26:13)
E/flutter ( 6677): #5      AndroidCamera.registerWith (package:camera_android/src/android_camera.dart:32:31)
E/flutter ( 6677): #6      _PluginRegistrant.register (file:///Users/manish/Documents/REBORN/flutter/user-app/.dart_tool/flutter_build/dart_plugin_registrant.dart:47:23)
E/flutter ( 6677): 

推荐答案

是的,他们发布了0.9.8+1个坏版本.

https://github.com/flutter/flutter/issues/106236#issuecomment-1161100481

这是移动到每包平台通道的意外副作用.默认方法通道没有这个问题,因为静态类字段是在Dart中延迟计算的,所以默认方法通道类构造函数只有在实际使用相机时才运行,而新版本的构造函数是在registerWith()中显式触发的.

推荐

在他们修复构建之前,我建议:

https://github.com/flutter/flutter/issues/106236#issuecomment-1161149799

  1. 删除pubspec.lock
  2. Downgrade to 0.9.7+1 (versions 0.9.8 and 0.9.8+1 throw the error)
    https://pub.dev/packages/camera/versions
  3. 运行flutter pub get

不推荐使用

您还可以覆盖依赖项

https://github.com/flutter/flutter/issues/106236#issuecomment-1159447210

dependency_overrides:
  camera_android: 0.9.7+1
  camera_avfoundation: 0.9.7+1

但我不推荐这种方法,因为(a)构建已中断,这是一种可能无法解决所有问题的黑客行为,(b)这些额外的代码行会减慢构建速度并添加到存储库历史记录中,以及(c)您需要记住删除这些代码行.降级软件包版本更容易.

Flutter相关问答推荐

如何更新文本字段的基础上的选定下拉菜单?

壁炉有序在Flutter

使用ThemeProvider不在亮模式和暗模式之间切换

在保持标高=1的情况下更改AppBar立面 colored颜色 /遮罩

blocTest错误:没有从`when()`中调用方法存根

如何在抖动中将PNG图像转换为WebP

如果我使用搜索栏,如何在嵌套滚动视图中停止自动滚动?

Firebase WHERE过滤器在日期字段中不起作用

使索引[0]在ListViewBuilder中返回字符串1

将自定义容器附加到屏幕底部

Flutter Dismissible 不会在 startToEnd 滑动时被关闭

「Flutter」错误:没有名为'kind'的命名参数

在 Flutter 中更改喜欢按钮的 colored颜色

Flutter 判断 Uint8List 是否有效 Image

Container 的 Flutter 背景图片不会出现

setState 方法有时有效,有时无效

java.lang.IncompatibleClassChangeError:找到接口 com.google.android.gms.location.SettingsClient,

如何根据字符串值动态构建和显示小部件?

Flutter:制作自定义小部件的最佳做法是什么?

我已经删除了我的 .android 密钥库,但我没有使用它,如何生成一个新的?