camerawesome 1.0.0-rc1+4 camerawesome: ^1.0.0-rc1+4 copied to clipboard
Easiest Flutter camera Plugin supporting capturing images, streaming images, video recording, switch sensors, autofocus, flash... on Android and iOS
import 'dart:io';
import 'package:better_open_file/better_open_file.dart';
import 'package:camerawesome/camerawesome_plugin.dart';
import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';
void main() {
runApp(const CameraAwesomeApp());
}
class CameraAwesomeApp extends StatelessWidget {
const CameraAwesomeApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: 'CamerAwesome App',
home: CameraPage(),
);
}
}
class CameraPage extends StatelessWidget {
const CameraPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: CameraAwesomeBuilder.awesome(
saveConfig: SaveConfig.photoAndVideo(
imagePathBuilder: () => _path(CaptureMode.photo),
videoPathBuilder: () => _path(CaptureMode.video),
initialCaptureMode: CaptureMode.photo,
),
onMediaTap: (mediaCapture) {
OpenFile.open(mediaCapture.filePath);
},
),
);
}
Future<String> _path(CaptureMode captureMode) async {
final Directory extDir = await getTemporaryDirectory();
final testDir =
await Directory('${extDir.path}/test').create(recursive: true);
final String fileExtension =
captureMode == CaptureMode.photo ? 'jpg' : 'mp4';
final String filePath =
'${testDir.path}/${DateTime.now().millisecondsSinceEpoch}.$fileExtension';
return filePath;
}
}