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
76d41143
Unverified
Commit
76d41143
authored
Jan 25, 2021
by
Chinmoy
Committed by
GitHub
Jan 25, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added padding property to NavigationRail items (#69404)
parent
c89d6498
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
170 additions
and
34 deletions
+170
-34
navigation_rail.dart
packages/flutter/lib/src/material/navigation_rail.dart
+47
-34
navigation_rail_test.dart
packages/flutter/test/material/navigation_rail_test.dart
+123
-0
No files found.
packages/flutter/lib/src/material/navigation_rail.dart
View file @
76d41143
...
@@ -496,6 +496,7 @@ class _NavigationRailState extends State<NavigationRail> with TickerProviderStat
...
@@ -496,6 +496,7 @@ class _NavigationRailState extends State<NavigationRail> with TickerProviderStat
labelType:
labelType
,
labelType:
labelType
,
iconTheme:
widget
.
selectedIndex
==
i
?
selectedIconTheme
:
unselectedIconTheme
,
iconTheme:
widget
.
selectedIndex
==
i
?
selectedIconTheme
:
unselectedIconTheme
,
labelTextStyle:
widget
.
selectedIndex
==
i
?
selectedLabelTextStyle
:
unselectedLabelTextStyle
,
labelTextStyle:
widget
.
selectedIndex
==
i
?
selectedLabelTextStyle
:
unselectedLabelTextStyle
,
padding:
widget
.
destinations
[
i
].
padding
,
onTap:
()
{
onTap:
()
{
widget
.
onDestinationSelected
!(
i
);
widget
.
onDestinationSelected
!(
i
);
},
},
...
@@ -579,6 +580,7 @@ class _RailDestination extends StatelessWidget {
...
@@ -579,6 +580,7 @@ class _RailDestination extends StatelessWidget {
required
this
.
labelTextStyle
,
required
this
.
labelTextStyle
,
required
this
.
onTap
,
required
this
.
onTap
,
required
this
.
indexLabel
,
required
this
.
indexLabel
,
this
.
padding
,
})
:
assert
(
minWidth
!=
null
),
})
:
assert
(
minWidth
!=
null
),
assert
(
minExtendedWidth
!=
null
),
assert
(
minExtendedWidth
!=
null
),
assert
(
icon
!=
null
),
assert
(
icon
!=
null
),
...
@@ -609,6 +611,7 @@ class _RailDestination extends StatelessWidget {
...
@@ -609,6 +611,7 @@ class _RailDestination extends StatelessWidget {
final
TextStyle
labelTextStyle
;
final
TextStyle
labelTextStyle
;
final
VoidCallback
onTap
;
final
VoidCallback
onTap
;
final
String
indexLabel
;
final
String
indexLabel
;
final
EdgeInsetsGeometry
?
padding
;
final
Animation
<
double
>
_positionAnimation
;
final
Animation
<
double
>
_positionAnimation
;
...
@@ -634,7 +637,9 @@ class _RailDestination extends StatelessWidget {
...
@@ -634,7 +637,9 @@ class _RailDestination extends StatelessWidget {
),
),
);
);
if
(
extendedTransitionAnimation
.
value
==
0
)
{
if
(
extendedTransitionAnimation
.
value
==
0
)
{
content
=
Stack
(
content
=
Padding
(
padding:
padding
??
EdgeInsets
.
zero
,
child:
Stack
(
children:
<
Widget
>[
children:
<
Widget
>[
iconPart
,
iconPart
,
// For semantics when label is not showing,
// For semantics when label is not showing,
...
@@ -648,9 +653,12 @@ class _RailDestination extends StatelessWidget {
...
@@ -648,9 +653,12 @@ class _RailDestination extends StatelessWidget {
),
),
),
),
]
]
),
);
);
}
else
{
}
else
{
content
=
ConstrainedBox
(
content
=
Padding
(
padding:
padding
??
EdgeInsets
.
zero
,
child:
ConstrainedBox
(
constraints:
BoxConstraints
(
constraints:
BoxConstraints
(
minWidth:
lerpDouble
(
minWidth
,
minExtendedWidth
,
extendedTransitionAnimation
.
value
)!,
minWidth:
lerpDouble
(
minWidth
,
minExtendedWidth
,
extendedTransitionAnimation
.
value
)!,
),
),
...
@@ -672,6 +680,7 @@ class _RailDestination extends StatelessWidget {
...
@@ -672,6 +680,7 @@ class _RailDestination extends StatelessWidget {
],
],
),
),
),
),
),
);
);
}
}
break
;
break
;
...
@@ -683,7 +692,7 @@ class _RailDestination extends StatelessWidget {
...
@@ -683,7 +692,7 @@ class _RailDestination extends StatelessWidget {
minWidth:
minWidth
,
minWidth:
minWidth
,
minHeight:
minWidth
,
minHeight:
minWidth
,
),
),
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
_horizontalDestinationPadding
),
padding:
padding
??
const
EdgeInsets
.
symmetric
(
horizontal:
_horizontalDestinationPadding
),
child:
ClipRect
(
child:
ClipRect
(
child:
Column
(
child:
Column
(
mainAxisSize:
MainAxisSize
.
min
,
mainAxisSize:
MainAxisSize
.
min
,
...
@@ -713,7 +722,7 @@ class _RailDestination extends StatelessWidget {
...
@@ -713,7 +722,7 @@ class _RailDestination extends StatelessWidget {
minWidth:
minWidth
,
minWidth:
minWidth
,
minHeight:
minWidth
,
minHeight:
minWidth
,
),
),
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
_horizontalDestinationPadding
),
padding:
padding
??
const
EdgeInsets
.
symmetric
(
horizontal:
_horizontalDestinationPadding
),
child:
Column
(
child:
Column
(
children:
<
Widget
>[
children:
<
Widget
>[
const
SizedBox
(
height:
_verticalDestinationPaddingWithLabel
),
const
SizedBox
(
height:
_verticalDestinationPaddingWithLabel
),
...
@@ -811,6 +820,7 @@ class NavigationRailDestination {
...
@@ -811,6 +820,7 @@ class NavigationRailDestination {
required
this
.
icon
,
required
this
.
icon
,
Widget
?
selectedIcon
,
Widget
?
selectedIcon
,
this
.
label
,
this
.
label
,
this
.
padding
,
})
:
selectedIcon
=
selectedIcon
??
icon
,
})
:
selectedIcon
=
selectedIcon
??
icon
,
assert
(
icon
!=
null
);
assert
(
icon
!=
null
);
...
@@ -848,6 +858,9 @@ class NavigationRailDestination {
...
@@ -848,6 +858,9 @@ class NavigationRailDestination {
/// still used for semantics, and may still be used if
/// still used for semantics, and may still be used if
/// [NavigationRail.extended] is true.
/// [NavigationRail.extended] is true.
final
Widget
?
label
;
final
Widget
?
label
;
/// The amount of space to inset the destination item.
final
EdgeInsetsGeometry
?
padding
;
}
}
class
_ExtendedNavigationRailAnimation
extends
InheritedWidget
{
class
_ExtendedNavigationRailAnimation
extends
InheritedWidget
{
...
...
packages/flutter/test/material/navigation_rail_test.dart
View file @
76d41143
...
@@ -2022,6 +2022,129 @@ void main() {
...
@@ -2022,6 +2022,129 @@ void main() {
semantics
.
dispose
();
semantics
.
dispose
();
});
});
testWidgets
(
'NavigationRailDestination padding properly applied - NavigationRailLabelType.all'
,
(
WidgetTester
tester
)
async
{
const
EdgeInsets
defaultPadding
=
EdgeInsets
.
symmetric
(
horizontal:
8.0
);
const
EdgeInsets
secondItemPadding
=
EdgeInsets
.
symmetric
(
vertical:
30.0
);
const
EdgeInsets
thirdItemPadding
=
EdgeInsets
.
symmetric
(
horizontal:
10.0
);
await
_pumpNavigationRail
(
tester
,
navigationRail:
NavigationRail
(
labelType:
NavigationRailLabelType
.
all
,
selectedIndex:
0
,
destinations:
const
<
NavigationRailDestination
>[
NavigationRailDestination
(
icon:
Icon
(
Icons
.
favorite_border
),
selectedIcon:
Icon
(
Icons
.
favorite
),
label:
Text
(
'Abc'
),
),
NavigationRailDestination
(
icon:
Icon
(
Icons
.
bookmark_border
),
selectedIcon:
Icon
(
Icons
.
bookmark
),
label:
Text
(
'Def'
),
padding:
secondItemPadding
,
),
NavigationRailDestination
(
icon:
Icon
(
Icons
.
star_border
),
selectedIcon:
Icon
(
Icons
.
star
),
label:
Text
(
'Ghi'
),
padding:
thirdItemPadding
,
),
],
),
);
final
Padding
firstItem
=
tester
.
widget
<
Padding
>(
find
.
widgetWithText
(
Padding
,
'Abc'
));
final
Padding
secondItem
=
tester
.
widget
<
Padding
>(
find
.
widgetWithText
(
Padding
,
'Def'
));
final
Padding
thirdItem
=
tester
.
widget
<
Padding
>(
find
.
widgetWithText
(
Padding
,
'Ghi'
));
expect
(
firstItem
.
padding
,
defaultPadding
);
expect
(
secondItem
.
padding
,
secondItemPadding
);
expect
(
thirdItem
.
padding
,
thirdItemPadding
);
});
testWidgets
(
'NavigationRailDestination padding properly applied - NavigationRailLabelType.selected'
,
(
WidgetTester
tester
)
async
{
const
EdgeInsets
defaultPadding
=
EdgeInsets
.
symmetric
(
horizontal:
8.0
);
const
EdgeInsets
secondItemPadding
=
EdgeInsets
.
symmetric
(
vertical:
30.0
);
const
EdgeInsets
thirdItemPadding
=
EdgeInsets
.
symmetric
(
horizontal:
10.0
);
await
_pumpNavigationRail
(
tester
,
navigationRail:
NavigationRail
(
labelType:
NavigationRailLabelType
.
selected
,
selectedIndex:
0
,
destinations:
const
<
NavigationRailDestination
>[
NavigationRailDestination
(
icon:
Icon
(
Icons
.
favorite_border
),
selectedIcon:
Icon
(
Icons
.
favorite
),
label:
Text
(
'Abc'
),
),
NavigationRailDestination
(
icon:
Icon
(
Icons
.
bookmark_border
),
selectedIcon:
Icon
(
Icons
.
bookmark
),
label:
Text
(
'Def'
),
padding:
secondItemPadding
,
),
NavigationRailDestination
(
icon:
Icon
(
Icons
.
star_border
),
selectedIcon:
Icon
(
Icons
.
star
),
label:
Text
(
'Ghi'
),
padding:
thirdItemPadding
,
),
],
),
);
final
Padding
firstItem
=
tester
.
widget
<
Padding
>(
find
.
widgetWithText
(
Padding
,
'Abc'
));
final
Padding
secondItem
=
tester
.
widget
<
Padding
>(
find
.
widgetWithText
(
Padding
,
'Def'
));
final
Padding
thirdItem
=
tester
.
widget
<
Padding
>(
find
.
widgetWithText
(
Padding
,
'Ghi'
));
expect
(
firstItem
.
padding
,
defaultPadding
);
expect
(
secondItem
.
padding
,
secondItemPadding
);
expect
(
thirdItem
.
padding
,
thirdItemPadding
);
});
testWidgets
(
'NavigationRailDestination padding properly applied - NavigationRailLabelType.none'
,
(
WidgetTester
tester
)
async
{
const
EdgeInsets
defaultPadding
=
EdgeInsets
.
zero
;
const
EdgeInsets
secondItemPadding
=
EdgeInsets
.
symmetric
(
vertical:
30.0
);
const
EdgeInsets
thirdItemPadding
=
EdgeInsets
.
symmetric
(
horizontal:
10.0
);
await
_pumpNavigationRail
(
tester
,
navigationRail:
NavigationRail
(
labelType:
NavigationRailLabelType
.
none
,
selectedIndex:
0
,
destinations:
const
<
NavigationRailDestination
>[
NavigationRailDestination
(
icon:
Icon
(
Icons
.
favorite_border
),
selectedIcon:
Icon
(
Icons
.
favorite
),
label:
Text
(
'Abc'
),
),
NavigationRailDestination
(
icon:
Icon
(
Icons
.
bookmark_border
),
selectedIcon:
Icon
(
Icons
.
bookmark
),
label:
Text
(
'Def'
),
padding:
secondItemPadding
,
),
NavigationRailDestination
(
icon:
Icon
(
Icons
.
star_border
),
selectedIcon:
Icon
(
Icons
.
star
),
label:
Text
(
'Ghi'
),
padding:
thirdItemPadding
,
),
],
),
);
final
Padding
firstItem
=
tester
.
widget
<
Padding
>(
find
.
widgetWithText
(
Padding
,
'Abc'
));
final
Padding
secondItem
=
tester
.
widget
<
Padding
>(
find
.
widgetWithText
(
Padding
,
'Def'
));
final
Padding
thirdItem
=
tester
.
widget
<
Padding
>(
find
.
widgetWithText
(
Padding
,
'Ghi'
));
expect
(
firstItem
.
padding
,
defaultPadding
);
expect
(
secondItem
.
padding
,
secondItemPadding
);
expect
(
thirdItem
.
padding
,
thirdItemPadding
);
});
}
}
TestSemantics
_expectedSemantics
(
)
{
TestSemantics
_expectedSemantics
(
)
{
...
...
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