A Flutter app example to access camera features.
- Display live camera preview.
- Capture photos.
- Switch between front and back cameras.
- Control flash mode.
- Display the captured imaged.
To use this example, add flutter_camera as a dependency in your pubspec.yaml file.
Here's a simple example of how to use the FlutterCameraScreen widget:
import 'dart:async';
import 'package:camera/camera.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_camera/camera/flutter_camera_screen.dart';
List<CameraDescription> _cameras = <CameraDescription>[];
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
try {
_cameras = await availableCameras();
} on CameraException catch (e) {
if (kDebugMode) {
debugPrint('Error fetching cameras: ${e.code} - ${e.description}');
}
}
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(home: FlutterCameraScreen(cameras: _cameras));
}
}For more detailed implementation, please refer to the flutter_camera_screen.dart widget.