Skip to content

Instantly share code, notes, and snippets.

@Nash0x7E2

Nash0x7E2/shadow-card.dart

Last active Jan 17, 2019
Embed
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.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