@@ -342,8 +342,7 @@ class DigitScannerPageState extends LocalizedState<DigitScannerPage>
342342 scannerId: widget.scannerId,
343343 ),
344344 );
345- } else if (widget.isEditEnabled &&
346- _originalBarcodes.isNotEmpty) {
345+ } else if (widget.isEditEnabled && _originalBarcodes.isNotEmpty) {
347346 // Restore initial barcode values when canceling edit
348347 context.read <DigitScannerBloc >().add (
349348 DigitScannerEvent .handleScanner (
@@ -561,7 +560,6 @@ class DigitScannerPageState extends LocalizedState<DigitScannerPage>
561560 if (! form.valid) return ;
562561
563562 final bloc = context.read <DigitScannerBloc >();
564- codes.add (form.control (_manualCodeFormKey).value);
565563
566564 try {
567565 final barcodeString =
@@ -585,8 +583,12 @@ class DigitScannerPageState extends LocalizedState<DigitScannerPage>
585583 final parser = GS1BarcodeParser .defaultParser ();
586584 final parsed = parser.parse (barcodeString);
587585 // ✅ Append to existing barcodes; DO NOT touch qrCodes in GS1 mode
586+ // Use local result as fallback when bloc state is empty
587+ final existingBarcodes = state.barCodes.isNotEmpty
588+ ? state.barCodes
589+ : result;
588590 final updatedBarcodes =
589- List <GS1Barcode >.from (state.barCodes )
591+ List <GS1Barcode >.from (existingBarcodes )
590592 ..add (parsed);
591593
592594 // Keep local mirror in sync (used by UI)
@@ -604,18 +606,16 @@ class DigitScannerPageState extends LocalizedState<DigitScannerPage>
604606 scannerId: widget.scannerId,
605607 ),
606608 );
607- setState (() {
608- manualCode = false ;
609- });
610609
611610 initializeCameras ();
612611 } catch (e) {
613- debugPrint ('Error parsing manual GS1 barcode: $e ' );
612+ debugPrint (
613+ 'Error parsing manual GS1 barcode: $e ' );
614614 Toast .showToast (
615615 context,
616616 type: ToastType .error,
617- message: localizations. translate (
618- i18.scanner.resourcesScanFailed),
617+ message: localizations
618+ . translate ( i18.scanner.resourcesScanFailed),
619619 sentenceCaseEnabled: false ,
620620 );
621621 }
@@ -836,18 +836,22 @@ class DigitScannerPageState extends LocalizedState<DigitScannerPage>
836836 type: ToastType .error,
837837 message: localizations
838838 .translate (i18.scanner.enterManualCode),
839- sentenceCaseEnabled: false ,
839+ sentenceCaseEnabled: false ,
840840 );
841841 } else {
842842 final bloc = context.read <DigitScannerBloc >();
843+ // Use local codes as fallback when bloc state is empty
844+ final existingQrCodes = state.qrCodes.isNotEmpty
845+ ? state.qrCodes
846+ : codes;
843847 final updatedQRCodes =
844- List <String >.from (state.qrCodes )
848+ List <String >.from (existingQrCodes )
845849 ..add (form
846850 .control (_manualCodeFormKey)
847851 .value
848852 .toString ()
849853 .trim ());
850- codes. add (form. control (_manualCodeFormKey).value) ;
854+ codes = updatedQRCodes ;
851855 bloc.add (
852856 DigitScannerEvent .handleScanner (
853857 barCode: state.barCodes,
@@ -940,8 +944,7 @@ class DigitScannerPageState extends LocalizedState<DigitScannerPage>
940944 scannerId: widget.scannerId,
941945 ),
942946 );
943- } else if (widget.isEditEnabled &&
944- _originalBarcodes.isNotEmpty) {
947+ } else if (widget.isEditEnabled && _originalBarcodes.isNotEmpty) {
945948 // Restore initial barcode values when canceling edit
946949 context.read <DigitScannerBloc >().add (
947950 DigitScannerEvent .handleScanner (
@@ -1047,13 +1050,6 @@ class DigitScannerPageState extends LocalizedState<DigitScannerPage>
10471050 i18.scanner.enterManualCode,
10481051 ),
10491052 onPressed: () {
1050- context.read <DigitScannerBloc >().add (
1051- DigitScannerEvent .handleScanner (
1052- barCode: [],
1053- qrCode: [],
1054- scannerId: widget.scannerId,
1055- ),
1056- );
10571053 setState (() {
10581054 manualCode = true ;
10591055 });
@@ -1070,7 +1066,8 @@ class DigitScannerPageState extends LocalizedState<DigitScannerPage>
10701066 ThemeData theme, DigitTextTheme textTheme, DigitScannerState state) {
10711067 // Use state.barCodes when available, fall back to local result list
10721068 // This handles the case where bloc state hasn't updated yet but result is set in initState
1073- final effectiveBarcodes = state.barCodes.isNotEmpty ? state.barCodes : result;
1069+ final effectiveBarcodes =
1070+ state.barCodes.isNotEmpty ? state.barCodes : result;
10741071 final effectiveQrCodes = state.qrCodes.isNotEmpty ? state.qrCodes : codes;
10751072 return Stack (
10761073 children: [
@@ -1115,13 +1112,10 @@ class DigitScannerPageState extends LocalizedState<DigitScannerPage>
11151112 ),
11161113 Positioned (
11171114 bottom: (spacer1 * 10 ),
1118- height: widget.effectiveIsGS1code
1119- ? effectiveBarcodes.length < 2
1120- ? (effectiveBarcodes.length * 160 ) + 80
1121- : MediaQuery .of (context).size.height / 2.5
1122- : effectiveQrCodes.length < 2
1123- ? ((effectiveQrCodes.length + 1 ) * 60 )
1124- : MediaQuery .of (context).size.height / 4 ,
1115+ height: (widget.effectiveIsGS1code
1116+ ? (effectiveBarcodes.length * 160.0 ) + 80.0
1117+ : ((effectiveQrCodes.length + 1 ) * 60.0 ))
1118+ .clamp (0.0 , MediaQuery .of (context).size.height / 3 ),
11251119 width: MediaQuery .of (context).size.width,
11261120 child: Container (
11271121 width: 100 ,
@@ -1200,9 +1194,8 @@ class DigitScannerPageState extends LocalizedState<DigitScannerPage>
12001194 crossAxisAlignment:
12011195 CrossAxisAlignment .start,
12021196 children: gs1Data.entries.map ((entry) {
1203- final label =
1204- localizations.translate (
1205- 'GS1_${entry .key }' );
1197+ final label = localizations
1198+ .translate ('GS1_${entry .key }' );
12061199 final value = entry.value is DateTime
12071200 ? DateFormat ('dd MMM yyyy' )
12081201 .format (entry.value)
@@ -1228,14 +1221,12 @@ class DigitScannerPageState extends LocalizedState<DigitScannerPage>
12281221 Expanded (
12291222 child: Text (
12301223 value,
1231- style:
1232- textTheme.bodyS.copyWith (
1233- color: theme.colorTheme.text
1234- .primary,
1224+ style: textTheme.bodyS.copyWith (
1225+ color: theme
1226+ .colorTheme.text.primary,
12351227 ),
12361228 maxLines: 2 ,
1237- overflow:
1238- TextOverflow .ellipsis,
1229+ overflow: TextOverflow .ellipsis,
12391230 ),
12401231 ),
12411232 ],
0 commit comments