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
91478d96
Unverified
Commit
91478d96
authored
Oct 22, 2020
by
Michael Goderbauer
Committed by
GitHub
Oct 22, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not instantiate intermediate tabs during transition (#68124)
parent
52c715fe
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
106 additions
and
3 deletions
+106
-3
sliver.dart
packages/flutter/lib/src/widgets/sliver.dart
+22
-3
tabs_test.dart
packages/flutter/test/material/tabs_test.dart
+84
-0
No files found.
packages/flutter/lib/src/widgets/sliver.dart
View file @
91478d96
...
...
@@ -861,6 +861,9 @@ class SliverList extends SliverMultiBoxAdaptorWidget {
required
SliverChildDelegate
delegate
,
})
:
super
(
key:
key
,
delegate:
delegate
);
@override
SliverMultiBoxAdaptorElement
createElement
()
=>
SliverMultiBoxAdaptorElement
(
this
,
replaceMovedChildren:
true
);
@override
RenderSliverList
createRenderObject
(
BuildContext
context
)
{
final
SliverMultiBoxAdaptorElement
element
=
context
as
SliverMultiBoxAdaptorElement
;
...
...
@@ -1079,7 +1082,21 @@ class SliverGrid extends SliverMultiBoxAdaptorWidget {
/// the children of subclasses of [RenderSliverMultiBoxAdaptor].
class
SliverMultiBoxAdaptorElement
extends
RenderObjectElement
implements
RenderSliverBoxChildManager
{
/// Creates an element that lazily builds children for the given widget.
SliverMultiBoxAdaptorElement
(
SliverMultiBoxAdaptorWidget
widget
)
:
super
(
widget
);
///
/// If `replaceMovedChildren` is set to true, a new child is proactively
/// inflate for the index that was previously occupied by a child that moved
/// to a new index. The layout offset of the moved child is copied over to the
/// new child. RenderObjects, that depend on the layout offset of existing
/// children during [RenderObject.performLayout] should set this to true
/// (example: [RenderSliverList]). For RenderObjects that figure out the
/// layout offset of their children without looking at the layout offset of
/// existing children this should be set to false (example:
/// [RenderSliverFixedExtentList]) to avoid inflating unnecessary children.
SliverMultiBoxAdaptorElement
(
SliverMultiBoxAdaptorWidget
widget
,
{
bool
replaceMovedChildren
=
false
})
:
_replaceMovedChildren
=
replaceMovedChildren
,
super
(
widget
);
final
bool
_replaceMovedChildren
;
@override
SliverMultiBoxAdaptorWidget
get
widget
=>
super
.
widget
as
SliverMultiBoxAdaptorWidget
;
...
...
@@ -1146,8 +1163,10 @@ class SliverMultiBoxAdaptorElement extends RenderObjectElement implements Render
childParentData
.
layoutOffset
=
null
;
newChildren
[
newIndex
]
=
_childElements
[
index
];
// We need to make sure the original index gets processed.
newChildren
.
putIfAbsent
(
index
,
()
=>
null
);
if
(
_replaceMovedChildren
)
{
// We need to make sure the original index gets processed.
newChildren
.
putIfAbsent
(
index
,
()
=>
null
);
}
// We do not want the remapped child to get deactivated during processElement.
_childElements
.
remove
(
index
);
}
else
{
...
...
packages/flutter/test/material/tabs_test.dart
View file @
91478d96
...
...
@@ -2771,6 +2771,52 @@ void main() {
await
tester
.
pump
();
expect
(
tabController
.
animation
!.
value
,
pageController
.
page
);
});
testWidgets
(
'Does not instantiate intermediate tabs during animation'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/14316.
final
List
<
String
>
log
=
<
String
>[];
await
tester
.
pumpWidget
(
MaterialApp
(
home:
DefaultTabController
(
length:
5
,
child:
Scaffold
(
appBar:
AppBar
(
bottom:
const
TabBar
(
tabs:
<
Widget
>[
Tab
(
text:
'car'
),
Tab
(
text:
'transit'
),
Tab
(
text:
'bike'
),
Tab
(
text:
'boat'
),
Tab
(
text:
'bus'
),
],
),
title:
const
Text
(
'Tabs Test'
),
),
body:
TabBarView
(
children:
<
Widget
>[
TabBody
(
index:
0
,
log:
log
),
TabBody
(
index:
1
,
log:
log
),
TabBody
(
index:
2
,
log:
log
),
TabBody
(
index:
3
,
log:
log
),
TabBody
(
index:
4
,
log:
log
),
],
),
),
),
));
expect
(
find
.
text
(
'0'
),
findsOneWidget
);
expect
(
find
.
text
(
'3'
),
findsNothing
);
expect
(
log
,
<
String
>[
'init: 0'
]);
await
tester
.
tap
(
find
.
text
(
'boat'
));
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'0'
),
findsNothing
);
expect
(
find
.
text
(
'3'
),
findsOneWidget
);
// No other tab got instantiated during the animation.
expect
(
log
,
<
String
>[
'init: 0'
,
'init: 3'
,
'dispose: 0'
]);
});
}
class
KeepAliveInk
extends
StatefulWidget
{
...
...
@@ -2826,3 +2872,41 @@ class TabBarDemo extends StatelessWidget {
}
class
MockScrollMetrics
extends
Fake
implements
ScrollMetrics
{}
class
TabBody
extends
StatefulWidget
{
const
TabBody
({
Key
?
key
,
required
this
.
index
,
required
this
.
log
})
:
super
(
key:
key
);
final
int
index
;
final
List
<
String
>
log
;
@override
State
<
TabBody
>
createState
()
=>
TabBodyState
();
}
class
TabBodyState
extends
State
<
TabBody
>
{
@override
void
initState
()
{
widget
.
log
.
add
(
'init:
${widget.index}
'
);
super
.
initState
();
}
@override
void
didUpdateWidget
(
TabBody
oldWidget
)
{
super
.
didUpdateWidget
(
oldWidget
);
// To keep the logging straight, widgets must not change their index.
assert
(
oldWidget
.
index
==
widget
.
index
);
}
@override
void
dispose
()
{
widget
.
log
.
add
(
'dispose:
${widget.index}
'
);
super
.
dispose
();
}
@override
Widget
build
(
BuildContext
context
)
{
return
Center
(
child:
Text
(
'
${widget.index}
'
),
);
}
}
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