Skip to content

Commit

Permalink
Fix about the previously scanned barcode
Browse files Browse the repository at this point in the history
Impacted files:
* `price_add_product_card.dart`: populated the previously scanned barcode
* `price_scan_page.dart`: checked if barcode was just previously scanned; added back button
  • Loading branch information
monsieurtanuki committed Sep 8, 2024
1 parent e66fef2 commit 8a8f462
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
14 changes: 12 additions & 2 deletions packages/smooth_app/lib/pages/prices/price_add_product_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ import 'package:smooth_app/pages/prices/price_model.dart';
import 'package:smooth_app/pages/prices/price_scan_page.dart';

/// Card where the user can input a price product: type the barcode or scan.
class PriceAddProductCard extends StatelessWidget {
class PriceAddProductCard extends StatefulWidget {
const PriceAddProductCard();

@override
State<PriceAddProductCard> createState() => _PriceAddProductCardState();
}

class _PriceAddProductCardState extends State<PriceAddProductCard> {
static const TextInputType _textInputType = TextInputType.number;

String? _latestScannedBarcode;

@override
Widget build(BuildContext context) {
final AppLocalizations appLocalizations = AppLocalizations.of(context);
Expand Down Expand Up @@ -85,12 +92,15 @@ class PriceAddProductCard extends StatelessWidget {
onPressed: () async {
final String? barcode = await Navigator.of(context).push<String>(
MaterialPageRoute<String>(
builder: (BuildContext context) => const PriceScanPage(),
builder: (BuildContext context) => PriceScanPage(
latestScannedBarcode: _latestScannedBarcode,
),
),
);
if (barcode == null) {
return;
}
_latestScannedBarcode = barcode;
if (!context.mounted) {
return;
}
Expand Down
13 changes: 12 additions & 1 deletion packages/smooth_app/lib/pages/prices/price_scan_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import 'package:smooth_app/helpers/camera_helper.dart';
import 'package:smooth_app/helpers/global_vars.dart';
import 'package:smooth_app/helpers/haptic_feedback_helper.dart';
import 'package:smooth_app/pages/scan/camera_scan_page.dart';
import 'package:smooth_app/widgets/smooth_app_bar.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';

/// Page showing the camera feed and decoding the first barcode, for Prices.
class PriceScanPage extends StatefulWidget {
const PriceScanPage();
const PriceScanPage({required this.latestScannedBarcode});

final String? latestScannedBarcode;

@override
State<PriceScanPage> createState() => _PriceScanPageState();
Expand All @@ -31,8 +34,16 @@ class _PriceScanPageState extends State<PriceScanPage>
Widget build(BuildContext context) {
final AppLocalizations appLocalizations = AppLocalizations.of(context);
return SmoothScaffold(
appBar: SmoothAppBar(
title: Text(appLocalizations.prices_add_an_item),
),
body: GlobalVars.barcodeScanner.getScanner(
onScan: (final String barcode) async {
// for some reason, the scanner sometimes returns immediately the
// previously scanned barcode.
if (widget.latestScannedBarcode == barcode) {
return false;
}
if (_mutex) {
return false;
}
Expand Down

0 comments on commit 8a8f462

Please sign in to comment.