Skip to content

Instantly share code, notes, and snippets.



Last active Jan 17, 2019
What would you like to do?
A card with the option to change the shadow color and animation duration of the default card
class ShadowCard extends StatelessWidget {
const ShadowCard({
Key key,
this.elevation = 1.0,
this.margin = const EdgeInsets.all(4.0),
this.clipBehavior = Clip.none,
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;
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