face_scanning_id 0.0.2+8
face_scanning_id: ^0.0.2+8 copied to clipboard
A Flutter package providing customizable face scanning UI widgets with camera integration and visual feedback.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:camera/camera.dart';
import 'package:face_scanning_id/face_scanning_id.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Allow all orientations for the app
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
final cameras = await availableCameras();
runApp(MyApp(cameras: cameras));
}
class MyApp extends StatelessWidget {
final List<CameraDescription> cameras;
const MyApp({super.key, required this.cameras});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Face Scanning ID Example',
theme: ThemeData(primarySwatch: Colors.blue, useMaterial3: true),
home: FaceScanScreen(cameras: cameras),
);
}
}
class FaceScanScreen extends StatefulWidget {
final List<CameraDescription> cameras;
const FaceScanScreen({super.key, required this.cameras});
@override
State<FaceScanScreen> createState() => _FaceScanScreenState();
}
class _FaceScanScreenState extends State<FaceScanScreen> {
CameraController? _cameraController;
bool _isScanning = false;
double _progress = 0.0;
String _message = 'Position your face in the circle';
@override
void initState() {
super.initState();
_initializeCamera();
}
Future<void> _initializeCamera() async {
if (widget.cameras.isEmpty) {
setState(() {
_message = 'No camera available';
});
return;
}
// Use front camera if available
final frontCamera = widget.cameras.firstWhere(
(camera) => camera.lensDirection == CameraLensDirection.front,
orElse: () => widget.cameras.first,
);
_cameraController = CameraController(
frontCamera,
ResolutionPreset.high,
enableAudio: false,
);
try {
await _cameraController!.initialize();
if (mounted) {
setState(() {});
}
} catch (e) {
setState(() {
_message = 'Camera initialization failed: $e';
});
}
}
void _startScanning() {
setState(() {
_isScanning = true;
_message = 'Scanning...';
});
// Simulate scanning progress
Future.delayed(const Duration(milliseconds: 100), _updateProgress);
}
void _updateProgress() {
if (!_isScanning || !mounted) return;
setState(() {
_progress += 0.05;
if (_progress >= 1.0) {
_progress = 1.0;
_isScanning = false;
_message = 'Scan complete!';
} else {
Future.delayed(const Duration(milliseconds: 100), _updateProgress);
}
});
}
@override
void dispose() {
_cameraController?.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Face Scanning ID Example'),
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
),
body: ScanFaceWidget(
diameter: 300,
ringSize: 20,
cameraController: _cameraController,
isScanning: _isScanning,
cameraInitialized: _cameraController?.value.isInitialized ?? false,
previewMirror: true,
progress: _progress,
message: _message,
borderColor: Colors.blue,
progressColor: Colors.green,
backgroundColor: Colors.black,
textColor: Colors.white,
buttonColor: Colors.blue,
buttonTextColor: Colors.white,
strokeWidth: 8.0,
onStartScanning: _startScanning,
onUpdateOverlay: (circleRect, previewSize) {
// Handle overlay updates for face detection
// You can integrate face detection logic here
},
),
);
}
}