Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Unable to view details of product after scanning #1726

Merged
merged 7 commits into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContinuousScanModel>();
subtitleText = '$brands${quantity == '' ? '' : ', $quantity'}';
trailingWidget = InkWell(
Expand Down
6 changes: 2 additions & 4 deletions packages/smooth_app/lib/helpers/picture_capture_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -41,7 +40,6 @@ Future<bool> uploadCapturedPicture(

Future<void> _updateContinuousScanModel(
BuildContext context, String barcode) async {
final ContinuousScanModel? model =
await ContinuousScanModel().load(context.read<LocalDatabase>());
await model?.onCreateProduct(barcode);
final ContinuousScanModel model = context.read<ContinuousScanModel>();
await model.onCreateProduct(barcode);
}
4 changes: 4 additions & 0 deletions packages/smooth_app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -64,6 +65,7 @@ late UserPreferences _userPreferences;
late ProductPreferences _productPreferences;
late LocalDatabase _localDatabase;
late ThemeProvider _themeProvider;
final ContinuousScanModel _continuousScanModel = ContinuousScanModel();
bool _init1done = false;

// Had to split init in 2 methods, for test/screenshots reasons.
Expand All @@ -84,6 +86,7 @@ Future<bool> _init1() async {
);
_userPreferences = await UserPreferences.getUserPreferences();
_localDatabase = await LocalDatabase.getLocalDatabase();
await _continuousScanModel.load(_localDatabase);
_productPreferences = ProductPreferences(
ProductPreferencesSelection(
setImportance: _userPreferences.setImportance,
Expand Down Expand Up @@ -167,6 +170,7 @@ class _SmoothAppState extends State<SmoothApp> {
provide<LocalDatabase>(_localDatabase),
provide<ThemeProvider>(_themeProvider),
provide<UserManagementProvider>(_userManagementProvider),
provide<ContinuousScanModel>(_continuousScanModel),
],
builder: _buildApp,
);
Expand Down
6 changes: 2 additions & 4 deletions packages/smooth_app/lib/pages/scan/scan_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -35,11 +34,10 @@ class _ScanPageState extends State<ScanPage> {
}

Future<void> _updateModel() async {
final LocalDatabase localDatabase = context.watch<LocalDatabase>();
if (_model == null) {
_model = await ContinuousScanModel().load(localDatabase);
_model = context.read<ContinuousScanModel>();
} else {
await _model?.refresh();
await _model!.refresh();
}
setState(() {});
}
Expand Down