Is there a way in flutter with camera 0.8.1 to stream from my camera to process the frames and keep the flash on while streaming? Working on windows and running on android
The example with camera 0.8.1 do not really give me a idea how to set the flashmode state. But I am still a novice so missing it most probably. Thank you. Get this error ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ The following NoSuchMethodError was thrown attaching to the render tree: The method 'setFlashMode' was called on null. Receiver: null Tried calling: setFlashMode(Instance of 'FlashMode')
When the exception was thrown, this was the stack: #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5) #1 _CameraAppState.initState (package:cameratest/main.dart:26:13) #2 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4632:57) #3 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4469:5) #4 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3541:14) #5 Element.updateChild (package:flutter/src/widgets/framework.dart:3306:18) #6 RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1182:16) #7 RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:1153:5) #8 RenderObjectToWidgetAdapter.attachToRenderTree. (package:flutter/src/widgets/binding.dart:1095:18) #9 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2647:19) #10 RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:1094:13) #11 WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:934:7) #12 WidgetsBinding.scheduleAttachRootWidget. (package:flutter/src/widgets/binding.dart:915:7) (elided 11 frames from class _RawReceivePortImpl, class _Timer, dart:async, and dart:async-patch) The code I have is for a preview at this time and want the flash to start when the app start.
import 'dart:async';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:camera/camera.dart';
List<CameraDescription> cameras;
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
cameras = await availableCameras();
_cameraController.setFlashMode(FlashMode.always);
runApp(CameraApp());
}
class CameraApp extends StatefulWidget {
@override
_CameraAppState createState() => _CameraAppState();
}
class _CameraAppState extends State<CameraApp> {
CameraController controller;
@override
void initState() {
super.initState();
controller = CameraController(cameras[0], ResolutionPreset.max);
controller.initialize().then((_) {
if (!mounted) {
return;
}
setState(() {
});
});
}
@override
void dispose() {
controller?.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
if (!controller.value.isInitialized) {
return Container();
}
return MaterialApp(
home: CameraPreview(controller),
);
}
}
you can set flashmode using the camera controller use it like this
and assign the controller to the camera preview