1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-08 13:58:47 +00:00

Landing beta changes in master for the new stable release (#747)

This commit is contained in:
Andrew Brogdon
2021-03-03 11:44:35 -08:00
committed by GitHub
parent 6c81510d6e
commit 8c1cd0b049
101 changed files with 1006 additions and 1040 deletions

View File

@@ -14,23 +14,31 @@ class AnimatedListDemo extends StatefulWidget {
class _AnimatedListDemoState extends State<AnimatedListDemo> {
final GlobalKey<AnimatedListState> _listKey = GlobalKey();
final listData = initialListData;
final listData = [
UserModel(0, 'Govind', 'Dixit'),
UserModel(1, 'Greta', 'Stoll'),
UserModel(2, 'Monty', 'Carlo'),
UserModel(3, 'Petey', 'Cruiser'),
UserModel(4, 'Barry', 'Cade'),
];
final initialListSize = 5;
void addUser() {
setState(() {
var index = listData.length;
listData.add(
UserModel(firstName: 'New', lastName: 'Person'),
UserModel(++_maxIdValue, 'New', 'Person'),
);
_listKey.currentState
_listKey.currentState!
.insertItem(index, duration: Duration(milliseconds: 300));
});
}
void deleteUser(int index) {
void deleteUser(int id) {
setState(() {
final index = listData.indexWhere((u) => u.id == id);
var user = listData.removeAt(index);
_listKey.currentState.removeItem(
_listKey.currentState!.removeItem(
index,
(context, animation) {
return FadeTransition(
@@ -49,7 +57,7 @@ class _AnimatedListDemoState extends State<AnimatedListDemo> {
});
}
Widget _buildItem(UserModel user, [int index]) {
Widget _buildItem(UserModel user) {
return ListTile(
key: ValueKey<UserModel>(user),
title: Text(user.firstName),
@@ -59,7 +67,7 @@ class _AnimatedListDemoState extends State<AnimatedListDemo> {
),
trailing: IconButton(
icon: Icon(Icons.delete),
onPressed: () => deleteUser(index),
onPressed: () => deleteUser(user.id),
),
);
}
@@ -79,11 +87,11 @@ class _AnimatedListDemoState extends State<AnimatedListDemo> {
body: SafeArea(
child: AnimatedList(
key: _listKey,
initialItemCount: initialListData.length,
initialItemCount: 5,
itemBuilder: (context, index, animation) {
return FadeTransition(
opacity: animation,
child: _buildItem(listData[index], index),
child: _buildItem(listData[index]),
);
},
),
@@ -93,31 +101,15 @@ class _AnimatedListDemoState extends State<AnimatedListDemo> {
}
class UserModel {
const UserModel({this.firstName, this.lastName});
UserModel(
this.id,
this.firstName,
this.lastName,
);
final int id;
final String firstName;
final String lastName;
}
List<UserModel> initialListData = [
UserModel(
firstName: 'Govind',
lastName: 'Dixit',
),
UserModel(
firstName: 'Greta',
lastName: 'Stoll',
),
UserModel(
firstName: 'Monty',
lastName: 'Carlo',
),
UserModel(
firstName: 'Petey',
lastName: 'Cruiser',
),
UserModel(
firstName: 'Barry',
lastName: 'Cade',
),
];
int _maxIdValue = 4;