-
-
Notifications
You must be signed in to change notification settings - Fork 287
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: #2396 - new widget SmoothProductCardTemplate #2593
Changes from all commits
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 |
---|---|---|
@@ -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, | ||
Comment on lines
+29
to
+30
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. I guess you took these values from the original card. We should store them in a const 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. Fair enough, but I don't know how to do that cleanly. You see, the 240x130 ratio comes from the svg files themselves. |
||
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, | ||
], | ||
), | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
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, | ||
), | ||
); | ||
} |
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.
Some magic numbers, what happenes when someone changes the font size
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.
I don't care about the font size, I just want 3 lines that fit in
width * .2
as in the original card.