Skip to content

Instantly share code, notes, and snippets.

@Nash0x7E2
Last active January 17, 2019 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nash0x7E2/76cac009b5e79f9d13d96ffa948f4236 to your computer and use it in GitHub Desktop.
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
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