Flutter. I'm trying to put a camera widget inside a small container
I am trying to put a full camera in a container that is 255 in height and full in width.
I've tried a lot of tweaking the code below, but I'm not sure how to apply the ratio.
in widget size Is there no room to fix it with the correct camera aspect ratio?
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:camera/camera.dart';
List<CameraDescription> cameras;
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
cameras = await availableCameras();
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),
);
}
}
from Recent Questions - Stack Overflow https://ift.tt/3icJBaB
https://ift.tt/eA8V8J
Comments
Post a Comment