Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
acf102be
Commit
acf102be
authored
Apr 28, 2017
by
Hans Muller
Committed by
GitHub
Apr 28, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
AnimatedList (#9649)
parent
67169043
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
550 additions
and
0 deletions
+550
-0
animated_list.dart
packages/flutter/lib/src/widgets/animated_list.dart
+373
-0
widgets.dart
packages/flutter/lib/widgets.dart
+1
-0
animated_list_test.dart
packages/flutter/test/widgets/animated_list_test.dart
+176
-0
No files found.
packages/flutter/lib/src/widgets/animated_list.dart
0 → 100644
View file @
acf102be
This diff is collapsed.
Click to expand it.
packages/flutter/lib/widgets.dart
View file @
acf102be
...
...
@@ -10,6 +10,7 @@ library widgets;
export
'package:vector_math/vector_math_64.dart'
show
Matrix4
;
export
'src/widgets/animated_cross_fade.dart'
;
export
'src/widgets/animated_list.dart'
;
export
'src/widgets/animated_size.dart'
;
export
'src/widgets/app.dart'
;
export
'src/widgets/async.dart'
;
...
...
packages/flutter/test/widgets/animated_list_test.dart
0 → 100644
View file @
acf102be
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:flutter_test/flutter_test.dart'
;
import
'package:flutter/widgets.dart'
;
void
main
(
)
{
testWidgets
(
'AnimatedList initialItemCount'
,
(
WidgetTester
tester
)
async
{
final
Map
<
int
,
Animation
<
double
>>
animations
=
<
int
,
Animation
<
double
>>{};
await
tester
.
pumpWidget
(
new
AnimatedList
(
initialItemCount:
2
,
itemBuilder:
(
BuildContext
context
,
int
index
,
Animation
<
double
>
animation
)
{
animations
[
index
]
=
animation
;
return
new
SizedBox
(
height:
100.0
,
child:
new
Center
(
child:
new
Text
(
'item
$index
'
),
),
);
},
),
);
expect
(
find
.
text
(
'item 0'
),
findsOneWidget
);
expect
(
find
.
text
(
'item 1'
),
findsOneWidget
);
expect
(
animations
.
containsKey
(
0
),
true
);
expect
(
animations
.
containsKey
(
1
),
true
);
expect
(
animations
[
0
].
value
,
1.0
);
expect
(
animations
[
1
].
value
,
1.0
);
});
testWidgets
(
'AnimatedList insert'
,
(
WidgetTester
tester
)
async
{
final
GlobalKey
<
AnimatedListState
>
listKey
=
new
GlobalKey
<
AnimatedListState
>();
await
tester
.
pumpWidget
(
new
AnimatedList
(
key:
listKey
,
itemBuilder:
(
BuildContext
context
,
int
index
,
Animation
<
double
>
animation
)
{
return
new
SizeTransition
(
key:
new
ValueKey
<
int
>(
index
),
axis:
Axis
.
vertical
,
sizeFactor:
animation
,
child:
new
SizedBox
(
height:
100.0
,
child:
new
Center
(
child:
new
Text
(
'item
$index
'
),
),
),
);
},
),
);
double
itemHeight
(
int
index
)
=>
tester
.
getSize
(
find
.
byKey
(
new
ValueKey
<
int
>(
index
))).
height
;
double
itemTop
(
int
index
)
=>
tester
.
getTopLeft
(
find
.
byKey
(
new
ValueKey
<
int
>(
index
))).
dy
;
double
itemBottom
(
int
index
)
=>
tester
.
getBottomLeft
(
find
.
byKey
(
new
ValueKey
<
int
>(
index
))).
dy
;
listKey
.
currentState
.
insertItem
(
0
,
duration:
const
Duration
(
milliseconds:
100
));
await
tester
.
pump
();
// Newly inserted item 0's height should animate from 0 to 100
expect
(
itemHeight
(
0
),
0.0
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
50
));
expect
(
itemHeight
(
0
),
50.0
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
50
));
expect
(
itemHeight
(
0
),
100.0
);
// The list now contains one fully expanded item at the top:
expect
(
find
.
text
(
'item 0'
),
findsOneWidget
);
expect
(
itemTop
(
0
),
0.0
);
expect
(
itemBottom
(
0
),
100.0
);
listKey
.
currentState
.
insertItem
(
0
,
duration:
const
Duration
(
milliseconds:
100
));
listKey
.
currentState
.
insertItem
(
0
,
duration:
const
Duration
(
milliseconds:
100
));
await
tester
.
pump
();
// The height of the newly inserted items at index 0 and 1 should animate from 0 to 100.
// The height of the original item, now at index 2, should remain 100.
expect
(
itemHeight
(
0
),
0.0
);
expect
(
itemHeight
(
1
),
0.0
);
expect
(
itemHeight
(
2
),
100.0
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
50
));
expect
(
itemHeight
(
0
),
50.0
);
expect
(
itemHeight
(
1
),
50.0
);
expect
(
itemHeight
(
2
),
100.0
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
50
));
expect
(
itemHeight
(
0
),
100.0
);
expect
(
itemHeight
(
1
),
100.0
);
expect
(
itemHeight
(
2
),
100.0
);
// The newly inserted "item 1" and "item 2" appear above "item 0"
expect
(
find
.
text
(
'item 0'
),
findsOneWidget
);
expect
(
find
.
text
(
'item 1'
),
findsOneWidget
);
expect
(
find
.
text
(
'item 2'
),
findsOneWidget
);
expect
(
itemTop
(
0
),
0.0
);
expect
(
itemBottom
(
0
),
100.0
);
expect
(
itemTop
(
1
),
100.0
);
expect
(
itemBottom
(
1
),
200.0
);
expect
(
itemTop
(
2
),
200.0
);
expect
(
itemBottom
(
2
),
300.0
);
});
testWidgets
(
'AnimatedList remove'
,
(
WidgetTester
tester
)
async
{
final
GlobalKey
<
AnimatedListState
>
listKey
=
new
GlobalKey
<
AnimatedListState
>();
final
List
<
int
>
items
=
<
int
>[
0
,
1
,
2
];
Widget
buildItem
(
BuildContext
context
,
int
item
,
Animation
<
double
>
animation
)
{
return
new
SizeTransition
(
key:
new
ValueKey
<
int
>(
item
),
axis:
Axis
.
vertical
,
sizeFactor:
animation
,
child:
new
SizedBox
(
height:
100.0
,
child:
new
Center
(
child:
new
Text
(
'item
$item
'
),
),
),
);
}
await
tester
.
pumpWidget
(
new
AnimatedList
(
key:
listKey
,
initialItemCount:
3
,
itemBuilder:
(
BuildContext
context
,
int
index
,
Animation
<
double
>
animation
)
{
return
buildItem
(
context
,
items
[
index
],
animation
);
},
),
);
double
itemTop
(
int
index
)
=>
tester
.
getTopLeft
(
find
.
byKey
(
new
ValueKey
<
int
>(
index
))).
dy
;
double
itemBottom
(
int
index
)
=>
tester
.
getBottomLeft
(
find
.
byKey
(
new
ValueKey
<
int
>(
index
))).
dy
;
expect
(
find
.
text
(
'item 0'
),
findsOneWidget
);
expect
(
find
.
text
(
'item 1'
),
findsOneWidget
);
expect
(
find
.
text
(
'item 2'
),
findsOneWidget
);
items
.
removeAt
(
0
);
listKey
.
currentState
.
removeItem
(
0
,
(
BuildContext
context
,
Animation
<
double
>
animation
)
=>
buildItem
(
context
,
0
,
animation
),
duration:
const
Duration
(
milliseconds:
100
),
);
// Item's 0, 1, 2 at 0, 100, 200. All heights 100.
expect
(
itemTop
(
0
),
0.0
);
expect
(
itemBottom
(
0
),
100.0
);
expect
(
itemTop
(
1
),
100.0
);
expect
(
itemBottom
(
1
),
200.0
);
expect
(
itemTop
(
2
),
200.0
);
expect
(
itemBottom
(
2
),
300.0
);
// Newly removed item 0's height should animate from 100 to 0 over 100ms
// Item's 0, 1, 2 at 0, 50, 150. Item 0's height is 50.
await
tester
.
pump
();
await
tester
.
pump
(
const
Duration
(
milliseconds:
50
));
expect
(
itemTop
(
0
),
0.0
);
expect
(
itemBottom
(
0
),
50.0
);
expect
(
itemTop
(
1
),
50.0
);
expect
(
itemBottom
(
1
),
150.0
);
expect
(
itemTop
(
2
),
150.0
);
expect
(
itemBottom
(
2
),
250.0
);
// Item's 0, 1, 2 at 0, 0, 0. Item 0's height is 0.
await
tester
.
pumpAndSettle
();
expect
(
itemTop
(
0
),
0.0
);
expect
(
itemBottom
(
0
),
0.0
);
expect
(
itemTop
(
1
),
0.0
);
expect
(
itemBottom
(
1
),
100.0
);
expect
(
itemTop
(
2
),
100.0
);
expect
(
itemBottom
(
2
),
200.0
);
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment