-
-
Save Nash0x7E2/a1cb604177ad82c6a5c86f0c9442ac1f to your computer and use it in GitHub Desktop.
This file contains 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'; | |
void main() { | |
runApp( | |
MaterialApp( | |
home: AnimatedListDemo(), | |
), | |
); | |
} | |
class UserModel { | |
UserModel({this.firstName, this.lastName, this.profileImageUrl}); | |
String firstName; | |
String lastName; | |
String profileImageUrl; | |
} | |
List<UserModel> listData = [ | |
UserModel( | |
firstName: "Nash", | |
lastName: "Ramdial", | |
profileImageUrl: | |
"https://pbs.twimg.com/profile_images/1035253589894197256/qNuF8w6e_400x400.jpg", | |
), | |
UserModel( | |
firstName: "Scott", | |
lastName: "Stoll", | |
profileImageUrl: | |
"https://pbs.twimg.com/profile_images/997431887286030336/QinQPXjS_400x400.jpg", | |
), | |
UserModel( | |
firstName: "Simon", | |
lastName: "Lightfoot", | |
profileImageUrl: | |
"https://pbs.twimg.com/profile_images/1017532253394624513/LgFqlJ4U_400x400.jpg", | |
), | |
UserModel( | |
firstName: "Jay", | |
lastName: "Meijer", | |
profileImageUrl: | |
"https://pbs.twimg.com/profile_images/1000361976361611264/Ty8LbTKx_400x400.jpg", | |
), | |
UserModel( | |
firstName: "Mariano", | |
lastName: "Zorrilla", | |
profileImageUrl: | |
"https://ca.slack-edge.com/TADUGCD9D-UC5F6HJ6T-gfbe5883d03f-1024", | |
), | |
]; | |
class AnimatedListDemo extends StatefulWidget { | |
_AnimatedListDemoState createState() => _AnimatedListDemoState(); | |
} | |
class _AnimatedListDemoState extends State<AnimatedListDemo> { | |
final GlobalKey<AnimatedListState> _listKey = GlobalKey(); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text("Animated List Demo"), | |
centerTitle: true, | |
leading: IconButton( | |
icon: Icon(Icons.add), | |
onPressed: (){ | |
//TODO: Add user | |
}, | |
), | |
), | |
), | |
body: SafeArea( | |
child: AnimatedList( | |
key: _listKey, | |
initialItemCount: listData.length, | |
itemBuilder: (BuildContext context, int index, Animation animation) { | |
return FadeTransition( | |
opacity: animation, | |
child: ListTile( | |
title: Text(listData[index].firstName), | |
subtitle: Text(listData[index].lastName), | |
leading: CircleAvatar( | |
backgroundImage: | |
NetworkImage(listData[index].profileImageUrl), | |
), | |
onLongPress: () { | |
//TODO: Delete user | |
}, | |
), | |
); | |
}, | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment