flutter startimagestream in flutting在纸幅中不工作

mwg9r5ms  于 2023-01-21  发布在  Flutter
关注(0)|答案(1)|浏览(188)

我正在使用摄像机获取图像流。启动图像流时出现此错误

Uncaught (in promise) Error: Assertion failed: 
file:///home/rahul/snap/flutter/common/flutter/.pub- 
cache/hosted/pub.dartlang.org/camera-0.9.8+1/lib/src/camera_controller.dart:422:12
defaultTargetPlatform == TargetPlatform.android ||
    default

这是我代码

// ignore_for_file: unused_local_variable, avoid_print, unused_element, unused_import, 
   depend_on_referenced_packages, must_be_immutable, sized_box_for_whitespace
   import 'dart:async';

   import 'package:flutter/material.dart';
   import 'package:flutter/services.dart';
   import 'package:heart_rate_app/networking/firebase_api.dart';
   import 'package:heart_rate_app/networking/heart_rate_api.dart';
   import 'dart:io' as io;
   import 'package:path_provider/path_provider.dart';
   import 'package:camera/camera.dart';
   import 'package:cross_file_image/cross_file_image.dart';

   import '../utils/color_detector.dart';

   class HomePage extends StatefulWidget {
    HomePage({Key? key, required this.cameras}) : super(key: key);
   List<CameraDescription> cameras;

  @override
  State<HomePage> createState() => _HomePageState();
  }

    class _HomePageState extends State<HomePage> {
    List<CameraDescription> cameras = [];
      late CameraController controller;


 @override
void initState() {
super.initState();
controller = CameraController(widget.cameras[0], ResolutionPreset.high);
controller.initialize().then((value) {
  if (!mounted) {
    return;
  }
  setState(() {});
});
 }

 @override
 void dispose() {
   controller.dispose();
   super.dispose();
  }

  @override
  Widget build(BuildContext context) {
   if (!controller.value.isInitialized) {
     return Container();
   }
   return Scaffold(
    body: Column(
    mainAxisAlignment: MainAxisAlignment.center,
    crossAxisAlignment: CrossAxisAlignment.center,
    children: [
      Container(
        height: 100,
        width: 100,
        child: CameraPreview(controller,),
      ),
      SizedBox(height: 20,),
     
   
      ElevatedButton(
          onPressed: () async {
            controller.startImageStream((image) {

            });
        
          },
          child: const Text("capture")),
    
    ],
  ),
   );

 }

}

这是chrome桌面上的错误截图。我也试过在我的手机chrome(android)上得到同样的错误。
...............................................................
请提供一些解决方案,谢谢。

goqiplq2

goqiplq21#

只需将https://pub.dev/packages/camera_web .包添加到yout pubspec.yaml文件中。
它将自动添加Web支持。

相关问题