Last active
January 17, 2019 19:11
-
-
Save Nash0x7E2/76cac009b5e79f9d13d96ffa948f4236 to your computer and use it in GitHub Desktop.
A card with the option to change the shadow color and animation duration of the default card
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
class ShadowCard extends StatelessWidget { | |
const ShadowCard({ | |
Key key, | |
this.color, | |
this.elevation = 1.0, | |
this.shape, | |
this.margin = const EdgeInsets.all(4.0), | |
this.clipBehavior = Clip.none, | |
this.child, | |
this.semanticContainer = true, | |
this.shadowColor = Colors.grey, | |
this.animationDuration = kThemeChangeDuration, | |
}) : assert(elevation != null && elevation >= 0.0), | |
super(key: key); | |
final Color color; | |
final double elevation; | |
final ShapeBorder shape; | |
final Clip clipBehavior; | |
final EdgeInsetsGeometry margin; | |
final bool semanticContainer; | |
final Color shadowColor; | |
final Duration animationDuration; | |
final Widget child; | |
@override | |
Widget build(BuildContext context) { | |
return Semantics( | |
container: semanticContainer, | |
explicitChildNodes: !semanticContainer, | |
child: Container( | |
margin: margin ?? const EdgeInsets.all(4.0), | |
child: Material( | |
animationDuration: animationDuration, | |
type: MaterialType.card, | |
color: color ?? Theme.of(context).cardColor, | |
elevation: elevation, | |
shadowColor: shadowColor, | |
shape: shape ?? const RoundedRectangleBorder( | |
borderRadius: BorderRadius.all(Radius.circular(4.0)), | |
), | |
clipBehavior: clipBehavior, | |
child: child, | |
), | |
), | |
); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment