-
-
Notifications
You must be signed in to change notification settings - Fork 380
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
Changes from all commits
eedb630
db1f5ec
9df5045
9804cd2
3caf9ef
b5ef09c
390257b
5fa1dc4
fb61397
26fe393
8706ee5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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; | ||||||
} | ||||||
|
@@ -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>[ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You've rolled back the previous code. |
||||||
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!, | ||||||
Comment on lines
+108
to
+111
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It appears the Was it intentional to remove the disabling effect of |
||||||
), | ||||||
), | ||||||
) | ||||||
.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, | ||||||
), | ||||||
), | ||||||
], | ||||||
Comment on lines
+103
to
+144
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] The layout for Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
), | ||||||
), | ||||||
], | ||||||
Comment on lines
+100
to
+147
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The UI structure for displaying the Could we consider refactoring this into a reusable widget or a helper method? For example, a method like |
||||||
), | ||||||
), | ||||||
], | ||||||
|
@@ -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, | ||||||
|
@@ -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 { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). |
||||||
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, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
_ProofSource.gallery, | ||||||
_ProofSource.history, | ||||||
], | ||||||
); | ||||||
} | ||||||
} |
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'; | ||||||||||||||
|
||||||||||||||
|
@@ -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(), | ||||||||||||||
vinay769 marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+19
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] The
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||
}; | ||||||||||||||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic for selecting a
_ProofSource
has been simplified. Previously,_ProofSource.getPossibleProofSources
(which accepted anincludeMyProofs
parameter) was used to determine the available sources. This method has been removed (Diff 4), and_ProofSource.select
now seems to always include_ProofSource.history
as an option.If
includeMyProofs
was previouslyfalse
in some scenarios, this would mean the 'history' option wasn't available. Is it intended for the 'history' option to always be present now, regardless of the context whereincludeMyProofs
might have been used?