Created
March 9, 2022 22:49
-
-
Save rodydavis/44a95a38e44aaa7250dc39e3c6e84099 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