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: minor improvement for summary_card #1474

Merged
merged 1 commit into from
Apr 3, 2022
Merged
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
67 changes: 30 additions & 37 deletions packages/smooth_app/lib/pages/product/summary_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,10 @@ class _SummaryCardState extends State<SummaryCard> {
void initState() {
super.initState();
if (widget.showUnansweredQuestions) {
loadProductQuestions();
_loadProductQuestions();
}
}

Future<void> loadProductQuestions() async {
_productQuestions = RobotoffQuestionsQuery(widget._product.barcode!)
.getRobotoffQuestionsForProduct();
}

@override
Widget build(BuildContext context) {
return LayoutBuilder(
Expand Down Expand Up @@ -141,10 +136,7 @@ class _SummaryCardState extends State<SummaryCard> {
child: Center(
child: Text(
AppLocalizations.of(context)!.tab_for_more,
style: Theme.of(context)
.textTheme
.bodyText1!
.apply(color: Colors.lightBlue),
style: Theme.of(context).primaryTextTheme.bodyText1,
),
),
),
Expand All @@ -156,7 +148,7 @@ class _SummaryCardState extends State<SummaryCard> {

Widget _buildSummaryCardContent(BuildContext context) {
final LocalDatabase localDatabase = context.read<LocalDatabase>();
final AppLocalizations appLocalizations = AppLocalizations.of(context)!;
final AppLocalizations localizations = AppLocalizations.of(context)!;
final List<Attribute> scoreAttributes =
getPopulatedAttributes(widget._product, SCORE_ATTRIBUTE_IDS);

Expand Down Expand Up @@ -235,6 +227,8 @@ class _SummaryCardState extends State<SummaryCard> {
.categoriesTagsInLanguages![ProductQuery.getLanguage()!]!.last;
}
}
final List<String> statesTags =
widget._product.statesTags ?? List<String>.empty();
return Column(
children: <Widget>[
ProductTitleCard(widget._product, widget.isFullVersion),
Expand All @@ -247,15 +241,13 @@ class _SummaryCardState extends State<SummaryCard> {
),
_buildProductQuestionsWidget(),
attributesContainer,
if (widget._product.statesTags
?.contains('en:categories-to-be-completed') ??
false)
addPanelButton(appLocalizations.score_add_missing_product_category,
onPressed: () {}),
if (statesTags.contains('en:categories-to-be-completed'))
addPanelButton(localizations.score_add_missing_product_category,
onPressed: () => _showNotImplemented(context)),
if (widget.isFullVersion)
if (categoryTag != null && categoryLabel != null)
addPanelButton(
appLocalizations.product_search_same_category,
localizations.product_search_same_category,
iconData: Icons.leaderboard,
onPressed: () async => ProductQueryPageHelper().openBestChoice(
color: Colors.deepPurple,
Expand All @@ -269,26 +261,24 @@ class _SummaryCardState extends State<SummaryCard> {
context: context,
),
),
if ((widget._product.statesTags
?.contains('en:product-name-to-be-completed') ??
false) ||
(widget._product.statesTags
?.contains('en:quantity-to-be-completed') ??
false))
if ((statesTags.contains('en:product-name-to-be-completed')) ||
(statesTags.contains('en:quantity-to-be-completed')))
addPanelButton(
'Complete basic details', // TODO(vik4114): localization
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Not implemented yet'),
duration: Duration(seconds: 2),
),
);
}),
onPressed: () => _showNotImplemented(context)),
],
);
}

void _showNotImplemented(BuildContext context) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Not implemented yet'),
duration: Duration(seconds: 2),
),
);
}

Widget _buildProductCompatibilityHeader(BuildContext context) {
final MatchedProduct matchedProduct = MatchedProduct.getMatchedProduct(
widget._product,
Expand Down Expand Up @@ -476,7 +466,7 @@ class _SummaryCardState extends State<SummaryCard> {
builder: (BuildContext context) => QuestionCard(
product: widget._product,
questions: questions,
updateProductUponAnswers: updateProductUponAnswers,
updateProductUponAnswers: _updateProductUponAnswers,
),
),
);
Expand Down Expand Up @@ -514,14 +504,17 @@ class _SummaryCardState extends State<SummaryCard> {
});
}

Future<void> updateProductUponAnswers() async {
Future<void> _updateProductUponAnswers() async {
// Reload the product questions, they might have been answered.
// Or the backend may have new ones.
await loadProductQuestions();
await _loadProductQuestions();
// Reload the product as it may have been updated because of the
// new answers.
if (widget.refreshProductCallback != null) {
widget.refreshProductCallback!(context);
}
widget.refreshProductCallback?.call(context);
}

Future<void> _loadProductQuestions() async {
_productQuestions = RobotoffQuestionsQuery(widget._product.barcode!)
.getRobotoffQuestionsForProduct();
}
}