forked from openfoodfacts/smooth-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: openfoodfacts#2396 - preparatory step with simple refactoring (o…
…penfoodfacts#2593) New files: * `smooth_product_card_template.dart`: Empty template for a product card display. * `smooth_product_image_container.dart`: Container to display the main product image on a product card. Impacted files: * `smooth_product_card_found.dart`: fix as `backgroundColor` was not taken into account anymore * `smooth_product_image.dart`: refactored with new class `SmoothImageContainer`
- Loading branch information
1 parent
2311867
commit 27681d1
Showing
4 changed files
with
134 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
packages/smooth_app/lib/cards/product_cards/smooth_product_card_template.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:smooth_app/cards/product_cards/smooth_product_card_found.dart'; | ||
import 'package:smooth_app/generic_lib/design_constants.dart'; | ||
import 'package:smooth_app/generic_lib/widgets/smooth_card.dart'; | ||
import 'package:smooth_app/generic_lib/widgets/smooth_product_image_container.dart'; | ||
import 'package:smooth_app/helpers/ui_helpers.dart'; | ||
|
||
/// Empty template for a product card display. | ||
/// | ||
/// Based on the "real" [SmoothProductCardFound]. | ||
class SmoothProductCardTemplate extends StatelessWidget { | ||
const SmoothProductCardTemplate(); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final Size screenSize = MediaQuery.of(context).size; | ||
final ThemeData themeData = Theme.of(context); | ||
final bool isDarkMode = themeData.colorScheme.brightness == Brightness.dark; | ||
final Color itemColor = isDarkMode ? PRIMARY_GREY_COLOR : LIGHT_GREY_COLOR; | ||
final Color backgroundColor = isDarkMode ? Colors.black : Colors.white; | ||
final double iconSize = IconWidgetSizer.getIconSizeFromContext(context); | ||
final Widget textWidget = Container( | ||
width: screenSize.width * .4, | ||
height: screenSize.width * .05, | ||
color: itemColor, | ||
); | ||
// In the actual display, it's a 240x130 svg resized with iconSize | ||
final Widget svgWidget = Container( | ||
height: iconSize * .9, | ||
width: 240 * iconSize / 130, | ||
color: itemColor, | ||
); | ||
return Container( | ||
decoration: BoxDecoration( | ||
borderRadius: ROUNDED_BORDER_RADIUS, | ||
color: backgroundColor, | ||
), | ||
child: SmoothCard( | ||
elevation: SmoothProductCardFound.elevation, | ||
color: Colors.transparent, | ||
padding: const EdgeInsets.all(VERY_SMALL_SPACE), | ||
child: Row( | ||
children: <Widget>[ | ||
SmoothProductImageContainer( | ||
width: screenSize.width * 0.20, | ||
height: screenSize.width * 0.20, | ||
child: Container(color: itemColor), | ||
), | ||
const Padding(padding: EdgeInsets.only(left: VERY_SMALL_SPACE)), | ||
Expanded( | ||
child: SizedBox( | ||
height: screenSize.width * 0.2, | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: <Widget>[ | ||
textWidget, | ||
textWidget, | ||
textWidget, | ||
], | ||
), | ||
), | ||
), | ||
const Padding(padding: EdgeInsets.only(left: VERY_SMALL_SPACE)), | ||
Padding( | ||
padding: const EdgeInsets.all(VERY_SMALL_SPACE), | ||
child: Column( | ||
children: <Widget>[ | ||
svgWidget, | ||
Container(height: iconSize * .2), | ||
svgWidget, | ||
], | ||
), | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
packages/smooth_app/lib/generic_lib/widgets/smooth_product_image_container.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:smooth_app/generic_lib/design_constants.dart'; | ||
|
||
/// Container to display the main product image on a product card. | ||
class SmoothProductImageContainer extends StatelessWidget { | ||
const SmoothProductImageContainer({ | ||
required this.height, | ||
required this.width, | ||
required this.child, | ||
}); | ||
|
||
final double height; | ||
final double width; | ||
final Widget child; | ||
|
||
@override | ||
Widget build(BuildContext context) => ClipRRect( | ||
borderRadius: ROUNDED_BORDER_RADIUS, | ||
child: SizedBox( | ||
width: width, | ||
height: height, | ||
child: child, | ||
), | ||
); | ||
} |