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
dd1c22e3
Unverified
Commit
dd1c22e3
authored
Sep 12, 2018
by
Jonah Williams
Committed by
GitHub
Sep 12, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix_some_padding (#20967)
parent
de7ad06d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
108 additions
and
17 deletions
+108
-17
button_bar.dart
packages/flutter/lib/src/material/button_bar.dart
+30
-16
button_theme.dart
packages/flutter/lib/src/material/button_theme.dart
+27
-1
button_bar_test.dart
packages/flutter/test/material/button_bar_test.dart
+50
-0
button_theme_test.dart
packages/flutter/test/material/button_theme_test.dart
+1
-0
No files found.
packages/flutter/lib/src/material/button_bar.dart
View file @
dd1c22e3
...
...
@@ -47,23 +47,37 @@ class ButtonBar extends StatelessWidget {
@override
Widget
build
(
BuildContext
context
)
{
final
ButtonThemeData
buttonTheme
=
ButtonTheme
.
of
(
context
);
// We divide by 4.0 because we want half of the average of the left and right padding.
final
double
paddingUnit
=
ButtonTheme
.
of
(
context
).
padding
.
horizontal
/
4.0
;
return
Padding
(
padding:
EdgeInsets
.
symmetric
(
vertical:
2.0
*
paddingUnit
,
horizontal:
paddingUnit
),
child:
Row
(
mainAxisAlignment:
alignment
,
mainAxisSize:
mainAxisSize
,
children:
children
.
map
<
Widget
>((
Widget
child
)
{
return
Padding
(
padding:
EdgeInsets
.
symmetric
(
horizontal:
paddingUnit
),
child:
child
);
}).
toList
()
)
final
double
paddingUnit
=
buttonTheme
.
padding
.
horizontal
/
4.0
;
final
Widget
child
=
Row
(
mainAxisAlignment:
alignment
,
mainAxisSize:
mainAxisSize
,
children:
children
.
map
<
Widget
>((
Widget
child
)
{
return
Padding
(
padding:
EdgeInsets
.
symmetric
(
horizontal:
paddingUnit
),
child:
child
);
}).
toList
()
);
switch
(
buttonTheme
.
layoutBehavior
)
{
case
ButtonBarLayoutBehavior
.
padded
:
return
Padding
(
padding:
EdgeInsets
.
symmetric
(
vertical:
2.0
*
paddingUnit
,
horizontal:
paddingUnit
),
child:
child
,
);
case
ButtonBarLayoutBehavior
.
constrained
:
return
Container
(
padding:
EdgeInsets
.
symmetric
(
horizontal:
paddingUnit
),
constraints:
const
BoxConstraints
(
minHeight:
52.0
),
alignment:
Alignment
.
center
,
child:
child
,
);
}
assert
(
false
);
return
null
;
}
}
packages/flutter/lib/src/material/button_theme.dart
View file @
dd1c22e3
...
...
@@ -26,6 +26,19 @@ enum ButtonTextTheme {
primary
,
}
/// Used with [ButtonTheme] and [ButtonThemeData] to define how the button bar
/// should size itself with either constraints or internal padding.
enum
ButtonBarLayoutBehavior
{
/// Button bars will be constrained to a minimum height of 52.
///
/// This setting is require to create button bars which conform to the
/// material specification.
constrained
,
/// Button bars will calculate their padding from the button theme padding.
padded
,
}
/// Used with [ButtonThemeData] to configure the color and geometry of buttons.
///
/// A button theme can be specified as part of the overall Material theme
...
...
@@ -60,6 +73,7 @@ class ButtonTheme extends InheritedWidget {
ButtonTheme
({
Key
key
,
ButtonTextTheme
textTheme
=
ButtonTextTheme
.
normal
,
ButtonBarLayoutBehavior
layoutBehavior
=
ButtonBarLayoutBehavior
.
padded
,
double
minWidth
=
88.0
,
double
height
=
36.0
,
EdgeInsetsGeometry
padding
,
...
...
@@ -70,13 +84,15 @@ class ButtonTheme extends InheritedWidget {
assert
(
minWidth
!=
null
&&
minWidth
>=
0.0
),
assert
(
height
!=
null
&&
height
>=
0.0
),
assert
(
alignedDropdown
!=
null
),
assert
(
layoutBehavior
!=
null
),
data
=
ButtonThemeData
(
textTheme:
textTheme
,
minWidth:
minWidth
,
height:
height
,
padding:
padding
,
shape:
shape
,
alignedDropdown:
alignedDropdown
alignedDropdown:
alignedDropdown
,
layoutBehavior:
layoutBehavior
,
),
super
(
key:
key
,
child:
child
);
...
...
@@ -113,6 +129,7 @@ class ButtonTheme extends InheritedWidget {
ShapeBorder
shape
,
bool
alignedDropdown
=
false
,
Widget
child
,
ButtonBarLayoutBehavior
layoutBehavior
=
ButtonBarLayoutBehavior
.
padded
,
})
:
assert
(
textTheme
!=
null
),
assert
(
minWidth
!=
null
&&
minWidth
>=
0.0
),
assert
(
height
!=
null
&&
height
>=
0.0
),
...
...
@@ -124,6 +141,7 @@ class ButtonTheme extends InheritedWidget {
padding:
padding
,
shape:
shape
,
alignedDropdown:
alignedDropdown
,
layoutBehavior:
layoutBehavior
,
),
super
(
key:
key
,
child:
child
);
...
...
@@ -162,11 +180,13 @@ class ButtonThemeData extends Diagnosticable {
this
.
height
=
36.0
,
EdgeInsetsGeometry
padding
,
ShapeBorder
shape
,
this
.
layoutBehavior
=
ButtonBarLayoutBehavior
.
padded
,
this
.
alignedDropdown
=
false
,
})
:
assert
(
textTheme
!=
null
),
assert
(
minWidth
!=
null
&&
minWidth
>=
0.0
),
assert
(
height
!=
null
&&
height
>=
0.0
),
assert
(
alignedDropdown
!=
null
),
assert
(
layoutBehavior
!=
null
),
_padding
=
padding
,
_shape
=
shape
;
...
...
@@ -187,6 +207,12 @@ class ButtonThemeData extends Diagnosticable {
/// size, internal padding, and shape.
final
ButtonTextTheme
textTheme
;
/// Defines whether a button bar should size itself with a minimum size
/// constraint or padding.
///
/// Defaults to [ButtonBarLayoutBehavior.padded].
final
ButtonBarLayoutBehavior
layoutBehavior
;
/// Simply a convenience that returns [minWidth] and [height] as a
/// [BoxConstraints] object:
/// ```dart
...
...
packages/flutter/test/material/button_bar_test.dart
View file @
dd1c22e3
...
...
@@ -14,4 +14,54 @@ void main() {
),
);
});
testWidgets
(
'ButtonBar has a min height of 52 when using ButtonBarLayoutBehavior.constrained'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
SingleChildScrollView
(
child:
ListBody
(
children:
<
Widget
>[
ButtonTheme
.
bar
(
layoutBehavior:
ButtonBarLayoutBehavior
.
constrained
,
child:
const
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
ButtonBar
(
children:
<
Widget
>[
SizedBox
(
width:
10.0
,
height:
10.0
),
],
),
),
),
],
),
),
);
final
Finder
buttonBar
=
find
.
byType
(
ButtonBar
);
expect
(
tester
.
getBottomRight
(
buttonBar
).
dy
-
tester
.
getTopRight
(
buttonBar
).
dy
,
52.0
);
});
testWidgets
(
'ButtonBar has padding applied when using ButtonBarLayoutBehavior.padded'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
SingleChildScrollView
(
child:
ListBody
(
children:
<
Widget
>[
ButtonTheme
.
bar
(
layoutBehavior:
ButtonBarLayoutBehavior
.
padded
,
child:
const
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
ButtonBar
(
children:
<
Widget
>[
SizedBox
(
width:
10.0
,
height:
10.0
),
],
),
),
),
],
),
),
);
final
Finder
buttonBar
=
find
.
byType
(
ButtonBar
);
expect
(
tester
.
getBottomRight
(
buttonBar
).
dy
-
tester
.
getTopRight
(
buttonBar
).
dy
,
26.0
);
});
}
packages/flutter/test/material/button_theme_test.dart
View file @
dd1c22e3
...
...
@@ -15,6 +15,7 @@ void main() {
borderRadius:
BorderRadius
.
all
(
Radius
.
circular
(
2.0
)),
));
expect
(
theme
.
alignedDropdown
,
false
);
expect
(
theme
.
layoutBehavior
,
ButtonBarLayoutBehavior
.
padded
);
});
test
(
'ButtonThemeData default overrides'
,
()
{
...
...
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