feat(barcode): add scanner, upd flutter version in ci

This commit is contained in:
mso7nueh
2025-11-17 20:25:52 +03:00
parent 66d2533add
commit db5dddff86
5 changed files with 112 additions and 6 deletions

View File

@@ -0,0 +1,87 @@
import 'package:flutter/material.dart';
import 'package:mobile_scanner/mobile_scanner.dart';
class BarcodeScannerScreen extends StatefulWidget {
const BarcodeScannerScreen({super.key});
@override
State<BarcodeScannerScreen> createState() => _BarcodeScannerScreenState();
}
class _BarcodeScannerScreenState extends State<BarcodeScannerScreen> {
final MobileScannerController _controller = MobileScannerController();
String? _detectedBarcode;
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Сканирование штрихкода'),
centerTitle: true,
),
body: Column(
children: [
Expanded(
child: MobileScanner(
controller: _controller,
onDetect: (capture) {
final List<Barcode> barcodes = capture.barcodes;
if (barcodes.isEmpty) return;
final rawValue = barcodes.first.rawValue;
if (rawValue == null || rawValue == _detectedBarcode) return;
setState(() {
_detectedBarcode = rawValue;
});
},
),
),
Container(
width: double.infinity,
padding: const EdgeInsets.all(16),
decoration: const BoxDecoration(
color: Color(0xFFF6F6F6),
borderRadius: BorderRadius.vertical(top: Radius.circular(24)),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text(
'Найденный штрихкод',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
),
const SizedBox(height: 8),
Text(
_detectedBarcode ?? 'Наведите камеру на штрихкод',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
color: _detectedBarcode == null ? Colors.grey : Colors.black,
),
),
const SizedBox(height: 16),
if (_detectedBarcode != null)
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: () {
Navigator.of(context).pop(_detectedBarcode);
},
child: const Text('Использовать штрихкод'),
),
),
],
),
),
],
),
);
}
}

View File

@@ -5,9 +5,11 @@ import 'package:eatvio_app/core/widgets/custom_text_form_field.dart';
import 'package:eatvio_app/features/diary/models/diary_day_model.dart';
import 'package:eatvio_app/features/diary/presentation/bloc/diary_cubit.dart';
import 'package:eatvio_app/features/diary/presentation/bloc/diary_state.dart';
import 'package:eatvio_app/features/diary/presentation/pages/barcode_scanner_screen.dart';
import 'package:eatvio_app/features/diary/presentation/widgets/glossary_moderation_request_modal_widget.dart';
import 'package:eatvio_app/features/glossary/models/glossary_model.dart';
import 'package:flutter/material.dart';
import 'package:material_symbols_icons/material_symbols_icons.dart';
class AddProductModal extends StatefulWidget {
final PortionModel? portion;
@@ -62,9 +64,25 @@ class _AddProductModalState extends State<AddProductModal> {
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
const Text(
'Добавление блюда',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.w600, color: Color(0xFF323F4B)),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text(
'Добавление блюда',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.w600, color: Color(0xFF323F4B)),
),
IconButton(
onPressed: () async {
final barcode = await Navigator.of(context).push<String>(MaterialPageRoute(builder: (context) => const BarcodeScannerScreen()));
if (barcode != null && barcode.isNotEmpty) {
productNameController.text = barcode;
setState(() {});
}
},
splashRadius: 20,
icon: const Icon(Symbols.barcode_scanner, color: Color(0xFF323F4B)),
),
],
),
const SizedBox(height: 16),
Row(