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
8b5cbca7
Unverified
Commit
8b5cbca7
authored
Jul 09, 2018
by
Hans Muller
Committed by
GitHub
Jul 09, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rebuilding BottomNavigationBar when items.length changes (#19179)
parent
032f8cdb
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
4 deletions
+59
-4
bottom_navigation_bar.dart
packages/flutter/lib/src/material/bottom_navigation_bar.dart
+21
-4
bottom_navigation_bar_test.dart
...ges/flutter/test/material/bottom_navigation_bar_test.dart
+38
-0
No files found.
packages/flutter/lib/src/material/bottom_navigation_bar.dart
View file @
8b5cbca7
...
...
@@ -303,7 +303,7 @@ class _BottomNavigationTile extends StatelessWidget {
}
class
_BottomNavigationBarState
extends
State
<
BottomNavigationBar
>
with
TickerProviderStateMixin
{
List
<
AnimationController
>
_controllers
;
List
<
AnimationController
>
_controllers
=
<
AnimationController
>[]
;
List
<
CurvedAnimation
>
_animations
;
// A queue of color splashes currently being animated.
...
...
@@ -315,9 +315,13 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
static
final
Tween
<
double
>
_flexTween
=
new
Tween
<
double
>(
begin:
1.0
,
end:
1.5
);
@override
void
initState
()
{
super
.
initState
();
void
_resetState
()
{
for
(
AnimationController
controller
in
_controllers
)
controller
.
dispose
();
for
(
_Circle
circle
in
_circles
)
circle
.
dispose
();
_circles
.
clear
();
_controllers
=
new
List
<
AnimationController
>.
generate
(
widget
.
items
.
length
,
(
int
index
)
{
return
new
AnimationController
(
duration:
kThemeAnimationDuration
,
...
...
@@ -335,6 +339,12 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
_backgroundColor
=
widget
.
items
[
widget
.
currentIndex
].
backgroundColor
;
}
@override
void
initState
()
{
super
.
initState
();
_resetState
();
}
void
_rebuild
()
{
setState
(()
{
// Rebuilding when any of the controllers tick, i.e. when the items are
...
...
@@ -385,6 +395,13 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
@override
void
didUpdateWidget
(
BottomNavigationBar
oldWidget
)
{
super
.
didUpdateWidget
(
oldWidget
);
// No animated segue if the length of the items list changes.
if
(
widget
.
items
.
length
!=
oldWidget
.
items
.
length
)
{
_resetState
();
return
;
}
if
(
widget
.
currentIndex
!=
oldWidget
.
currentIndex
)
{
switch
(
widget
.
type
)
{
case
BottomNavigationBarType
.
fixed
:
...
...
packages/flutter/test/material/bottom_navigation_bar_test.dart
View file @
8b5cbca7
...
...
@@ -602,6 +602,44 @@ void main() {
semantics
.
dispose
();
});
testWidgets
(
'BottomNavigationBar handles items.length changes'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/10322
Widget
buildFrame
(
int
itemCount
)
{
return
new
MaterialApp
(
home:
new
Scaffold
(
bottomNavigationBar:
new
BottomNavigationBar
(
type:
BottomNavigationBarType
.
fixed
,
currentIndex:
0
,
items:
new
List
<
BottomNavigationBarItem
>.
generate
(
itemCount
,
(
int
itemIndex
)
{
return
new
BottomNavigationBarItem
(
icon:
const
Icon
(
Icons
.
android
),
title:
new
Text
(
'item
$itemIndex
'
),
);
}),
),
),
);
}
await
tester
.
pumpWidget
(
buildFrame
(
3
));
expect
(
find
.
text
(
'item 0'
),
findsOneWidget
);
expect
(
find
.
text
(
'item 1'
),
findsOneWidget
);
expect
(
find
.
text
(
'item 2'
),
findsOneWidget
);
expect
(
find
.
text
(
'item 3'
),
findsNothing
);
await
tester
.
pumpWidget
(
buildFrame
(
4
));
expect
(
find
.
text
(
'item 0'
),
findsOneWidget
);
expect
(
find
.
text
(
'item 1'
),
findsOneWidget
);
expect
(
find
.
text
(
'item 2'
),
findsOneWidget
);
expect
(
find
.
text
(
'item 3'
),
findsOneWidget
);
await
tester
.
pumpWidget
(
buildFrame
(
2
));
expect
(
find
.
text
(
'item 0'
),
findsOneWidget
);
expect
(
find
.
text
(
'item 1'
),
findsOneWidget
);
expect
(
find
.
text
(
'item 2'
),
findsNothing
);
expect
(
find
.
text
(
'item 3'
),
findsNothing
);
});
}
Widget
boilerplate
(
{
Widget
bottomNavigationBar
,
@required
TextDirection
textDirection
})
{
...
...
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