From 02ead3db83874c0e855119c5e2d08b7065d2815e Mon Sep 17 00:00:00 2001 From: Abhishek Date: Sat, 30 Apr 2022 23:25:49 +0530 Subject: [PATCH 1/7] fix: Unable to view details of product after scanning --- .../smooth_app/lib/cards/product_cards/product_title_card.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/smooth_app/lib/cards/product_cards/product_title_card.dart b/packages/smooth_app/lib/cards/product_cards/product_title_card.dart index 77cef9ff5cc..534f304bd71 100644 --- a/packages/smooth_app/lib/cards/product_cards/product_title_card.dart +++ b/packages/smooth_app/lib/cards/product_cards/product_title_card.dart @@ -28,7 +28,7 @@ class ProductTitleCard extends StatelessWidget { final Widget trailingWidget; final String brands = product.brands ?? appLocalizations.unknownBrand; final String quantity = product.quantity ?? ''; - if (isRemovable) { + if (isRemovable && !isSelectable) { final ContinuousScanModel model = context.watch(); subtitleText = '$brands${quantity == '' ? '' : ', $quantity'}'; trailingWidget = InkWell( From 04534eb3b4f439f32afee612520dda4a1c610d88 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Sun, 1 May 2022 00:35:19 +0530 Subject: [PATCH 2/7] moved the provider to main.dart file --- .../lib/cards/product_cards/product_title_card.dart | 2 +- packages/smooth_app/lib/main.dart | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/smooth_app/lib/cards/product_cards/product_title_card.dart b/packages/smooth_app/lib/cards/product_cards/product_title_card.dart index 534f304bd71..77cef9ff5cc 100644 --- a/packages/smooth_app/lib/cards/product_cards/product_title_card.dart +++ b/packages/smooth_app/lib/cards/product_cards/product_title_card.dart @@ -28,7 +28,7 @@ class ProductTitleCard extends StatelessWidget { final Widget trailingWidget; final String brands = product.brands ?? appLocalizations.unknownBrand; final String quantity = product.quantity ?? ''; - if (isRemovable && !isSelectable) { + if (isRemovable) { final ContinuousScanModel model = context.watch(); subtitleText = '$brands${quantity == '' ? '' : ', $quantity'}'; trailingWidget = InkWell( diff --git a/packages/smooth_app/lib/main.dart b/packages/smooth_app/lib/main.dart index f2131260796..b71b562e3d4 100644 --- a/packages/smooth_app/lib/main.dart +++ b/packages/smooth_app/lib/main.dart @@ -14,6 +14,7 @@ import 'package:openfoodfacts/utils/OpenFoodAPIConfiguration.dart'; import 'package:package_info_plus/package_info_plus.dart'; import 'package:provider/provider.dart'; import 'package:sentry_flutter/sentry_flutter.dart'; +import 'package:smooth_app/data_models/continuous_scan_model.dart'; import 'package:smooth_app/data_models/product_preferences.dart'; import 'package:smooth_app/data_models/user_management_provider.dart'; import 'package:smooth_app/data_models/user_preferences.dart'; @@ -110,6 +111,8 @@ class _SmoothAppState extends State { final UserManagementProvider _userManagementProvider = UserManagementProvider(); + final ContinuousScanModel _continuousScanModel = ContinuousScanModel(); + bool systemDarkmodeOn = false; final Brightness brightness = SchedulerBinding.instance?.window.platformBrightness ?? Brightness.light; @@ -167,6 +170,7 @@ class _SmoothAppState extends State { provide(_localDatabase), provide(_themeProvider), provide(_userManagementProvider), + provide(_continuousScanModel), ], builder: _buildApp, ); From 72adc4d405d0c9f5be1ebefbc632597b0435af2b Mon Sep 17 00:00:00 2001 From: Abhishek Date: Sun, 1 May 2022 23:20:30 +0530 Subject: [PATCH 3/7] cross button changes --- .../smooth_app/lib/cards/product_cards/product_title_card.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/smooth_app/lib/cards/product_cards/product_title_card.dart b/packages/smooth_app/lib/cards/product_cards/product_title_card.dart index 77cef9ff5cc..534f304bd71 100644 --- a/packages/smooth_app/lib/cards/product_cards/product_title_card.dart +++ b/packages/smooth_app/lib/cards/product_cards/product_title_card.dart @@ -28,7 +28,7 @@ class ProductTitleCard extends StatelessWidget { final Widget trailingWidget; final String brands = product.brands ?? appLocalizations.unknownBrand; final String quantity = product.quantity ?? ''; - if (isRemovable) { + if (isRemovable && !isSelectable) { final ContinuousScanModel model = context.watch(); subtitleText = '$brands${quantity == '' ? '' : ', $quantity'}'; trailingWidget = InkWell( From 3aa54536431d25679b42f1a2a812c53697ba461b Mon Sep 17 00:00:00 2001 From: Abhishek Date: Tue, 3 May 2022 13:39:38 +0530 Subject: [PATCH 4/7] removed extra instances of ContinuousScanModel() --- packages/smooth_app/lib/helpers/picture_capture_helper.dart | 5 +++-- packages/smooth_app/lib/pages/scan/scan_page.dart | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/smooth_app/lib/helpers/picture_capture_helper.dart b/packages/smooth_app/lib/helpers/picture_capture_helper.dart index 7ea91e7debc..1db6b4f2f96 100644 --- a/packages/smooth_app/lib/helpers/picture_capture_helper.dart +++ b/packages/smooth_app/lib/helpers/picture_capture_helper.dart @@ -41,7 +41,8 @@ Future uploadCapturedPicture( Future _updateContinuousScanModel( BuildContext context, String barcode) async { - final ContinuousScanModel? model = - await ContinuousScanModel().load(context.read()); + final ContinuousScanModel? model = await context + .read() + .load(context.read()); await model?.onCreateProduct(barcode); } diff --git a/packages/smooth_app/lib/pages/scan/scan_page.dart b/packages/smooth_app/lib/pages/scan/scan_page.dart index 88371070c97..46c3baf6cca 100644 --- a/packages/smooth_app/lib/pages/scan/scan_page.dart +++ b/packages/smooth_app/lib/pages/scan/scan_page.dart @@ -35,9 +35,10 @@ class _ScanPageState extends State { } Future _updateModel() async { - final LocalDatabase localDatabase = context.watch(); if (_model == null) { - _model = await ContinuousScanModel().load(localDatabase); + _model = await context + .read() + .load(context.read()); } else { await _model?.refresh(); } From ff7c14d86ee70bdd4f939f3bcf197c5ee46c94b7 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Tue, 3 May 2022 15:50:21 +0530 Subject: [PATCH 5/7] added provider to async init --- .../smooth_app/lib/helpers/picture_capture_helper.dart | 7 +++---- packages/smooth_app/lib/main.dart | 4 ++-- packages/smooth_app/lib/pages/scan/scan_page.dart | 5 ++--- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/smooth_app/lib/helpers/picture_capture_helper.dart b/packages/smooth_app/lib/helpers/picture_capture_helper.dart index 1db6b4f2f96..001d805a894 100644 --- a/packages/smooth_app/lib/helpers/picture_capture_helper.dart +++ b/packages/smooth_app/lib/helpers/picture_capture_helper.dart @@ -41,8 +41,7 @@ Future uploadCapturedPicture( Future _updateContinuousScanModel( BuildContext context, String barcode) async { - final ContinuousScanModel? model = await context - .read() - .load(context.read()); - await model?.onCreateProduct(barcode); + final ContinuousScanModel model = context.read(); + model.load(context.read()); + await model.onCreateProduct(barcode); } diff --git a/packages/smooth_app/lib/main.dart b/packages/smooth_app/lib/main.dart index b71b562e3d4..7a641b1914a 100644 --- a/packages/smooth_app/lib/main.dart +++ b/packages/smooth_app/lib/main.dart @@ -65,6 +65,7 @@ late UserPreferences _userPreferences; late ProductPreferences _productPreferences; late LocalDatabase _localDatabase; late ThemeProvider _themeProvider; +late ContinuousScanModel _continuousScanModel; bool _init1done = false; // Had to split init in 2 methods, for test/screenshots reasons. @@ -85,6 +86,7 @@ Future _init1() async { ); _userPreferences = await UserPreferences.getUserPreferences(); _localDatabase = await LocalDatabase.getLocalDatabase(); + _continuousScanModel = ContinuousScanModel(); _productPreferences = ProductPreferences( ProductPreferencesSelection( setImportance: _userPreferences.setImportance, @@ -111,8 +113,6 @@ class _SmoothAppState extends State { final UserManagementProvider _userManagementProvider = UserManagementProvider(); - final ContinuousScanModel _continuousScanModel = ContinuousScanModel(); - bool systemDarkmodeOn = false; final Brightness brightness = SchedulerBinding.instance?.window.platformBrightness ?? Brightness.light; diff --git a/packages/smooth_app/lib/pages/scan/scan_page.dart b/packages/smooth_app/lib/pages/scan/scan_page.dart index 46c3baf6cca..dabffaa6083 100644 --- a/packages/smooth_app/lib/pages/scan/scan_page.dart +++ b/packages/smooth_app/lib/pages/scan/scan_page.dart @@ -36,9 +36,8 @@ class _ScanPageState extends State { Future _updateModel() async { if (_model == null) { - _model = await context - .read() - .load(context.read()); + _model = context.read(); + _model!.load(context.read()); } else { await _model?.refresh(); } From 0c18e5e89aab169d29e52eb09e6c9d6a8f309ff8 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Tue, 3 May 2022 15:56:46 +0530 Subject: [PATCH 6/7] loaded at init --- packages/smooth_app/lib/helpers/picture_capture_helper.dart | 2 -- packages/smooth_app/lib/main.dart | 2 +- packages/smooth_app/lib/pages/scan/scan_page.dart | 2 -- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/smooth_app/lib/helpers/picture_capture_helper.dart b/packages/smooth_app/lib/helpers/picture_capture_helper.dart index 001d805a894..1765d5e4206 100644 --- a/packages/smooth_app/lib/helpers/picture_capture_helper.dart +++ b/packages/smooth_app/lib/helpers/picture_capture_helper.dart @@ -3,7 +3,6 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:openfoodfacts/openfoodfacts.dart'; import 'package:provider/provider.dart'; import 'package:smooth_app/data_models/continuous_scan_model.dart'; -import 'package:smooth_app/database/local_database.dart'; import 'package:smooth_app/database/product_query.dart'; import 'package:smooth_app/generic_lib/loading_dialog.dart'; @@ -42,6 +41,5 @@ Future uploadCapturedPicture( Future _updateContinuousScanModel( BuildContext context, String barcode) async { final ContinuousScanModel model = context.read(); - model.load(context.read()); await model.onCreateProduct(barcode); } diff --git a/packages/smooth_app/lib/main.dart b/packages/smooth_app/lib/main.dart index 7a641b1914a..65c5a0cb090 100644 --- a/packages/smooth_app/lib/main.dart +++ b/packages/smooth_app/lib/main.dart @@ -86,7 +86,7 @@ Future _init1() async { ); _userPreferences = await UserPreferences.getUserPreferences(); _localDatabase = await LocalDatabase.getLocalDatabase(); - _continuousScanModel = ContinuousScanModel(); + _continuousScanModel = (await ContinuousScanModel().load(_localDatabase))!; _productPreferences = ProductPreferences( ProductPreferencesSelection( setImportance: _userPreferences.setImportance, diff --git a/packages/smooth_app/lib/pages/scan/scan_page.dart b/packages/smooth_app/lib/pages/scan/scan_page.dart index dabffaa6083..91f44142097 100644 --- a/packages/smooth_app/lib/pages/scan/scan_page.dart +++ b/packages/smooth_app/lib/pages/scan/scan_page.dart @@ -7,7 +7,6 @@ import 'package:permission_handler/permission_handler.dart'; import 'package:provider/provider.dart'; import 'package:smooth_app/data_models/continuous_scan_model.dart'; import 'package:smooth_app/data_models/user_preferences.dart'; -import 'package:smooth_app/database/local_database.dart'; import 'package:smooth_app/generic_lib/buttons/smooth_action_button.dart'; import 'package:smooth_app/generic_lib/dialogs/smooth_alert_dialog.dart'; import 'package:smooth_app/generic_lib/widgets/smooth_card.dart'; @@ -37,7 +36,6 @@ class _ScanPageState extends State { Future _updateModel() async { if (_model == null) { _model = context.read(); - _model!.load(context.read()); } else { await _model?.refresh(); } From 8a7f55c15d0be9e4c9d33b577942ca63e97dfbe5 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Tue, 3 May 2022 21:04:15 +0530 Subject: [PATCH 7/7] improvization --- packages/smooth_app/lib/main.dart | 4 ++-- packages/smooth_app/lib/pages/scan/scan_page.dart | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/smooth_app/lib/main.dart b/packages/smooth_app/lib/main.dart index 65c5a0cb090..3f777da3b6f 100644 --- a/packages/smooth_app/lib/main.dart +++ b/packages/smooth_app/lib/main.dart @@ -65,7 +65,7 @@ late UserPreferences _userPreferences; late ProductPreferences _productPreferences; late LocalDatabase _localDatabase; late ThemeProvider _themeProvider; -late ContinuousScanModel _continuousScanModel; +final ContinuousScanModel _continuousScanModel = ContinuousScanModel(); bool _init1done = false; // Had to split init in 2 methods, for test/screenshots reasons. @@ -86,7 +86,7 @@ Future _init1() async { ); _userPreferences = await UserPreferences.getUserPreferences(); _localDatabase = await LocalDatabase.getLocalDatabase(); - _continuousScanModel = (await ContinuousScanModel().load(_localDatabase))!; + await _continuousScanModel.load(_localDatabase); _productPreferences = ProductPreferences( ProductPreferencesSelection( setImportance: _userPreferences.setImportance, diff --git a/packages/smooth_app/lib/pages/scan/scan_page.dart b/packages/smooth_app/lib/pages/scan/scan_page.dart index 91f44142097..16f770216be 100644 --- a/packages/smooth_app/lib/pages/scan/scan_page.dart +++ b/packages/smooth_app/lib/pages/scan/scan_page.dart @@ -37,7 +37,7 @@ class _ScanPageState extends State { if (_model == null) { _model = context.read(); } else { - await _model?.refresh(); + await _model!.refresh(); } setState(() {}); }