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
c9e4541c
Commit
c9e4541c
authored
Feb 09, 2017
by
Adam Barth
Committed by
GitHub
Feb 09, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Port LazyBlock tests to ListView (#8026)
parent
1a61a76e
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
289 additions
and
320 deletions
+289
-320
lazy_block_test.dart
packages/flutter/test/widgets/lazy_block_test.dart
+0
-191
list_view_fling_test.dart
packages/flutter/test/widgets/list_view_fling_test.dart
+31
-0
list_view_relayout_test.dart
packages/flutter/test/widgets/list_view_relayout_test.dart
+158
-0
list_view_viewporting_test.dart
...ages/flutter/test/widgets/list_view_viewporting_test.dart
+74
-91
list_view_with_inherited_test.dart
...s/flutter/test/widgets/list_view_with_inherited_test.dart
+1
-1
scrollable_fling_test.dart
packages/flutter/test/widgets/scrollable_fling_test.dart
+25
-37
No files found.
packages/flutter/test/widgets/lazy_block_test.dart
deleted
100644 → 0
View file @
1a61a76e
// Copyright 2016 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/material.dart'
;
void
main
(
)
{
testWidgets
(
'Block inside LazyBlock'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
new
LazyBlock
(
delegate:
new
LazyBlockChildren
(
children:
<
Widget
>[
new
Block
(
children:
<
Widget
>[
new
Text
(
'1'
),
new
Text
(
'2'
),
new
Text
(
'3'
),
]
),
new
Block
(
children:
<
Widget
>[
new
Text
(
'4'
),
new
Text
(
'5'
),
new
Text
(
'6'
),
]
),
]
)
));
});
testWidgets
(
'Underflowing LazyBlock should relayout for additional children'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/5950
await
tester
.
pumpWidget
(
new
LazyBlock
(
delegate:
new
LazyBlockChildren
(
children:
<
Widget
>[
new
SizedBox
(
height:
100.0
,
child:
new
Text
(
'100'
)),
]
)
));
await
tester
.
pumpWidget
(
new
LazyBlock
(
delegate:
new
LazyBlockChildren
(
children:
<
Widget
>[
new
SizedBox
(
height:
100.0
,
child:
new
Text
(
'100'
)),
new
SizedBox
(
height:
200.0
,
child:
new
Text
(
'200'
)),
]
)
));
expect
(
find
.
text
(
'200'
),
findsOneWidget
);
});
testWidgets
(
'Underflowing LazyBlock contentExtent should track additional children'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
new
LazyBlock
(
delegate:
new
LazyBlockChildren
(
children:
<
Widget
>[
new
SizedBox
(
height:
100.0
,
child:
new
Text
(
'100'
)),
]
)
));
StatefulElement
statefulElement
=
tester
.
element
(
find
.
byType
(
Scrollable
));
ScrollableState
scrollable
=
statefulElement
.
state
;
OverscrollWhenScrollableBehavior
scrollBehavior
=
scrollable
.
scrollBehavior
;
expect
(
scrollBehavior
.
contentExtent
,
equals
(
100.0
));
await
tester
.
pumpWidget
(
new
LazyBlock
(
delegate:
new
LazyBlockChildren
(
children:
<
Widget
>[
new
SizedBox
(
height:
100.0
,
child:
new
Text
(
'100'
)),
new
SizedBox
(
height:
200.0
,
child:
new
Text
(
'200'
)),
]
)
));
expect
(
scrollBehavior
.
contentExtent
,
equals
(
300.0
));
await
tester
.
pumpWidget
(
new
LazyBlock
(
delegate:
new
LazyBlockChildren
(
children:
<
Widget
>[
]
)
));
expect
(
scrollBehavior
.
contentExtent
,
equals
(
0.0
));
});
testWidgets
(
'Overflowing LazyBlock should relayout for missing children'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
new
LazyBlock
(
delegate:
new
LazyBlockChildren
(
children:
<
Widget
>[
new
SizedBox
(
height:
300.0
,
child:
new
Text
(
'300'
)),
new
SizedBox
(
height:
400.0
,
child:
new
Text
(
'400'
)),
]
)
));
expect
(
find
.
text
(
'300'
),
findsOneWidget
);
expect
(
find
.
text
(
'400'
),
findsOneWidget
);
await
tester
.
pumpWidget
(
new
LazyBlock
(
delegate:
new
LazyBlockChildren
(
children:
<
Widget
>[
new
SizedBox
(
height:
300.0
,
child:
new
Text
(
'300'
)),
]
)
));
expect
(
find
.
text
(
'300'
),
findsOneWidget
);
expect
(
find
.
text
(
'400'
),
findsNothing
);
await
tester
.
pumpWidget
(
new
LazyBlock
(
delegate:
new
LazyBlockChildren
(
children:
<
Widget
>[
]
)
));
expect
(
find
.
text
(
'300'
),
findsNothing
);
expect
(
find
.
text
(
'400'
),
findsNothing
);
});
testWidgets
(
'Overflowing LazyBlock should not relayout for additional children'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
new
LazyBlock
(
delegate:
new
LazyBlockChildren
(
children:
<
Widget
>[
new
SizedBox
(
height:
300.0
,
child:
new
Text
(
'300'
)),
new
SizedBox
(
height:
400.0
,
child:
new
Text
(
'400'
)),
]
)
));
expect
(
find
.
text
(
'300'
),
findsOneWidget
);
expect
(
find
.
text
(
'400'
),
findsOneWidget
);
await
tester
.
pumpWidget
(
new
LazyBlock
(
delegate:
new
LazyBlockChildren
(
children:
<
Widget
>[
new
SizedBox
(
height:
300.0
,
child:
new
Text
(
'300'
)),
new
SizedBox
(
height:
400.0
,
child:
new
Text
(
'400'
)),
new
SizedBox
(
height:
100.0
,
child:
new
Text
(
'100'
)),
]
)
));
expect
(
find
.
text
(
'300'
),
findsOneWidget
);
expect
(
find
.
text
(
'400'
),
findsOneWidget
);
expect
(
find
.
text
(
'100'
),
findsNothing
);
StatefulElement
statefulElement
=
tester
.
element
(
find
.
byType
(
Scrollable
));
ScrollableState
scrollable
=
statefulElement
.
state
;
OverscrollWhenScrollableBehavior
scrollBehavior
=
scrollable
.
scrollBehavior
;
expect
(
scrollBehavior
.
contentExtent
,
equals
(
700.0
));
});
testWidgets
(
'Overflowing LazyBlock should become scrollable'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/5920
// When a LazyBlock's viewport hasn't overflowed, scrolling is disabled.
// When children are added that cause it to overflow, scrolling should
// be enabled.
await
tester
.
pumpWidget
(
new
LazyBlock
(
delegate:
new
LazyBlockChildren
(
children:
<
Widget
>[
new
SizedBox
(
height:
100.0
,
child:
new
Text
(
'100'
)),
]
)
));
StatefulElement
statefulElement
=
tester
.
element
(
find
.
byType
(
Scrollable
));
ScrollableState
scrollable
=
statefulElement
.
state
;
OverscrollWhenScrollableBehavior
scrollBehavior
=
scrollable
.
scrollBehavior
;
expect
(
scrollBehavior
.
isScrollable
,
isFalse
);
await
tester
.
pumpWidget
(
new
LazyBlock
(
delegate:
new
LazyBlockChildren
(
children:
<
Widget
>[
new
SizedBox
(
height:
100.0
,
child:
new
Text
(
'100'
)),
new
SizedBox
(
height:
200.0
,
child:
new
Text
(
'200'
)),
new
SizedBox
(
height:
400.0
,
child:
new
Text
(
'400'
)),
]
)
));
expect
(
scrollBehavior
.
isScrollable
,
isTrue
);
});
}
packages/flutter/test/widgets/l
azy_block
_fling_test.dart
→
packages/flutter/test/widgets/l
ist_view
_fling_test.dart
View file @
c9e4541c
...
...
@@ -8,35 +8,24 @@ import 'package:flutter/material.dart';
const
double
kHeight
=
10.0
;
const
double
kFlingOffset
=
kHeight
*
20.0
;
class
TestDelegate
extends
LazyBlockDelegate
{
@override
Widget
buildItem
(
BuildContext
context
,
int
index
)
{
void
main
(
)
{
testWidgets
(
'Flings don
\'
t stutter'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
new
ListView
.
builder
(
itemBuilder:
(
BuildContext
context
,
int
index
)
{
return
new
Container
(
height:
kHeight
);
}
},
));
@override
double
estimateTotalExtent
(
int
firstIndex
,
int
lastIndex
,
double
minOffset
,
double
firstStartOffset
,
double
lastEndOffset
)
{
return
double
.
INFINITY
;
double
getCurrentOffset
()
{
return
tester
.
state
<
Scrollable2State
>(
find
.
byType
(
Scrollable2
)).
position
.
pixels
;
}
@override
bool
shouldRebuild
(
LazyBlockDelegate
oldDelegate
)
=>
false
;
}
double
currentOffset
;
void
main
(
)
{
testWidgets
(
'Flings don
\'
t stutter'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
new
LazyBlock
(
delegate:
new
TestDelegate
(),
onScroll:
(
double
scrollOffset
)
{
currentOffset
=
scrollOffset
;
},
));
await
tester
.
fling
(
find
.
byType
(
LazyBlock
),
const
Offset
(
0.0
,
-
kFlingOffset
),
1000.0
);
expect
(
currentOffset
,
kFlingOffset
);
await
tester
.
fling
(
find
.
byType
(
ListView
),
const
Offset
(
0.0
,
-
kFlingOffset
),
1000.0
);
expect
(
getCurrentOffset
(),
kFlingOffset
);
while
(
tester
.
binding
.
transientCallbackCount
>
0
)
{
double
lastOffset
=
currentOffset
;
double
lastOffset
=
getCurrentOffset
()
;
await
tester
.
pump
(
const
Duration
(
milliseconds:
20
));
expect
(
currentOffset
,
greaterThan
(
lastOffset
));
expect
(
getCurrentOffset
()
,
greaterThan
(
lastOffset
));
}
},
skip:
true
);
// see https://github.com/flutter/flutter/issues/5339
}
packages/flutter/test/widgets/list_view_relayout_test.dart
0 → 100644
View file @
c9e4541c
// Copyright 2016 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/material.dart'
;
import
'package:flutter/rendering.dart'
;
void
main
(
)
{
testWidgets
(
'Nested ListView with shrinkWrap'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
new
ListView
(
shrinkWrap:
true
,
children:
<
Widget
>[
new
ListView
(
shrinkWrap:
true
,
children:
<
Widget
>[
new
Text
(
'1'
),
new
Text
(
'2'
),
new
Text
(
'3'
),
],
),
new
ListView
(
shrinkWrap:
true
,
children:
<
Widget
>[
new
Text
(
'4'
),
new
Text
(
'5'
),
new
Text
(
'6'
),
],
),
],
));
});
testWidgets
(
'Underflowing ListView should relayout for additional children'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/5950
await
tester
.
pumpWidget
(
new
ListView
(
children:
<
Widget
>[
new
SizedBox
(
height:
100.0
,
child:
new
Text
(
'100'
)),
],
));
await
tester
.
pumpWidget
(
new
ListView
(
children:
<
Widget
>[
new
SizedBox
(
height:
100.0
,
child:
new
Text
(
'100'
)),
new
SizedBox
(
height:
200.0
,
child:
new
Text
(
'200'
)),
],
));
expect
(
find
.
text
(
'200'
),
findsOneWidget
);
});
testWidgets
(
'Underflowing ListView contentExtent should track additional children'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
new
ListView
(
children:
<
Widget
>[
new
SizedBox
(
height:
100.0
,
child:
new
Text
(
'100'
)),
],
));
RenderSliverList
list
=
tester
.
renderObject
(
find
.
byType
(
SliverList
));
expect
(
list
.
geometry
.
scrollExtent
,
equals
(
100.0
));
await
tester
.
pumpWidget
(
new
ListView
(
children:
<
Widget
>[
new
SizedBox
(
height:
100.0
,
child:
new
Text
(
'100'
)),
new
SizedBox
(
height:
200.0
,
child:
new
Text
(
'200'
)),
],
));
expect
(
list
.
geometry
.
scrollExtent
,
equals
(
300.0
));
await
tester
.
pumpWidget
(
new
ListView
(
children:
<
Widget
>[]
));
expect
(
list
.
geometry
.
scrollExtent
,
equals
(
0.0
));
});
testWidgets
(
'Overflowing ListView should relayout for missing children'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
new
ListView
(
children:
<
Widget
>[
new
SizedBox
(
height:
300.0
,
child:
new
Text
(
'300'
)),
new
SizedBox
(
height:
400.0
,
child:
new
Text
(
'400'
)),
],
));
expect
(
find
.
text
(
'300'
),
findsOneWidget
);
expect
(
find
.
text
(
'400'
),
findsOneWidget
);
await
tester
.
pumpWidget
(
new
ListView
(
children:
<
Widget
>[
new
SizedBox
(
height:
300.0
,
child:
new
Text
(
'300'
)),
],
));
expect
(
find
.
text
(
'300'
),
findsOneWidget
);
expect
(
find
.
text
(
'400'
),
findsNothing
);
await
tester
.
pumpWidget
(
new
ListView
(
children:
<
Widget
>[]
));
expect
(
find
.
text
(
'300'
),
findsNothing
);
expect
(
find
.
text
(
'400'
),
findsNothing
);
});
testWidgets
(
'Overflowing ListView should not relayout for additional children'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
new
ListView
(
children:
<
Widget
>[
new
SizedBox
(
height:
300.0
,
child:
new
Text
(
'300'
)),
new
SizedBox
(
height:
400.0
,
child:
new
Text
(
'400'
)),
],
));
expect
(
find
.
text
(
'300'
),
findsOneWidget
);
expect
(
find
.
text
(
'400'
),
findsOneWidget
);
await
tester
.
pumpWidget
(
new
ListView
(
children:
<
Widget
>[
new
SizedBox
(
height:
300.0
,
child:
new
Text
(
'300'
)),
new
SizedBox
(
height:
400.0
,
child:
new
Text
(
'400'
)),
new
SizedBox
(
height:
100.0
,
child:
new
Text
(
'100'
)),
],
));
expect
(
find
.
text
(
'300'
),
findsOneWidget
);
expect
(
find
.
text
(
'400'
),
findsOneWidget
);
expect
(
find
.
text
(
'100'
),
findsNothing
);
RenderSliverList
list
=
tester
.
renderObject
(
find
.
byType
(
SliverList
));
expect
(
list
.
geometry
.
scrollExtent
,
equals
(
700.0
));
});
testWidgets
(
'Overflowing ListView should become scrollable'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/5920
// When a ListView's viewport hasn't overflowed, scrolling is disabled.
// When children are added that cause it to overflow, scrolling should
// be enabled.
await
tester
.
pumpWidget
(
new
ListView
(
children:
<
Widget
>[
new
SizedBox
(
height:
100.0
,
child:
new
Text
(
'100'
)),
],
));
Scrollable2State
scrollable
=
tester
.
state
(
find
.
byType
(
Scrollable2
));
expect
(
scrollable
.
position
.
maxScrollExtent
,
0.0
);
await
tester
.
pumpWidget
(
new
ListView
(
children:
<
Widget
>[
new
SizedBox
(
height:
100.0
,
child:
new
Text
(
'100'
)),
new
SizedBox
(
height:
200.0
,
child:
new
Text
(
'200'
)),
new
SizedBox
(
height:
400.0
,
child:
new
Text
(
'400'
)),
],
));
expect
(
scrollable
.
position
.
maxScrollExtent
,
100.0
);
});
}
packages/flutter/test/widgets/l
azy_block_viewport
_test.dart
→
packages/flutter/test/widgets/l
ist_view_viewporting
_test.dart
View file @
c9e4541c
...
...
@@ -9,7 +9,7 @@ import 'package:flutter/rendering.dart';
import
'test_widgets.dart'
;
void
main
(
)
{
testWidgets
(
'L
azyBlockViewport
mount/dismount smoke test'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'L
istView
mount/dismount smoke test'
,
(
WidgetTester
tester
)
async
{
List
<
int
>
callbackTracker
=
<
int
>[];
// the root view is 800x600 in the test environment
...
...
@@ -17,18 +17,17 @@ void main() {
Widget
builder
()
{
return
new
FlipWidget
(
left:
new
L
azyBlockViewport
(
delegate:
new
LazyBlockBuilder
(
builder:
(
BuildContext
context
,
int
i
)
{
callbackTracker
.
add
(
i
);
left:
new
L
istView
.
builder
(
itemBuilder:
(
BuildContext
context
,
int
index
)
{
callbackTracker
.
add
(
i
ndex
);
return
new
Container
(
key:
new
ValueKey
<
int
>(
i
),
key:
new
ValueKey
<
int
>(
i
ndex
),
height:
100.0
,
child:
new
Text
(
"
$i
"
)
child:
new
Text
(
"
$i
ndex
"
),
);
}),
startOffset:
0.0
},
),
right:
new
Text
(
'Not Today'
)
right:
new
Text
(
'Not Today'
)
,
);
}
...
...
@@ -51,32 +50,30 @@ void main() {
expect
(
callbackTracker
,
equals
(<
int
>[
0
,
1
,
2
,
3
,
4
,
5
]));
});
testWidgets
(
'L
azyBlockViewport
vertical'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'L
istView
vertical'
,
(
WidgetTester
tester
)
async
{
List
<
int
>
callbackTracker
=
<
int
>[];
// the root view is 800x600 in the test environment
// so if our widget is 200 pixels tall, it should fit exactly 3 times.
// but if we are offset by 300 pixels, there will be 4, numbered 1-4.
double
offset
=
300.0
;
IndexedWidgetBuilder
itemBuilder
=
(
BuildContext
context
,
int
i
)
{
callbackTracker
.
add
(
i
);
IndexedWidgetBuilder
itemBuilder
=
(
BuildContext
context
,
int
index
)
{
callbackTracker
.
add
(
index
);
return
new
Container
(
key:
new
ValueKey
<
int
>(
i
),
key:
new
ValueKey
<
int
>(
i
ndex
),
width:
500.0
,
// this should be ignored
height:
200.0
,
child:
new
Text
(
"
$i
"
)
child:
new
Text
(
'
$index
'
),
);
};
Widget
builder
()
{
return
new
FlipWidget
(
left:
new
L
azyBlockViewport
(
delegate:
new
LazyBlockBuilder
(
builder:
itemBuilder
),
startOffset:
offset
left:
new
L
istView
.
builder
(
controller:
new
ScrollController
(
initialScrollOffset:
300.0
),
itemBuilder:
itemBuilder
,
),
right:
new
Text
(
'Not Today'
)
right:
new
Text
(
'Not Today'
)
,
);
}
...
...
@@ -86,12 +83,13 @@ void main() {
expect
(
callbackTracker
,
equals
(<
int
>[
0
,
1
,
2
,
3
,
4
]));
callbackTracker
.
clear
();
offset
=
400.0
;
// now only 3 should fit, numbered 2-4.
Scrollable2State
scrollable
=
tester
.
state
(
find
.
byType
(
Scrollable2
));
scrollable
.
position
.
jumpTo
(
400.0
);
// now only 3 should fit, numbered 2-4.
await
tester
.
pumpWidget
(
builder
());
// We build
all th
e children to find their new size.
expect
(
callbackTracker
,
equals
(<
int
>[
0
,
1
,
2
,
3
,
4
]));
// We build
the visibl
e children to find their new size.
expect
(
callbackTracker
,
equals
(<
int
>[
1
,
2
,
3
,
4
]));
callbackTracker
.
clear
();
await
tester
.
pumpWidget
(
builder
());
...
...
@@ -101,33 +99,31 @@ void main() {
callbackTracker
.
clear
();
});
testWidgets
(
'L
azyBlockViewport
horizontal'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'L
istView
horizontal'
,
(
WidgetTester
tester
)
async
{
List
<
int
>
callbackTracker
=
<
int
>[];
// the root view is 800x600 in the test environment
// so if our widget is 200 pixels wide, it should fit exactly 4 times.
// but if we are offset by 300 pixels, there will be 5, numbered 1-5.
double
offset
=
300.0
;
IndexedWidgetBuilder
itemBuilder
=
(
BuildContext
context
,
int
i
)
{
callbackTracker
.
add
(
i
);
IndexedWidgetBuilder
itemBuilder
=
(
BuildContext
context
,
int
index
)
{
callbackTracker
.
add
(
index
);
return
new
Container
(
key:
new
ValueKey
<
int
>(
i
),
key:
new
ValueKey
<
int
>(
i
ndex
),
height:
500.0
,
// this should be ignored
width:
200.0
,
child:
new
Text
(
"
$i
"
)
child:
new
Text
(
'
$index
'
),
);
};
Widget
builder
()
{
return
new
FlipWidget
(
left:
new
L
azyBlockViewport
(
delegate:
new
LazyBlockBuilder
(
builder:
itemBuilder
)
,
startOffset:
offset
,
mainAxis:
Axis
.
horizontal
left:
new
L
istView
.
builder
(
scrollDirection:
Axis
.
horizontal
,
controller:
new
ScrollController
(
initialScrollOffset:
300.0
)
,
itemBuilder:
itemBuilder
,
),
right:
new
Text
(
'Not Today'
)
right:
new
Text
(
'Not Today'
)
,
);
}
...
...
@@ -138,12 +134,13 @@ void main() {
callbackTracker
.
clear
();
offset
=
400.0
;
// now only 4 should fit, numbered 2-5.
Scrollable2State
scrollable
=
tester
.
state
(
find
.
byType
(
Scrollable2
));
scrollable
.
position
.
jumpTo
(
400.0
);
// now only 4 should fit, numbered 2-5.
await
tester
.
pumpWidget
(
builder
());
// We build
all th
e children to find their new size.
expect
(
callbackTracker
,
equals
(<
int
>[
0
,
1
,
2
,
3
,
4
,
5
]));
// We build
the visibl
e children to find their new size.
expect
(
callbackTracker
,
equals
(<
int
>[
1
,
2
,
3
,
4
,
5
]));
callbackTracker
.
clear
();
await
tester
.
pumpWidget
(
builder
());
...
...
@@ -153,17 +150,17 @@ void main() {
callbackTracker
.
clear
();
});
testWidgets
(
'L
azyBlockViewport
reinvoke builders'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'L
istView
reinvoke builders'
,
(
WidgetTester
tester
)
async
{
List
<
int
>
callbackTracker
=
<
int
>[];
List
<
String
>
text
=
<
String
>[];
IndexedWidgetBuilder
itemBuilder
=
(
BuildContext
context
,
int
i
)
{
callbackTracker
.
add
(
i
);
IndexedWidgetBuilder
itemBuilder
=
(
BuildContext
context
,
int
i
ndex
)
{
callbackTracker
.
add
(
i
ndex
);
return
new
Container
(
key:
new
ValueKey
<
int
>(
i
),
key:
new
ValueKey
<
int
>(
i
ndex
),
width:
500.0
,
// this should be ignored
height:
220.0
,
child:
new
Text
(
"
$i
"
)
child:
new
Text
(
'
$index
'
)
);
};
...
...
@@ -173,9 +170,8 @@ void main() {
}
Widget
builder
()
{
return
new
LazyBlockViewport
(
delegate:
new
LazyBlockBuilder
(
builder:
itemBuilder
),
startOffset:
0.0
return
new
ListView
.
builder
(
itemBuilder:
itemBuilder
,
);
}
...
...
@@ -196,24 +192,24 @@ void main() {
text
.
clear
();
});
testWidgets
(
'L
azyBlockViewport
reinvoke builders'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'L
istView
reinvoke builders'
,
(
WidgetTester
tester
)
async
{
StateSetter
setState
;
ThemeData
themeData
=
new
ThemeData
.
light
();
IndexedWidgetBuilder
itemBuilder
=
(
BuildContext
context
,
int
i
)
{
IndexedWidgetBuilder
itemBuilder
=
(
BuildContext
context
,
int
i
ndex
)
{
return
new
Container
(
key:
new
ValueKey
<
int
>(
i
),
key:
new
ValueKey
<
int
>(
i
ndex
),
width:
500.0
,
// this should be ignored
height:
220.0
,
decoration:
new
BoxDecoration
(
backgroundColor:
Theme
.
of
(
context
).
primaryColor
backgroundColor:
Theme
.
of
(
context
).
primaryColor
,
),
child:
new
Text
(
"
$i
"
)
child:
new
Text
(
'
$index
'
),
);
};
Widget
viewport
=
new
L
azyBlockViewport
(
delegate:
new
LazyBlockBuilder
(
builder:
itemBuilder
)
Widget
viewport
=
new
L
istView
.
builder
(
itemBuilder:
itemBuilder
,
);
await
tester
.
pumpWidget
(
...
...
@@ -240,24 +236,24 @@ void main() {
expect
(
decoraton
.
backgroundColor
,
equals
(
Colors
.
green
[
500
]));
});
testWidgets
(
'L
azyBlockViewport
padding'
,
(
WidgetTester
tester
)
async
{
IndexedWidgetBuilder
itemBuilder
=
(
BuildContext
context
,
int
i
)
{
testWidgets
(
'L
istView
padding'
,
(
WidgetTester
tester
)
async
{
IndexedWidgetBuilder
itemBuilder
=
(
BuildContext
context
,
int
i
ndex
)
{
return
new
Container
(
key:
new
ValueKey
<
int
>(
i
),
key:
new
ValueKey
<
int
>(
i
ndex
),
width:
500.0
,
// this should be ignored
height:
220.0
,
decoration:
new
BoxDecoration
(
backgroundColor:
Colors
.
green
[
500
]
),
child:
new
Text
(
"
$i
"
)
child:
new
Text
(
'
$index
'
),
);
};
await
tester
.
pumpWidget
(
new
L
azyBlockViewport
(
new
L
istView
.
builder
(
padding:
const
EdgeInsets
.
fromLTRB
(
7.0
,
3.0
,
5.0
,
11.0
),
delegate:
new
LazyBlockBuilder
(
builder:
itemBuilder
)
)
itemBuilder:
itemBuilder
,
)
,
);
RenderBox
firstBox
=
tester
.
renderObject
(
find
.
text
(
'0'
));
...
...
@@ -266,38 +262,25 @@ void main() {
expect
(
firstBox
.
size
.
width
,
equals
(
800.0
-
12.0
));
});
testWidgets
(
'Underflow extents'
,
(
WidgetTester
tester
)
async
{
int
lastFirstIndex
;
int
lastLastIndex
;
double
lastFirstStartOffset
;
double
lastLastEndOffset
;
double
lastMinScrollOffset
;
double
lastContainerExtent
;
void
handleExtendsChanged
(
int
firstIndex
,
int
lastIndex
,
double
firstStartOffset
,
double
lastEndOffset
,
double
minScrollOffset
,
double
containerExtent
)
{
lastFirstIndex
=
firstIndex
;
lastLastIndex
=
lastIndex
;
lastFirstStartOffset
=
firstStartOffset
;
lastLastEndOffset
=
lastEndOffset
;
lastMinScrollOffset
=
minScrollOffset
;
lastContainerExtent
=
containerExtent
;
}
await
tester
.
pumpWidget
(
new
LazyBlockViewport
(
onExtentsChanged:
handleExtendsChanged
,
delegate:
new
LazyBlockChildren
(
testWidgets
(
'ListView underflow extents'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
new
ListView
(
children:
<
Widget
>[
new
Container
(
height:
100.0
),
new
Container
(
height:
100.0
),
new
Container
(
height:
100.0
),
]
)
],
));
expect
(
lastFirstIndex
,
0
);
expect
(
lastLastIndex
,
2
);
expect
(
lastFirstStartOffset
,
0.0
);
expect
(
lastLastEndOffset
,
300.0
);
expect
(
lastContainerExtent
,
600.0
);
expect
(
lastMinScrollOffset
,
0.0
);
RenderSliverList
list
=
tester
.
renderObject
(
find
.
byType
(
SliverList
));
expect
(
list
.
indexOf
(
list
.
firstChild
),
equals
(
0
));
expect
(
list
.
indexOf
(
list
.
lastChild
),
equals
(
2
));
expect
(
list
.
childScrollOffset
(
list
.
firstChild
),
equals
(
0.0
));
expect
(
list
.
geometry
.
scrollExtent
,
equals
(
300.0
));
ScrollPosition
position
=
tester
.
state
<
Scrollable2State
>(
find
.
byType
(
Scrollable2
)).
position
;
expect
(
position
.
viewportDimension
,
equals
(
600.0
));
expect
(
position
.
minScrollExtent
,
equals
(
0.0
));
});
}
packages/flutter/test/widgets/
scrollable_list
_with_inherited_test.dart
→
packages/flutter/test/widgets/
list_view
_with_inherited_test.dart
View file @
c9e4541c
...
...
@@ -27,7 +27,7 @@ Widget buildFrame() {
}
void
main
(
)
{
testWidgets
(
'L
azyBlock
is a build function (smoketest)'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'L
istView
is a build function (smoketest)'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
buildFrame
());
expect
(
find
.
text
(
'0'
),
findsOneWidget
);
expect
(
find
.
text
(
'1'
),
findsOneWidget
);
...
...
packages/flutter/test/widgets/scrollable_fling_test.dart
View file @
c9e4541c
...
...
@@ -7,32 +7,16 @@ import 'dart:io';
import
'package:flutter_test/flutter_test.dart'
;
import
'package:flutter/material.dart'
;
class
TestDelegate
extends
LazyBlockDelegate
{
@override
Widget
buildItem
(
BuildContext
context
,
int
index
)
{
return
new
Text
(
'
$index
'
);
}
@override
double
estimateTotalExtent
(
int
firstIndex
,
int
lastIndex
,
double
minOffset
,
double
firstStartOffset
,
double
lastEndOffset
)
{
return
double
.
INFINITY
;
}
@override
bool
shouldRebuild
(
LazyBlockDelegate
oldDelegate
)
=>
false
;
}
double
currentOffset
;
Future
<
Null
>
pumpTest
(
WidgetTester
tester
,
TargetPlatform
platform
)
async
{
await
tester
.
pumpWidget
(
new
Container
());
await
tester
.
pumpWidget
(
new
MaterialApp
(
theme:
new
ThemeData
(
platform:
platform
),
home:
new
LazyBlock
(
delegate:
new
TestDelegate
(),
onScroll:
(
double
scrollOffset
)
{
currentOffset
=
scrollOffset
;
},
home:
new
ListView
.
builder
(
itemBuilder:
(
BuildContext
context
,
int
index
)
{
return
new
Text
(
'
$index
'
);
},
),
));
return
null
;
...
...
@@ -42,21 +26,25 @@ const double dragOffset = 213.82;
void
main
(
)
{
testWidgets
(
'Flings on different platforms'
,
(
WidgetTester
tester
)
async
{
double
getCurrentOffset
()
{
return
tester
.
state
<
Scrollable2State
>(
find
.
byType
(
Scrollable2
)).
position
.
pixels
;
}
await
pumpTest
(
tester
,
TargetPlatform
.
android
);
await
tester
.
fling
(
find
.
byType
(
L
azyBlock
),
const
Offset
(
0.0
,
-
dragOffset
),
1000.0
);
expect
(
currentOffset
,
dragOffset
);
await
tester
.
fling
(
find
.
byType
(
L
istView
),
const
Offset
(
0.0
,
-
dragOffset
),
1000.0
);
expect
(
getCurrentOffset
()
,
dragOffset
);
await
tester
.
pump
();
// trigger fling
expect
(
currentOffset
,
dragOffset
);
expect
(
getCurrentOffset
()
,
dragOffset
);
await
tester
.
pump
(
const
Duration
(
seconds:
5
));
final
double
result1
=
currentOffset
;
final
double
result1
=
getCurrentOffset
()
;
await
pumpTest
(
tester
,
TargetPlatform
.
iOS
);
await
tester
.
fling
(
find
.
byType
(
L
azyBlock
),
const
Offset
(
0.0
,
-
dragOffset
),
1000.0
);
expect
(
currentOffset
,
dragOffset
);
await
tester
.
fling
(
find
.
byType
(
L
istView
),
const
Offset
(
0.0
,
-
dragOffset
),
1000.0
);
expect
(
getCurrentOffset
()
,
dragOffset
);
await
tester
.
pump
();
// trigger fling
expect
(
currentOffset
,
dragOffset
);
expect
(
getCurrentOffset
()
,
dragOffset
);
await
tester
.
pump
(
const
Duration
(
seconds:
5
));
final
double
result2
=
currentOffset
;
final
double
result2
=
getCurrentOffset
()
;
expect
(
result1
,
lessThan
(
result2
));
// iOS (result2) is slipperier than Android (result1)
});
...
...
@@ -67,19 +55,19 @@ void main() {
List
<
Widget
>
textWidgets
=
<
Widget
>[];
for
(
int
i
=
0
;
i
<
250
;
i
++)
textWidgets
.
add
(
new
GestureDetector
(
onTap:
()
{
log
.
add
(
'tap
$i
'
);
},
child:
new
Text
(
'
$i
'
)));
await
tester
.
pumpWidget
(
new
Block
(
children:
textWidgets
));
await
tester
.
pumpWidget
(
new
ListView
(
children:
textWidgets
));
expect
(
log
,
equals
(<
String
>[]));
await
tester
.
tap
(
find
.
byType
(
Scrollable
));
await
tester
.
tap
(
find
.
byType
(
Scrollable
2
));
await
tester
.
pump
(
const
Duration
(
milliseconds:
50
));
expect
(
log
,
equals
(<
String
>[
'tap 18'
]));
await
tester
.
fling
(
find
.
byType
(
Scrollable
),
const
Offset
(
0.0
,
-
200.0
),
1000.0
);
await
tester
.
fling
(
find
.
byType
(
Scrollable
2
),
const
Offset
(
0.0
,
-
200.0
),
1000.0
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
50
));
expect
(
log
,
equals
(<
String
>[
'tap 18'
]));
await
tester
.
tap
(
find
.
byType
(
Scrollable
));
await
tester
.
tap
(
find
.
byType
(
Scrollable
2
));
await
tester
.
pump
(
const
Duration
(
milliseconds:
50
));
expect
(
log
,
equals
(<
String
>[
'tap 18'
]));
await
tester
.
tap
(
find
.
byType
(
Scrollable
));
await
tester
.
tap
(
find
.
byType
(
Scrollable
2
));
await
tester
.
pump
(
const
Duration
(
milliseconds:
50
));
expect
(
log
,
equals
(<
String
>[
'tap 18'
,
'tap 31'
]));
},
skip:
Platform
.
isMacOS
);
// Skip due to https://github.com/flutter/flutter/issues/6961
...
...
@@ -90,18 +78,18 @@ void main() {
List
<
Widget
>
textWidgets
=
<
Widget
>[];
for
(
int
i
=
0
;
i
<
250
;
i
++)
textWidgets
.
add
(
new
GestureDetector
(
onTap:
()
{
log
.
add
(
'tap
$i
'
);
},
child:
new
Text
(
'
$i
'
)));
await
tester
.
pumpWidget
(
new
Block
(
children:
textWidgets
));
await
tester
.
pumpWidget
(
new
ListView
(
children:
textWidgets
));
expect
(
log
,
equals
(<
String
>[]));
await
tester
.
tap
(
find
.
byType
(
Scrollable
));
await
tester
.
tap
(
find
.
byType
(
Scrollable
2
));
await
tester
.
pump
(
const
Duration
(
milliseconds:
50
));
expect
(
log
,
equals
(<
String
>[
'tap 18'
]));
await
tester
.
fling
(
find
.
byType
(
Scrollable
),
const
Offset
(
0.0
,
-
200.0
),
1000.0
);
await
tester
.
fling
(
find
.
byType
(
Scrollable
2
),
const
Offset
(
0.0
,
-
200.0
),
1000.0
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
50
));
expect
(
log
,
equals
(<
String
>[
'tap 18'
]));
await
tester
.
pump
(
const
Duration
(
seconds:
50
));
expect
(
log
,
equals
(<
String
>[
'tap 18'
]));
await
tester
.
tap
(
find
.
byType
(
Scrollable
));
await
tester
.
tap
(
find
.
byType
(
Scrollable
2
));
await
tester
.
pump
(
const
Duration
(
milliseconds:
50
));
expect
(
log
,
equals
(<
String
>[
'tap 18'
,
'tap 43'
]));
},
skip:
Platform
.
isMacOS
);
// Skip due to https://github.com/flutter/flutter/issues/6961
...
...
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