颤动摄像头插件无法导入/可用

时间:2018-04-17 21:55:26

标签: dart flutter

开始在我的flutter app上实现camera plugin时出现以下错误:

> source <- 'J:\\tidy_examples\\dummyfiles\\small_random.txt'
> des <- 'N:\\JAL\\2018\\_temp\\small_random.txt'
> test_copy(source, des)
r file.copy: 6.49 sec elapsed
system call: 2.12 sec elapsed
> 
> source <- 'J:\\tidy_examples\\dummyfiles\\medium_random.txt'
> des <- 'N:\\JAL\\2018\\_temp\\medium_random.txt'
> test_copy(source, des)
r file.copy: 56.86 sec elapsed
system call: 4.65 sec elapsed
> 
> source <- 'J:\\tidy_examples\\dummyfiles\\large_random.txt'
> des <- 'N:\\JAL\\2018\\_temp\\large_random.txt'
> test_copy(source, des)
r file.copy: 562.94 sec elapsed
system call: 31.01 sec elapsed
> 

在我开始使用插件本身之前不会发生错误,即如果我用 [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() etc该应用运行正常。我已经按照提供的链接安装说明并尝试粘贴所有示例incode代替我但仍然得到错误

我的main.dart:

void main() => runApp(new App());

我的pubspec.yml:

  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(),
      );
    }
  }

这是我的第一个真正扑动的应用程序,所以任何帮助将不胜感激。

由于

1 个答案:

答案 0 :(得分:3)

首先检查您的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());
}