Skip to content

feat: Add receipt and price icons to prices screen #6421

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

Draft
wants to merge 11 commits into
base: develop
Choose a base branch
from
Draft
144 changes: 68 additions & 76 deletions packages/smooth_app/lib/pages/prices/price_proof_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,30 +74,17 @@ class PriceProofCard extends StatelessWidget {
child: SmoothLargeButtonWithIcon(
text: !model.hasImage
? appLocalizations.prices_proof_find
: model.proofType.getTitle(appLocalizations),
: model.proofType == ProofType.receipt
? appLocalizations.prices_proof_receipt
: appLocalizations.prices_proof_price_tag,
leadingIcon: !model.hasImage
? const Icon(_iconTodo)
: const Icon(_iconDone),
onPressed: model.proof != null
? null
: () async {
final List<_ProofSource> sources =
_ProofSource.getPossibleProofSources(
includeMyProofs: includeMyProofs,
);
// not very likely
if (sources.isEmpty) {
return;
}
final _ProofSource? proofSource;
if (sources.length == 1) {
proofSource = sources.first;
} else {
proofSource = await _ProofSource.select(
context,
sources: sources,
);
}
final _ProofSource? proofSource =
await _ProofSource.select(context);
if (proofSource == null) {
return;
}
Expand All @@ -110,26 +97,54 @@ class PriceProofCard extends StatelessWidget {
),
LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) => Row(
children: (const <ProofType>[
ProofType.receipt,
ProofType.priceTag,
])
.map<Widget>(
(final ProofType item) => SizedBox(
width: constraints.maxWidth / 2,
child: RadioListTile<ProofType>(
title: Text(item.getTitle(appLocalizations)),
value: item,
children: <Widget>[
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've rolled back the previous code.
Please stick to the previous code unless you have a good reason. Duplicating code is not a good reason.

SizedBox(
width: constraints.maxWidth / 2,
child: Row(
children: [
Radio<ProofType>(
value: ProofType.receipt,
groupValue: model.proofType,
onChanged:
model.proof != null || forcedProofType != null
? null
: (final ProofType? proofType) =>
model.proofType = proofType!,
onChanged: model.proof != null
? null
: (final ProofType? proofType) =>
model.proofType = proofType!,
),
),
)
.toList(),
Icon(ProofType.receipt.getIcon()),
const SizedBox(width: 8),
Expanded(
child: Text(
appLocalizations.prices_proof_receipt,
maxLines: 2,
),
),
],
),
),
SizedBox(
width: constraints.maxWidth / 2,
child: Row(
children: [
Radio<ProofType>(
value: ProofType.priceTag,
groupValue: model.proofType,
onChanged: model.proof != null
? null
: (final ProofType? proofType) =>
model.proofType = proofType!,
),
Icon(ProofType.priceTag.getIcon()),
const SizedBox(width: 8),
Expanded(
child: Text(
appLocalizations.prices_proof_price_tag,
maxLines: 2,
),
),
],
),
),
],
),
),
],
Expand All @@ -143,18 +158,6 @@ enum _ProofSource {
gallery,
history;

String getTitle(final AppLocalizations appLocalizations) => switch (this) {
_ProofSource.camera => appLocalizations.settings_app_camera,
_ProofSource.gallery => appLocalizations.gallery_source_label,
_ProofSource.history => appLocalizations.user_search_proofs_title,
};

IconData getIconData() => switch (this) {
_ProofSource.camera => Icons.camera_rounded,
_ProofSource.gallery => Icons.perm_media_rounded,
_ProofSource.history => Icons.document_scanner_rounded,
};

Future<void> process(
final BuildContext context,
final PriceModel model,
Expand Down Expand Up @@ -189,40 +192,29 @@ enum _ProofSource {
}
}

static List<_ProofSource> getPossibleProofSources({
required final bool includeMyProofs,
}) {
final List<_ProofSource> result = <_ProofSource>[];
final bool hasCamera = CameraHelper.hasACamera;
if (hasCamera) {
result.add(_ProofSource.camera);
}
result.add(_ProofSource.gallery);
if (includeMyProofs) {
result.add(_ProofSource.history);
}
return result;
}

static Future<_ProofSource?> select(
final BuildContext context, {
required final List<_ProofSource> sources,
}) async {
static Future<_ProofSource?> select(final BuildContext context) async {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please stick to the previous code (especially as you've removed bug fixes).
Besides, _ProofSource has nothing to do with the current PR, therefore I wouldn't expect reviewing that code.
Unless there's a good reason.

final AppLocalizations appLocalizations = AppLocalizations.of(context);
final bool hasCamera = CameraHelper.hasACamera;

return showSmoothListOfChoicesModalSheet<_ProofSource>(
context: context,
title: appLocalizations.prices_proof_find,
labels: sources.map<String>(
(_ProofSource source) => source.getTitle(appLocalizations),
),
prefixIcons: sources
.map<Widget>(
(_ProofSource source) => Icon(source.getIconData()),
)
.toList(),
labels: <String>[
if (hasCamera) appLocalizations.settings_app_camera,
appLocalizations.gallery_source_label,
appLocalizations.user_search_proofs_title,
],
prefixIcons: <Widget>[
if (hasCamera) const Icon(Icons.camera_rounded),
const Icon(Icons.perm_media_rounded),
const Icon(Icons.document_scanner_rounded),
],
addEndArrowToItems: true,
values: sources,
values: <_ProofSource>[
_ProofSource.camera,
_ProofSource.gallery,
_ProofSource.history,
],
);
}
}
10 changes: 10 additions & 0 deletions packages/smooth_app/lib/pages/prices/proof_type_extensions.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:openfoodfacts/openfoodfacts.dart';

Expand All @@ -11,4 +12,13 @@ extension ProofTypeExtension on ProofType {
// not used for the moment
ProofType.shopImport => 'Shop import',
};

IconData getIcon() => switch (this) {
ProofType.receipt => Icons.receipt_long,
ProofType.priceTag => Icons.local_offer,
// TODO: Handle this case.
ProofType.gdprRequest => throw UnimplementedError(),
// TODO: Handle this case.
ProofType.shopImport => throw UnimplementedError(),
};
}
44 changes: 0 additions & 44 deletions packages/smooth_app/macos/Flutter/GeneratedPluginRegistrant.swift

This file was deleted.

Loading
Loading