我遇到以下问题,希望有人可以帮助我。我尝试使用以下代码将相机包含在我的 flutter 应用程序中:
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:camera/camera.dart';
class Route02 extends StatefulWidget {
@override
CameraState createState() => CameraState();
}
class CameraState extends State<Route02> {
late List<CameraDescription> cameras;
late CameraController _controller;
bool isReady = false;
@override
void initState() {
super.initState();
setupCameras();
}
Future<void> setupCameras() async {
try {
cameras = await availableCameras();
_controller = new CameraController(cameras[0], ResolutionPreset.ultraHigh);
await _controller.initialize();
} on CameraException catch () {
setState(() {
isReady = false;
});
}
setState(() {
isReady = true;
});
}
Widget …Run Code Online (Sandbox Code Playgroud)