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: knowledgePanels are now loaded with the other product fields #1691

Merged
merged 1 commit into from
Apr 28, 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
33 changes: 0 additions & 33 deletions packages/smooth_app/lib/database/knowledge_panels_query.dart

This file was deleted.

1 change: 1 addition & 0 deletions packages/smooth_app/lib/database/product_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ abstract class ProductQuery {
ProductField.ECOSCORE_DATA,
ProductField.ECOSCORE_GRADE,
ProductField.ECOSCORE_SCORE,
ProductField.KNOWLEDGE_PANELS,
];

Future<SearchResult> getSearchResult();
Expand Down
63 changes: 15 additions & 48 deletions packages/smooth_app/lib/pages/product/new_product_page.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:openfoodfacts/model/KnowledgePanels.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:provider/provider.dart';
import 'package:smooth_app/cards/product_cards/knowledge_panels/knowledge_panels_builder.dart';
Expand All @@ -11,7 +10,6 @@ import 'package:smooth_app/data_models/product_list.dart';
import 'package:smooth_app/data_models/product_preferences.dart';
import 'package:smooth_app/data_models/user_preferences.dart';
import 'package:smooth_app/database/dao_product_list.dart';
import 'package:smooth_app/database/knowledge_panels_query.dart';
import 'package:smooth_app/database/local_database.dart';
import 'package:smooth_app/database/product_query.dart';
import 'package:smooth_app/generic_lib/buttons/smooth_action_button.dart';
Expand Down Expand Up @@ -225,52 +223,21 @@ class _ProductPageState extends State<ProductPage> {
);
}

FutureBuilder<KnowledgePanels> _buildKnowledgePanelCards() {
// Note that this will make a new request on every rebuild.
// TODO(jasmeet): Avoid additional requests on rebuilds.
final Future<KnowledgePanels> knowledgePanels = KnowledgePanelsQuery(
barcode: _product.barcode!,
).getKnowledgePanels();
return FutureBuilder<KnowledgePanels>(
future: knowledgePanels,
builder:
(BuildContext context, AsyncSnapshot<KnowledgePanels> snapshot) {
List<Widget> knowledgePanelWidgets = <Widget>[];
if (snapshot.hasData) {
// Render all KnowledgePanels
knowledgePanelWidgets = KnowledgePanelsBuilder(
setState: () => setState(() {}),
refreshProductCallback: _refreshProduct,
).buildAll(
snapshot.data!,
context: context,
product: _product,
);
} else if (snapshot.hasError) {
// TODO(jasmeet): Retry the request.
// Do nothing for now.
} else {
// Query results not available yet.
knowledgePanelWidgets = <Widget>[_buildLoadingWidget()];
}
return KnowledgePanelProductCards(knowledgePanelWidgets);
});
}

Widget _buildLoadingWidget() {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: const <Widget>[
SizedBox(
child: CircularProgressIndicator(),
width: 60,
height: 60,
),
],
),
);
Widget _buildKnowledgePanelCards() {
final List<Widget> knowledgePanelWidgets;
if (_product.knowledgePanels == null) {
knowledgePanelWidgets = <Widget>[];
} else {
knowledgePanelWidgets = KnowledgePanelsBuilder(
setState: () => setState(() {}),
refreshProductCallback: _refreshProduct,
).buildAll(
_product.knowledgePanels!,
context: context,
product: _product,
);
}
return KnowledgePanelProductCards(knowledgePanelWidgets);
}

Future<void> _editList() async {
Expand Down