Unverified Commit 6c07863f authored by MH Johnson's avatar MH Johnson Committed by GitHub

[Material] Refactor _build<Widget> methods in BottomNavBar (#26722)

parent 9f72c5fb
...@@ -220,7 +220,84 @@ class _BottomNavigationTile extends StatelessWidget { ...@@ -220,7 +220,84 @@ class _BottomNavigationTile extends StatelessWidget {
final bool selected; final bool selected;
final String indexLabel; 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; double tweenStart;
Color iconColor; Color iconColor;
switch (type) { switch (type) {
...@@ -253,8 +330,22 @@ class _BottomNavigationTile extends StatelessWidget { ...@@ -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( return Align(
alignment: Alignment.bottomCenter, alignment: Alignment.bottomCenter,
heightFactor: 1.0, heightFactor: 1.0,
...@@ -284,8 +375,20 @@ class _BottomNavigationTile extends StatelessWidget { ...@@ -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( return Align(
alignment: Alignment.bottomCenter, alignment: Alignment.bottomCenter,
heightFactor: 1.0, heightFactor: 1.0,
...@@ -314,53 +417,6 @@ class _BottomNavigationTile extends StatelessWidget { ...@@ -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 { class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerProviderStateMixin {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment