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: 4628 - refactoring as preparatory work #4641

Merged
merged 7 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
25 changes: 12 additions & 13 deletions packages/smooth_app/lib/helpers/product_cards_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,18 @@ Widget buildProductSmoothCard({
EdgeInsets? margin = const EdgeInsets.symmetric(
horizontal: SMALL_SPACE,
),
}) {
return SmoothCard(
margin: margin,
padding: padding,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
if (header != null) header,
body,
],
),
);
}
}) =>
SmoothCard(
margin: margin,
padding: padding,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
if (header != null) header,
body,
],
),
);

// used to be in now defunct `AttributeListExpandable`
List<Attribute> getPopulatedAttributes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:smooth_app/data_models/preferences/user_preferences.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/knowledge_panel/knowledge_panels/knowledge_panel_expanded_card.dart';
import 'package:smooth_app/knowledge_panel/knowledge_panels/knowledge_panel_page.dart';
import 'package:smooth_app/knowledge_panel/knowledge_panels/knowledge_panel_summary_card.dart';
import 'package:smooth_app/knowledge_panel/knowledge_panels_builder.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';

Expand All @@ -28,12 +27,11 @@ class KnowledgePanelCard extends StatelessWidget {
Widget build(BuildContext context) {
final UserPreferences userPreferences = context.watch<UserPreferences>();
final KnowledgePanel? panel =
KnowledgePanelWidget.getKnowledgePanel(product, panelId);
KnowledgePanelsBuilder.getKnowledgePanel(product, panelId);
if (panel == null) {
return EMPTY_WIDGET;
}
if (_isExpandedByUser(panel, userPreferences) ||
(panel.expanded ?? false)) {
if (_isExpandedByUser(panel, userPreferences) || (panel.expanded == true)) {
return KnowledgePanelExpandedCard(
panelId: panelId,
product: product,
Expand All @@ -45,28 +43,23 @@ class KnowledgePanelCard extends StatelessWidget {
padding: const EdgeInsets.symmetric(vertical: SMALL_SPACE),
child: InkWell(
borderRadius: ANGULAR_BORDER_RADIUS,
child: KnowledgePanelSummaryCard(
child: KnowledgePanelsBuilder.getPanelSummaryWidget(
panel,
isClickable: true,
margin: EdgeInsets.zero,
),
onTap: () {
final Brightness? brightness =
SmoothBrightnessOverride.of(context)?.brightness;

Navigator.push<Widget>(
context,
MaterialPageRoute<Widget>(
builder: (BuildContext context) => SmoothBrightnessOverride(
brightness: brightness,
child: KnowledgePanelPage(
panelId: panelId,
product: product,
),
onTap: () async => Navigator.push<Widget>(
context,
MaterialPageRoute<Widget>(
builder: (BuildContext context) => SmoothBrightnessOverride(
brightness: SmoothBrightnessOverride.of(context)?.brightness,
child: KnowledgePanelPage(
panelId: panelId,
product: product,
),
),
);
},
),
),
),
);
}
Expand All @@ -82,7 +75,7 @@ class KnowledgePanelCard extends StatelessWidget {
for (final String panelId in expandedPanelIds) {
if (panel.titleElement != null &&
panel.titleElement!.title ==
KnowledgePanelWidget.getKnowledgePanel(product, panelId)
KnowledgePanelsBuilder.getKnowledgePanel(product, panelId)
?.titleElement
?.title) {
if (userPreferences.getFlag(getExpandFlagTag(panelId)) ?? false) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import 'package:flutter/material.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/knowledge_panel/knowledge_panels/knowledge_panel_element_card.dart';
import 'package:smooth_app/knowledge_panel/knowledge_panels/knowledge_panel_summary_card.dart';
import 'package:smooth_app/knowledge_panel/knowledge_panels_builder.dart';

class KnowledgePanelExpandedCard extends StatelessWidget {
Expand All @@ -19,21 +17,31 @@ class KnowledgePanelExpandedCard extends StatelessWidget {
@override
Widget build(BuildContext context) {
final KnowledgePanel panel =
KnowledgePanelWidget.getKnowledgePanel(product, panelId)!;
KnowledgePanelsBuilder.getKnowledgePanel(product, panelId)!;
final List<Widget> elementWidgets = <Widget>[];
elementWidgets.add(KnowledgePanelSummaryCard(panel, isClickable: false));
for (final KnowledgePanelElement element
in panel.elements ?? <KnowledgePanelElement>[]) {
elementWidgets.add(
Padding(
padding: const EdgeInsetsDirectional.only(top: VERY_SMALL_SPACE),
child: KnowledgePanelElementCard(
knowledgePanelElement: element,
product: product,
isInitiallyExpanded: isInitiallyExpanded,
),
),
);
final Widget? summary = KnowledgePanelsBuilder.getPanelSummaryWidget(
panel,
isClickable: false,
);
if (summary != null) {
elementWidgets.add(summary);
}
if (panel.elements != null) {
for (final KnowledgePanelElement element in panel.elements!) {
final Widget? elementWidget = KnowledgePanelsBuilder.getElementWidget(
knowledgePanelElement: element,
product: product,
isInitiallyExpanded: isInitiallyExpanded,
);
if (elementWidget != null) {
elementWidgets.add(
Padding(
padding: const EdgeInsetsDirectional.only(top: VERY_SMALL_SPACE),
child: elementWidget,
),
);
}
}
}
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'package:flutter/material.dart';
import 'package:openfoodfacts/openfoodfacts.dart';

/// Card that displays a Knowledge Panel _Image_ element.
class KnowledgePanelImageCard extends StatelessWidget {
const KnowledgePanelImageCard({
required this.imageElement,
});

final KnowledgePanelImageElement imageElement;

@override
Widget build(BuildContext context) => Image.network(
imageElement.url,
g123k marked this conversation as resolved.
Show resolved Hide resolved
width: imageElement.width?.toDouble(),
height: imageElement.height?.toDouble(),
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:smooth_app/pages/product/common/product_refresher.dart';
import 'package:smooth_app/widgets/smooth_app_bar.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';

/// Detail page of knowledge panels (if you click on the forward/more button).
class KnowledgePanelPage extends StatefulWidget {
const KnowledgePanelPage({
required this.panelId,
Expand Down Expand Up @@ -116,7 +117,7 @@ class _KnowledgePanelPageState extends State<KnowledgePanelPage>
groupElement?.title!.isNotEmpty == true) {
return groupElement!.title!;
}
final KnowledgePanel? panel = KnowledgePanelWidget.getKnowledgePanel(
final KnowledgePanel? panel = KnowledgePanelsBuilder.getKnowledgePanel(
upToDateProduct,
widget.panelId,
);
Expand Down
Loading