-
-
Save samuelematias/20e4f7b579366fbca138e32d2c62291f to your computer and use it in GitHub Desktop.
Flutter Material Outlined Card
This file contains hidden or 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
import 'package:flutter/material.dart'; | |
class OutlinedCard extends StatefulWidget { | |
const OutlinedCard({ | |
Key? key, | |
required this.child, | |
}) : super(key: key); | |
final Widget child; | |
@override | |
State<OutlinedCard> createState() => _OutlinedCardState(); | |
} | |
class _OutlinedCardState extends State<OutlinedCard> { | |
bool _hovered = false; | |
@override | |
Widget build(BuildContext context) { | |
final borderRadius = BorderRadius.circular(_hovered ? 20 : 8); | |
const animationCurve = Curves.easeInOut; | |
return MouseRegion( | |
onEnter: (_) { | |
setState(() { | |
_hovered = true; | |
}); | |
}, | |
onExit: (_) { | |
setState(() { | |
_hovered = false; | |
}); | |
}, | |
cursor: SystemMouseCursors.click, | |
child: AnimatedContainer( | |
duration: kThemeAnimationDuration, | |
curve: animationCurve, | |
decoration: BoxDecoration( | |
border: Border.all( | |
color: Theme.of(context).colorScheme.outline, | |
width: 1, | |
), | |
borderRadius: borderRadius, | |
), | |
child: TweenAnimationBuilder<BorderRadius>( | |
duration: kThemeAnimationDuration, | |
curve: animationCurve, | |
tween: Tween(begin: BorderRadius.zero, end: borderRadius), | |
builder: (context, borderRadius, child) => ClipRRect( | |
clipBehavior: Clip.antiAlias, | |
borderRadius: borderRadius, | |
child: child, | |
), | |
child: widget.child, | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment