为啥相机不颤抖打开?

Posted

技术标签:

【中文标题】为啥相机不颤抖打开?【英文标题】:Why doesn't a camera open with flutter?为什么相机不颤抖打开? 【发布时间】:2021-03-28 23:10:16 【问题描述】:

我正在尝试使用颤振打开相机,这就是我得到的:

E/flutter (26189): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] 未处理的异常:MissingPluginException(在通道 plugins.flutter.io/camera 上找不到方法 availableCameras 的实现)

E/flutter (26189): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:157:7)

E/flutter (26189):

E/flutter (26189): #1 availableCameras (package:camera/camera.dart:56:9)

E/flutter (26189):

E/flutter (26189): #2 main (package:flutter_realtime_detection/main.dart:11:15)

E/flutter (26189):

这是flutter不接受的行:

Future<Null> main() async 
   WidgetsFlutterBinding.ensureInitialized();
   try 
      cameras = await availableCameras();
    on CameraException catch (e) 
      print('Error: $e.code\nError Message: $e.message');
   
   runApp(new MyApp());

我尝试过flutter clean、hot reloads但没有任何帮助(

这里是颤振医生-v

[✓] Flutter (Channel master, 1.24.0-8.0.pre.342, on macOS 11.1 20C69 darwin-x64, locale en-GB)
    • Flutter version 1.24.0-8.0.pre.342 at /Users/fimarubin/Developer/flutter \
    • Framework revision 226532b157 (4 weeks ago), 2020-11-21 12:08:04 +0100\
    • Engine revision 23a8e027db\
    • Dart version 2.12.0 (build 2.12.0-62.0.dev)

[✓] android toolchain - develop for Android devices (Android SDK version 30.0.2)\
    • Android SDK at /Users/fimarubin/Library/Android/sdk\
    • Platform android-30, build-tools 30.0.2\
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java\
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)\
    • All Android licenses accepted.

[✓] Xcode - develop for ios and macOS (Xcode 12.3)\
    • Xcode at /Applications/Xcode.app/Contents/Developer\
    • Xcode 12.3, Build version 12C33\
    • CocoaPods version 1.10.0

[✓] Android Studio (version 4.1)\
    • Android Studio at /Applications/Android Studio.app/Contents\
    • Flutter plugin can be installed from:\
      ???? https://plugins.jetbrains.com/plugin/9212-flutter\
    • Dart plugin can be installed from:\
      ???? https://plugins.jetbrains.com/plugin/6351-dart\
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)

[✓] Connected device (1 available)\
    • SM G9750 (mobile) • R28M31Y893Y • android-arm64 • Android 10 (API 29)

• No issues found!

【问题讨论】:

【参考方案1】:

请确保设置了以下依赖项:

相机:

path_provider:

路径:

dependencies:
  flutter:
    sdk: flutter
  camera:
  path_provider:
  path:

确保插件服务已初始化,以便可以调用 `availableCameras()

WidgetsFlutterBinding.ensureInitialized();

final cameras = await availableCameras();

【讨论】:

我编辑了一个帖子,所以你可以看到我的主要功能。我已经这样做了( 我明白了。我也稍微修改了我的答案。您是否设置了所有必需的依赖项? 是的,谢谢,我重新检查了我的 pubspec.yaml,结果发现我的相机依赖项有误(谢谢! 不客气。请将此标记为已回答,以便我们关闭它。

以上是关于为啥相机不颤抖打开?的主要内容,如果未能解决你的问题,请参考以下文章

为啥不可以微信扫码登录了

[当我在颤抖中单击TextField时,我的键盘打开和关闭

用ps打开raw文件为啥会被压缩

为啥我一打开vray渲染器就渲染出来一片黑

ngCordova Camera 不打开相机但打开相册

为啥我的相机胶卷模式是空的?