gascom/lib/screens/national_id_camera_screen.dart
Abdullah Salah 216efb8a83 first commit
2024-12-25 11:09:55 +03:00

120 lines
3.6 KiB
Dart

import 'package:auto_size_text/auto_size_text.dart';
import 'package:camerawesome/camerawesome_plugin.dart';
import 'package:flutter/material.dart';
import 'package:gascom/constants/app_theme.dart';
import 'package:gascom/widgets/custom_app_bar.dart';
class NationalIdCameraScreen extends StatefulWidget {
const NationalIdCameraScreen({
super.key,
required this.title,
required this.subtitle,
required this.description,
required this.onScanComplete,
});
final String title;
final String subtitle;
final String description;
final void Function() onScanComplete;
@override
State<NationalIdCameraScreen> createState() => _NationalIdCameraScreenState();
}
class _NationalIdCameraScreenState extends State<NationalIdCameraScreen> {
String? error;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: const CustomAppBar(),
body: SafeArea(
child: CameraAwesomeBuilder.custom(
sensorConfig: SensorConfig.single(
aspectRatio: CameraAspectRatios.ratio_16_9,
flashMode: FlashMode.none,
sensor: Sensor.position(SensorPosition.back),
zoom: 0.0,
),
saveConfig: SaveConfig.photo(
),
builder: (state, previewSize) {
return Stack(
children: [
Center(
child: ClipPath(
clipper: HoleClipper(),
child: Container(
color: AppTheme.primaryColor,
),
),
),
Positioned(
top: 30,
left: 20,
right: 20,
child: AutoSizeText(
widget.title,
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
fontWeight: FontWeight.w500,
),
textAlign: TextAlign.center,
maxLines: 2,
)
),
Positioned(
top: 100,
left: 20,
right: 20,
child: AutoSizeText(
widget.subtitle,
style: Theme.of(context).textTheme.bodySmall,
textAlign: TextAlign.center,
maxLines: 1,
)
),
Positioned(
bottom: 200,
left: 20,
right: 20,
child: AutoSizeText(
error ?? widget.description,
style: Theme.of(context).textTheme.bodySmall,
textAlign: TextAlign.center,
maxLines: 2,
)
),
],
);
}
),
),
);
}
}
class HoleClipper extends CustomClipper<Path> {
@override
Path getClip(Size size) {
final path = Path()
..addRect(Rect.fromLTWH(0, 0, size.width, size.height))
..addRRect(RRect.fromRectAndRadius(
Rect.fromCenter(
center: Offset(size.width / 2, size.height * 0.38),
width: size.width - (size.width * 0.1), // Adjust the width of the square
height: size.height - (size.height * 0.7), // Adjust the height of the square to match the width for a square shape
),
const Radius.circular(20), // Adjust the border radius as needed
))
..fillType = PathFillType.evenOdd;
return path;
}
@override
bool shouldReclip(covariant CustomClipper<Path> oldClipper) {
return false;
}
}