gpt4 book ai didi

dart - Flutter 相机插件无法导入/可用

转载 作者:行者123 更新时间:2023-12-03 02:53:29 27 4
gpt4 key购买 nike

开始实现 camera plugin 时出现以下错误在我的 flutter 应用程序上:

  [VERBOSE-2:dart_error.cc(16)] Unhandled exception:
MissingPluginException(No implementation found for method init on channel plugins.flutter.io/camera)
#0 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:153:7)
<asynchronous suspension>
#1 _channel (package:camera/camera.dart:7:5)
#2 _channel (package:camera/camera.dart:6:21)
#3 availableCameras (package:camera/camera.dart:42:41)
<asynchronous suspension>
#4 main (file:///Users/waynerumble/Desktop/scott_and_viki/lib/main.dart:10:19)
<asynchronous suspension>
#5 _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:279:19)
#6 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)
[VERBOSE-2:dart_error.cc(16)] Unhandled exception:
MissingPluginException(No implementation found for method list on channel plugins.flutter.io/camera)
#0 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:153:7)
<asynchronous suspension>
#1 availableCameras (package:camera/camera.dart:42:50)
<asynchronous suspension>
#2 main (file:///Users/waynerumble/Desktop/scott_and_viki/lib/main.dart:10:19)
<asynchronous suspension>
#3 _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:279:19)
#4 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)

直到我开始使用插件本身时才会发生错误,即如果我替换 Future<null> main() etcvoid main() => runApp(new App());该应用程序运行良好。我已经按照提供的链接中的安装说明进行操作,并尝试粘贴所有示例代码来代替我的代码,但仍然出现错误

我的 main.dart:
  import 'package:flutter/material.dart';
import 'Localisations.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'dart:async';
import 'package:camera/camera.dart';

List<CameraDescription> cameras;

Future<Null> main() async {
cameras = await availableCameras();
runApp(new App());
}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
var statusBarHeight = MediaQuery.of(context).padding.top;
var titleText = new Text(Localize.of(context).appTitle,
textAlign: TextAlign.center,
style: new TextStyle(fontFamily: 'CallingAngelsPersonalUse',
fontSize: 50.0,
color: Colors.black)
);
var backgroundImage = new BoxDecoration(
image: new DecorationImage(
image: new AssetImage('assets/background.png'),
fit: BoxFit.cover,
),
);

var mainContainer = new Container(
padding: EdgeInsets.only(top: statusBarHeight),
height: double.infinity,
width: double.infinity,
decoration: backgroundImage,
child: new Column(
children: <Widget>[
new Container(
margin: EdgeInsets.only(top: 10.0),
child: titleText
)
],
),

);

return new Scaffold(
body: mainContainer,
);
}
}

class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
onGenerateTitle: (BuildContext context) => Localize.of(context).appTitle,
localizationsDelegates: [
const LocalizeDelegate(),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: [
const Locale('en', '')
],
home: new MyApp(),
);
}
}

我的 pubspec.yml:
dependencies:
flutter:
sdk: flutter
camera: ^0.1.2
path_provider: ^0.4.0
flutter_localizations:
sdk: flutter

这是我的第一个真正的 Flutter 应用程序,因此我们将不胜感激。

谢谢

最佳答案

首先检查您的 app.build minSdkVersion。确保 minSdkVersion 为 21。

       minSdkVersion 21
这里的代码示例。
List<CameraDescription> cameras = [];
main() async{
WidgetsFlutterBinding.ensureInitialized();
try {
cameras = await availableCameras();

} on CameraException catch (e) {
logError(e.code, e.description);
}
runApp(MyApp());
}

关于dart - Flutter 相机插件无法导入/可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49888079/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com