Skip to content

Instantly share code, notes, and snippets.

@pskink
Created January 9, 2020 09:45
Show Gist options
  • Save pskink/e1026422c2a2c37df60e2b750656a0dc to your computer and use it in GitHub Desktop.
Save pskink/e1026422c2a2c37df60e2b750656a0dc to your computer and use it in GitHub Desktop.
class RoundedListView extends StatefulWidget {
@override
_RoundedListViewState createState() => _RoundedListViewState();
}
class _RoundedListViewState extends State<RoundedListView> with TickerProviderStateMixin {
var size = 32;
@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: size,
itemBuilder: (BuildContext context, int index) {
AnimationController ctrl = AnimationController(duration: Duration(milliseconds: 200), vsync: this);
Animation scaleAnimation = Tween(begin: 1.0, end: 0.9).animate(ctrl);
selectItem(bool forward) => forward? ctrl.forward() : ctrl.reverse();
return ScaleTransition(
scale: scaleAnimation,
child: Card(
clipBehavior: Clip.antiAlias,
margin: EdgeInsets.fromLTRB(2.0, index == 0? 2.0 : 0.0, 2.0, index == size - 1? 8.0 : 1.0),
elevation: 4.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
top: Radius.circular(index == 0? 24 : 0),
bottom: Radius.circular(index == size - 1? 24 : 0),
),
),
child: InkWell(
splashColor: Colors.orange,
highlightColor: Colors.transparent,
onTapDown: (d) => selectItem(true),
onTapCancel: () => selectItem(false),
onTap: () => selectItem(false),
child: ListTile(title: Text('item #$index')),
),
),
);
},
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment