skip to Main Content

I’m using camera to get image stream in flutter.
I’m getting this error while start stream

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

here is my code

// 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")),
    
    ],
  ),
   );


 }


}

here is the error screenshot from the chrome desktop. and I also tried on my phone chrome (android) getting the same error.

………………………………………………………

please provide some solution for this. thanks in advance.

enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    camera_web plugin is under development.

    Missing implementation of camera_web
    The web implementation of the camera is missing the following features:

    1. Exposure mode, point and offset
    2. Focus mode and point
    3. Sensor orientation
    4. Image format group
    5. Streaming of frames

  2. Just add the https://pub.dev/packages/camera_web. package in yout pubspec.yaml file.

    It will automatically add the web support.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search