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

feat: Add price with the "Edit UI" #6171

Merged
merged 1 commit into from
Jan 10, 2025
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
14 changes: 8 additions & 6 deletions packages/smooth_app/lib/pages/prices/price_add_product_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:provider/provider.dart';
import 'package:smooth_app/data_models/preferences/user_preferences.dart';
import 'package:smooth_app/database/local_database.dart';
import 'package:smooth_app/generic_lib/buttons/smooth_large_button_with_icon.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/generic_lib/dialogs/smooth_alert_dialog.dart';
import 'package:smooth_app/generic_lib/widgets/smooth_card.dart';
import 'package:smooth_app/generic_lib/widgets/smooth_text_form_field.dart';
Expand Down Expand Up @@ -40,14 +41,15 @@ class _PriceAddProductCardState extends State<PriceAddProductCard> {
@override
Widget build(BuildContext context) {
final AppLocalizations appLocalizations = AppLocalizations.of(context);
return SmoothCard(
return SmoothCardWithRoundedHeader(
title: appLocalizations.prices_add_an_item,
leading: const Icon(Icons.add_circle_outlined),
contentPadding: const EdgeInsetsDirectional.symmetric(
horizontal: SMALL_SPACE,
vertical: MEDIUM_SPACE,
),
child: Column(
children: <Widget>[
ListTile(
title: Text(
appLocalizations.prices_add_an_item,
),
),
SmoothLargeButtonWithIcon(
text: appLocalizations.prices_barcode_reader_action,
icon: Icons.barcode_reader,
Expand Down
13 changes: 8 additions & 5 deletions packages/smooth_app/lib/pages/prices/price_amount_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,16 @@ class _PriceAmountCardState extends State<PriceAmountCard> {
final PriceAmountModel model = priceModel.elementAt(widget.index);
final int total = priceModel.length;

return SmoothCard(
return SmoothCardWithRoundedHeader(
title: '${appLocalizations.prices_amount_subtitle}'
'${total == 1 ? '' : ' (${widget.index + 1}/$total)'}',
leading: const Icon(Icons.calculate_rounded),
contentPadding: const EdgeInsetsDirectional.symmetric(
vertical: MEDIUM_SPACE,
horizontal: SMALL_SPACE,
),
child: Column(
children: <Widget>[
Text(
'${appLocalizations.prices_amount_subtitle}'
'${total == 1 ? '' : ' (${widget.index + 1}/$total)'}',
),
PriceProductListTile(
product: model.product,
trailingIconData: total == 1 ? null : Icons.clear,
Expand Down
14 changes: 8 additions & 6 deletions packages/smooth_app/lib/pages/prices/price_currency_card.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/generic_lib/widgets/smooth_card.dart';
import 'package:smooth_app/pages/prices/price_currency_selector.dart';

Expand All @@ -10,13 +11,14 @@ class PriceCurrencyCard extends StatelessWidget {
@override
Widget build(BuildContext context) {
final AppLocalizations appLocalizations = AppLocalizations.of(context);
return SmoothCard(
child: Column(
children: <Widget>[
Text(appLocalizations.prices_currency_subtitle),
PriceCurrencySelector(),
],
return SmoothCardWithRoundedHeader(
title: appLocalizations.prices_currency_subtitle,
leading: const Icon(Icons.price_change),
contentPadding: const EdgeInsetsDirectional.symmetric(
horizontal: SMALL_SPACE,
vertical: MEDIUM_SPACE,
),
child: PriceCurrencySelector(),
);
}
}
69 changes: 35 additions & 34 deletions packages/smooth_app/lib/pages/prices/price_date_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import 'package:smooth_app/generic_lib/buttons/smooth_large_button_with_icon.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/generic_lib/widgets/smooth_card.dart';
import 'package:smooth_app/pages/prices/price_model.dart';
import 'package:smooth_app/query/product_query.dart';
Expand All @@ -17,42 +18,42 @@ class PriceDateCard extends StatelessWidget {
final AppLocalizations appLocalizations = AppLocalizations.of(context);
final String locale = ProductQuery.getLocaleString();
final DateFormat dateFormat = DateFormat.yMd(locale);
return SmoothCard(
child: Column(
children: <Widget>[
Text(appLocalizations.prices_date_subtitle),
SmoothLargeButtonWithIcon(
text: dateFormat.format(model.date),
icon: Icons.calendar_month,
onPressed: model.proof != null
? null
: () async {
final DateTime? newDate = await showDatePicker(
context: context,
locale: Locale(ProductQuery.getLanguage().offTag),
firstDate: model.firstDate,
lastDate: model.today,
builder:
(final BuildContext context, final Widget? child) {
// for some reason we don't have a fine display without that theme.
// cf. https://stackoverflow.com/questions/50321182/how-to-customize-a-date-picker
final ThemeData themeData =
Theme.of(context).brightness == Brightness.light
? ThemeData.light()
: ThemeData.dark();
return Theme(
data: themeData.copyWith(),
child: child!,
);
},
return SmoothCardWithRoundedHeader(
title: appLocalizations.prices_date_subtitle,
leading: const Icon(Icons.calendar_month),
contentPadding: const EdgeInsetsDirectional.symmetric(
horizontal: SMALL_SPACE,
vertical: MEDIUM_SPACE,
),
child: SmoothLargeButtonWithIcon(
text: dateFormat.format(model.date),
icon: Icons.calendar_month,
onPressed: model.proof != null
? null
: () async {
final DateTime? newDate = await showDatePicker(
context: context,
locale: Locale(ProductQuery.getLanguage().offTag),
firstDate: model.firstDate,
lastDate: model.today,
builder: (final BuildContext context, final Widget? child) {
// for some reason we don't have a fine display without that theme.
// cf. https://stackoverflow.com/questions/50321182/how-to-customize-a-date-picker
final ThemeData themeData =
Theme.of(context).brightness == Brightness.light
? ThemeData.light()
: ThemeData.dark();
return Theme(
data: themeData.copyWith(),
child: child!,
);
if (newDate == null) {
return;
}
model.date = newDate;
},
),
],
);
if (newDate == null) {
return;
}
model.date = newDate;
},
),
);
}
Expand Down
104 changes: 53 additions & 51 deletions packages/smooth_app/lib/pages/prices/price_location_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:provider/provider.dart';
import 'package:smooth_app/database/dao_osm_location.dart';
import 'package:smooth_app/database/local_database.dart';
import 'package:smooth_app/generic_lib/buttons/smooth_large_button_with_icon.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/generic_lib/widgets/smooth_card.dart';
import 'package:smooth_app/pages/locations/osm_location.dart';
import 'package:smooth_app/pages/locations/search_location_helper.dart';
Expand All @@ -21,57 +22,58 @@ class PriceLocationCard extends StatelessWidget {
final PriceModel model = context.watch<PriceModel>();
final AppLocalizations appLocalizations = AppLocalizations.of(context);
final OsmLocation? location = model.location;
return SmoothCard(
child: Column(
children: <Widget>[
Text(appLocalizations.prices_location_subtitle),
SmoothLargeButtonWithIcon(
text: location == null
? appLocalizations.prices_location_find
: location.getTitle() ??
location.getSubtitle() ??
location.getLatLng().toString(),
icon: location == null
? Icons.shopping_cart
: PriceButton.locationIconData,
onPressed: model.proof != null
? null
: () async {
final LocalDatabase localDatabase =
context.read<LocalDatabase>();
final List<SearchLocationPreloadedItem> preloadedList =
<SearchLocationPreloadedItem>[];
for (final OsmLocation osmLocation in model.locations!) {
preloadedList.add(
SearchLocationPreloadedItem(
osmLocation,
popFirst: false,
),
);
}
final OsmLocation? osmLocation =
await Navigator.push<OsmLocation>(
context,
MaterialPageRoute<OsmLocation>(
builder: (BuildContext context) => SearchPage(
SearchLocationHelper(),
preloadedList: preloadedList,
autofocus: false,
),
),
);
if (osmLocation == null) {
return;
}
final DaoOsmLocation daoOsmLocation =
DaoOsmLocation(localDatabase);
await daoOsmLocation.put(osmLocation);
final List<OsmLocation> newOsmLocations =
await daoOsmLocation.getAll();
model.locations = newOsmLocations;
},
),
],
return SmoothCardWithRoundedHeader(
title: appLocalizations.prices_location_subtitle,
leading: const Icon(Icons.shopping_cart),
contentPadding: const EdgeInsetsDirectional.symmetric(
horizontal: SMALL_SPACE,
vertical: MEDIUM_SPACE,
),
child: SmoothLargeButtonWithIcon(
text: location == null
? appLocalizations.prices_location_find
: location.getTitle() ??
location.getSubtitle() ??
location.getLatLng().toString(),
icon: location == null
? Icons.shopping_cart
: PriceButton.locationIconData,
onPressed: model.proof != null
? null
: () async {
final LocalDatabase localDatabase =
context.read<LocalDatabase>();
final List<SearchLocationPreloadedItem> preloadedList =
<SearchLocationPreloadedItem>[];
for (final OsmLocation osmLocation in model.locations!) {
preloadedList.add(
SearchLocationPreloadedItem(
osmLocation,
popFirst: false,
),
);
}
final OsmLocation? osmLocation =
await Navigator.push<OsmLocation>(
context,
MaterialPageRoute<OsmLocation>(
builder: (BuildContext context) => SearchPage(
SearchLocationHelper(),
preloadedList: preloadedList,
autofocus: false,
),
),
);
if (osmLocation == null) {
return;
}
final DaoOsmLocation daoOsmLocation =
DaoOsmLocation(localDatabase);
await daoOsmLocation.put(osmLocation);
final List<OsmLocation> newOsmLocations =
await daoOsmLocation.getAll();
model.locations = newOsmLocations;
},
),
);
}
Expand Down
55 changes: 33 additions & 22 deletions packages/smooth_app/lib/pages/prices/price_proof_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:provider/provider.dart';
import 'package:smooth_app/data_models/preferences/user_preferences.dart';
import 'package:smooth_app/generic_lib/buttons/smooth_large_button_with_icon.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/generic_lib/widgets/smooth_card.dart';
import 'package:smooth_app/helpers/camera_helper.dart';
import 'package:smooth_app/pages/crop_parameters.dart';
Expand All @@ -27,10 +28,15 @@ class PriceProofCard extends StatelessWidget {
Widget build(BuildContext context) {
final PriceModel model = context.watch<PriceModel>();
final AppLocalizations appLocalizations = AppLocalizations.of(context);
return SmoothCard(
return SmoothCardWithRoundedHeader(
title: appLocalizations.prices_proof_subtitle,
leading: const Icon(Icons.document_scanner_rounded),
contentPadding: const EdgeInsetsDirectional.symmetric(
horizontal: SMALL_SPACE,
vertical: MEDIUM_SPACE,
),
child: Column(
children: <Widget>[
Text(appLocalizations.prices_proof_subtitle),
if (model.proof != null)
Image(
image: NetworkImage(
Expand All @@ -53,26 +59,31 @@ class PriceProofCard extends StatelessWidget {
height: constraints.maxWidth,
),
),
SmoothLargeButtonWithIcon(
text: !model.hasImage
? appLocalizations.prices_proof_find
: model.proofType == ProofType.receipt
? appLocalizations.prices_proof_receipt
: appLocalizations.prices_proof_price_tag,
icon: !model.hasImage ? _iconTodo : _iconDone,
onPressed: model.proof != null
? null
: () async {
final _ProofSource? proofSource =
await _ProofSource.select(context);
if (proofSource == null) {
return;
}
if (!context.mounted) {
return;
}
return proofSource.process(context, model);
},
Padding(
padding: const EdgeInsetsDirectional.symmetric(
horizontal: SMALL_SPACE,
),
child: SmoothLargeButtonWithIcon(
text: !model.hasImage
? appLocalizations.prices_proof_find
: model.proofType == ProofType.receipt
? appLocalizations.prices_proof_receipt
: appLocalizations.prices_proof_price_tag,
icon: !model.hasImage ? _iconTodo : _iconDone,
onPressed: model.proof != null
? null
: () async {
final _ProofSource? proofSource =
await _ProofSource.select(context);
if (proofSource == null) {
return;
}
if (!context.mounted) {
return;
}
return proofSource.process(context, model);
},
),
),
LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) => Row(
Expand Down
Loading
Loading