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
6c07863f
Unverified
Commit
6c07863f
authored
Jan 18, 2019
by
MH Johnson
Committed by
GitHub
Jan 18, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Material] Refactor _build<Widget> methods in BottomNavBar (#26722)
parent
9f72c5fb
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
106 additions
and
50 deletions
+106
-50
bottom_navigation_bar.dart
packages/flutter/lib/src/material/bottom_navigation_bar.dart
+106
-50
No files found.
packages/flutter/lib/src/material/bottom_navigation_bar.dart
View file @
6c07863f
...
...
@@ -220,7 +220,84 @@ class _BottomNavigationTile extends StatelessWidget {
final
bool
selected
;
final
String
indexLabel
;
Widget
_buildIcon
()
{
@override
Widget
build
(
BuildContext
context
)
{
// In order to use the flex container to grow the tile during animation, we
// need to divide the changes in flex allotment into smaller pieces to
// produce smooth animation. We do this by multiplying the flex value
// (which is an integer) by a large number.
int
size
;
Widget
label
;
switch
(
type
)
{
case
BottomNavigationBarType
.
fixed
:
size
=
1
;
label
=
_FixedLabel
(
colorTween:
colorTween
,
animation:
animation
,
item:
item
);
break
;
case
BottomNavigationBarType
.
shifting
:
size
=
(
flex
*
1000.0
).
round
();
label
=
_ShiftingLabel
(
animation:
animation
,
item:
item
);
break
;
}
return
Expanded
(
flex:
size
,
child:
Semantics
(
container:
true
,
header:
true
,
selected:
selected
,
child:
Stack
(
children:
<
Widget
>[
InkResponse
(
onTap:
onTap
,
child:
Column
(
crossAxisAlignment:
CrossAxisAlignment
.
center
,
mainAxisAlignment:
MainAxisAlignment
.
spaceBetween
,
mainAxisSize:
MainAxisSize
.
min
,
children:
<
Widget
>[
_TileIcon
(
type:
type
,
colorTween:
colorTween
,
animation:
animation
,
iconSize:
iconSize
,
selected:
selected
,
item:
item
,
),
label
,
],
),
),
Semantics
(
label:
indexLabel
,
)
],
),
),
);
}
}
class
_TileIcon
extends
StatelessWidget
{
const
_TileIcon
({
Key
key
,
@required
this
.
type
,
@required
this
.
colorTween
,
@required
this
.
animation
,
@required
this
.
iconSize
,
@required
this
.
selected
,
@required
this
.
item
,
})
:
super
(
key:
key
);
final
BottomNavigationBarType
type
;
final
ColorTween
colorTween
;
final
Animation
<
double
>
animation
;
final
double
iconSize
;
final
bool
selected
;
final
BottomNavigationBarItem
item
;
@override
Widget
build
(
BuildContext
context
)
{
double
tweenStart
;
Color
iconColor
;
switch
(
type
)
{
...
...
@@ -253,8 +330,22 @@ class _BottomNavigationTile extends StatelessWidget {
),
);
}
}
class
_FixedLabel
extends
StatelessWidget
{
const
_FixedLabel
({
Key
key
,
@required
this
.
colorTween
,
@required
this
.
animation
,
@required
this
.
item
,
})
:
super
(
key:
key
);
final
ColorTween
colorTween
;
final
Animation
<
double
>
animation
;
final
BottomNavigationBarItem
item
;
Widget
_buildFixedLabel
()
{
@override
Widget
build
(
BuildContext
context
)
{
return
Align
(
alignment:
Alignment
.
bottomCenter
,
heightFactor:
1.0
,
...
...
@@ -284,8 +375,20 @@ class _BottomNavigationTile extends StatelessWidget {
),
);
}
}
class
_ShiftingLabel
extends
StatelessWidget
{
const
_ShiftingLabel
({
Key
key
,
@required
this
.
animation
,
@required
this
.
item
,
})
:
super
(
key:
key
);
Widget
_buildShiftingLabel
()
{
final
Animation
<
double
>
animation
;
final
BottomNavigationBarItem
item
;
@override
Widget
build
(
BuildContext
context
)
{
return
Align
(
alignment:
Alignment
.
bottomCenter
,
heightFactor:
1.0
,
...
...
@@ -314,53 +417,6 @@ class _BottomNavigationTile extends StatelessWidget {
),
);
}
@override
Widget
build
(
BuildContext
context
)
{
// In order to use the flex container to grow the tile during animation, we
// need to divide the changes in flex allotment into smaller pieces to
// produce smooth animation. We do this by multiplying the flex value
// (which is an integer) by a large number.
int
size
;
Widget
label
;
switch
(
type
)
{
case
BottomNavigationBarType
.
fixed
:
size
=
1
;
label
=
_buildFixedLabel
();
break
;
case
BottomNavigationBarType
.
shifting
:
size
=
(
flex
*
1000.0
).
round
();
label
=
_buildShiftingLabel
();
break
;
}
return
Expanded
(
flex:
size
,
child:
Semantics
(
container:
true
,
header:
true
,
selected:
selected
,
child:
Stack
(
children:
<
Widget
>[
InkResponse
(
onTap:
onTap
,
child:
Column
(
crossAxisAlignment:
CrossAxisAlignment
.
center
,
mainAxisAlignment:
MainAxisAlignment
.
spaceBetween
,
mainAxisSize:
MainAxisSize
.
min
,
children:
<
Widget
>[
_buildIcon
(),
label
,
],
),
),
Semantics
(
label:
indexLabel
,
)
],
),
),
);
}
}
class
_BottomNavigationBarState
extends
State
<
BottomNavigationBar
>
with
TickerProviderStateMixin
{
...
...
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