blink_shot 1.0.0+1
blink_shot: ^1.0.0+1 copied to clipboard
A Flutter package for blink detection and Blink Shot photo flow.
import 'package:blink_shot/blink_shot.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const ExampleApp());
}
class ExampleApp extends StatelessWidget {
const ExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Blink Shot Example',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
useMaterial3: true,
),
home: const ExampleHomePage(),
);
}
}
class ExampleHomePage extends StatefulWidget {
const ExampleHomePage({super.key});
@override
State<ExampleHomePage> createState() => _ExampleHomePageState();
}
class _ExampleHomePageState extends State<ExampleHomePage> {
late final BlinkShotController _controller;
String _status = 'Initializing...';
String? _imagePath;
late List<String> _capturedPaths;
@override
void initState() {
super.initState();
_capturedPaths = [];
_controller = BlinkShotController(
config: const BlinkShotConfig(),
onCapture: (file) {
debugPrint('[Example] Image captured: ${file.path}');
setState(() {
_status = 'Image captured: ${file.name}';
_imagePath = file.path;
_capturedPaths.add(file.path);
});
},
onError: (error) {
debugPrint('[Example] Controller error: $error');
setState(() {
_status = 'Error: $error';
});
},
onStateChanged: (state) {
debugPrint('[Example] Controller state changed: $state');
setState(() {
_status = switch (state) {
BlinkShotState.initializing => 'Initializing camera...',
BlinkShotState.ready => 'Ready to capture',
BlinkShotState.capturing => 'Capturing...',
BlinkShotState.paused => 'Paused',
BlinkShotState.error => 'Camera error',
BlinkShotState.disposed => 'Camera disposed',
};
});
},
);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Blink Shot'), elevation: 0),
body: DefaultTextStyle(
style: Theme.of(context).textTheme.bodyMedium!,
child: Column(
children: [
Expanded(
child: BlinkShotView(
controller: _controller,
instructionText: 'Position your face in the frame', // Optional custom instruction text
captureButtonLabel: 'Take Photo', // Optional Custom button label
),
),
Container(
color: Colors.black87,
width: double.infinity,
padding: const EdgeInsets.all(16),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Status: $_status',
style: const TextStyle(color: Colors.white),
),
const SizedBox(height: 8),
Text(
'Face Aligned: ${_controller.isFaceAligned}',
style: const TextStyle(color: Colors.white),
),
const SizedBox(height: 8),
Text(
'Captured: ${_capturedPaths.length}',
style: const TextStyle(color: Colors.white70),
),
if (_imagePath != null) ...[
const SizedBox(height: 8),
const Text(
'Last file:',
style: TextStyle(color: Colors.white70),
),
Text(
_imagePath!.split('/').last,
style: const TextStyle(
color: Colors.white70,
fontSize: 12,
),
overflow: TextOverflow.ellipsis,
),
],
],
),
),
),
],
),
),
);
}
}