This repository has been archived on 2025-08-25. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
Seshat/lib/ui/sell_page/widgets/scan_screen.dart
2025-08-15 23:23:43 +02:00

94 lines
2.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:mobile_scanner/mobile_scanner.dart';
import 'package:seshat/ui/sell_page/view_model/sell_view_model.dart';
import 'package:seshat/ui/sell_page/widgets/manual_search_popup.dart';
import 'package:seshat/ui/sell_page/widgets/sell_choice_popup.dart';
class ScanScreen extends StatefulWidget {
const ScanScreen({super.key, required this.viewModel});
final SellViewModel viewModel;
@override
State<ScanScreen> createState() => _ScanScreenState();
}
class _ScanScreenState extends State<ScanScreen> {
final MobileScannerController controller = MobileScannerController(
formats: [BarcodeFormat.ean13],
detectionTimeoutMs: 1000,
);
@override
void dispose() {
controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Stack(
children: [
ColoredBox(
color: Theme.of(context).scaffoldBackgroundColor,
child: SizedBox(
width: MediaQuery.sizeOf(context).width,
height: MediaQuery.sizeOf(context).height,
),
),
MobileScanner(
controller: controller,
onDetect: (barcodes) async {
controller.stop();
showDialog(
context: context,
useSafeArea: true,
builder: (context) =>
SellChoicePopup(viewModel: widget.viewModel),
);
await widget.viewModel.scanBook(barcodes);
},
),
SafeArea(
child: Column(
children: [
IconButton(
onPressed: () {
widget.viewModel.showScan = false;
},
icon: Icon(Icons.arrow_back),
),
],
),
),
Center(child: SvgPicture.asset('assets/scan-overlay.svg')),
Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Center(
child: TextButton(
style: ButtonStyle(
backgroundColor: WidgetStatePropertyAll(theme.cardColor),
),
onPressed: () {
controller.stop();
showDialog(
context: context,
barrierDismissible: false,
builder: (context) =>
ManualSearchPopup(viewModel: widget.viewModel),
);
},
child: Text("Vendre un livre sans scanner"),
),
),
SizedBox(height: 5),
],
),
],
);
}
}