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
c8832045
Commit
c8832045
authored
Jan 15, 2020
by
Tianguang
Committed by
Flutter GitHub Bot
Jan 15, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow IconButton to have smaller sizes (#47457)
parent
5d37de26
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
104 additions
and
6 deletions
+104
-6
button.dart
packages/flutter/lib/src/material/button.dart
+1
-4
icon_button.dart
packages/flutter/lib/src/material/icon_button.dart
+30
-2
theme_data.dart
packages/flutter/lib/src/material/theme_data.dart
+10
-0
icon_button_test.dart
packages/flutter/test/material/icon_button_test.dart
+63
-0
No files found.
packages/flutter/lib/src/material/button.dart
View file @
c8832045
...
...
@@ -366,10 +366,7 @@ class _RawMaterialButtonState extends State<RawMaterialButton> {
final
Color
effectiveTextColor
=
MaterialStateProperty
.
resolveAs
<
Color
>(
widget
.
textStyle
?.
color
,
_states
);
final
ShapeBorder
effectiveShape
=
MaterialStateProperty
.
resolveAs
<
ShapeBorder
>(
widget
.
shape
,
_states
);
final
Offset
densityAdjustment
=
widget
.
visualDensity
.
baseSizeAdjustment
;
final
BoxConstraints
effectiveConstraints
=
widget
.
constraints
.
copyWith
(
minWidth:
widget
.
constraints
.
minWidth
!=
null
?
(
widget
.
constraints
.
minWidth
+
densityAdjustment
.
dx
).
clamp
(
0.0
,
double
.
infinity
)
as
double
:
null
,
minHeight:
widget
.
constraints
.
minWidth
!=
null
?
(
widget
.
constraints
.
minHeight
+
densityAdjustment
.
dy
).
clamp
(
0.0
,
double
.
infinity
)
as
double
:
null
,
);
final
BoxConstraints
effectiveConstraints
=
widget
.
visualDensity
.
effectiveConstraints
(
widget
.
constraints
);
final
EdgeInsetsGeometry
padding
=
widget
.
padding
.
add
(
EdgeInsets
.
only
(
left:
densityAdjustment
.
dx
,
...
...
packages/flutter/lib/src/material/icon_button.dart
View file @
c8832045
...
...
@@ -154,6 +154,7 @@ class IconButton extends StatelessWidget {
this
.
autofocus
=
false
,
this
.
tooltip
,
this
.
enableFeedback
=
true
,
this
.
constraints
,
})
:
assert
(
iconSize
!=
null
),
assert
(
padding
!=
null
),
assert
(
alignment
!=
null
),
...
...
@@ -288,6 +289,26 @@ class IconButton extends StatelessWidget {
/// * [Feedback] for providing platform-specific feedback to certain actions.
final
bool
enableFeedback
;
/// Optional size constraints for the button.
///
/// When unspecified, defaults to:
/// ```dart
/// const BoxConstraints(
/// minWidth: kMinInteractiveDimension,
/// minHeight: kMinInteractiveDimension,
/// )
/// ```
/// where [kMinInteractiveDimension] is 48.0, and then with visual density
/// applied.
///
/// The default constraints ensure that the button is accessible.
/// Specifying this parameter enables creation of buttons smaller than
/// the minimum size, but it is not recommended.
///
/// The visual density uses the [visualDensity] parameter if specified,
/// and `Theme.of(context).visualDensity` otherwise.
final
BoxConstraints
constraints
;
@override
Widget
build
(
BuildContext
context
)
{
assert
(
debugCheckHasMaterial
(
context
));
...
...
@@ -298,9 +319,16 @@ class IconButton extends StatelessWidget {
else
currentColor
=
disabledColor
??
theme
.
disabledColor
;
final
Offset
densityAdjustment
=
(
visualDensity
??
theme
.
visualDensity
).
baseSizeAdjustment
;
final
VisualDensity
effectiveVisualDensity
=
visualDensity
??
theme
.
visualDensity
;
final
BoxConstraints
unadjustedConstraints
=
constraints
??
const
BoxConstraints
(
minWidth:
_kMinButtonSize
,
minHeight:
_kMinButtonSize
,
);
final
BoxConstraints
adjustedConstraints
=
effectiveVisualDensity
.
effectiveConstraints
(
unadjustedConstraints
);
Widget
result
=
ConstrainedBox
(
constraints:
BoxConstraints
(
minWidth:
_kMinButtonSize
+
densityAdjustment
.
dx
,
minHeight:
_kMinButtonSize
+
densityAdjustment
.
dy
)
,
constraints:
adjustedConstraints
,
child:
Padding
(
padding:
padding
,
child:
SizedBox
(
...
...
packages/flutter/lib/src/material/theme_data.dart
View file @
c8832045
...
...
@@ -1815,6 +1815,16 @@ class VisualDensity extends Diagnosticable {
);
}
/// Return a copy of [constraints] whose minimum width and height have been
/// updated with the [baseSizeAdjustment].
BoxConstraints
effectiveConstraints
(
BoxConstraints
constraints
){
assert
(
constraints
!=
null
&&
constraints
.
debugAssertIsValid
());
return
constraints
.
copyWith
(
minWidth:
(
constraints
.
minWidth
+
baseSizeAdjustment
.
dx
).
clamp
(
0.0
,
double
.
infinity
).
toDouble
(),
minHeight:
(
constraints
.
minHeight
+
baseSizeAdjustment
.
dy
).
clamp
(
0.0
,
double
.
infinity
).
toDouble
(),
);
}
@override
bool
operator
==(
Object
other
)
{
if
(
other
.
runtimeType
!=
runtimeType
)
{
...
...
packages/flutter/test/material/icon_button_test.dart
View file @
c8832045
...
...
@@ -75,6 +75,69 @@ void main() {
expect
(
iconButton
.
size
,
const
Size
(
70.0
,
70.0
));
});
testWidgets
(
'Small icons with non-null constraints can be <48dp'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
wrap
(
child:
IconButton
(
iconSize:
10.0
,
onPressed:
mockOnPressedFunction
,
icon:
const
Icon
(
Icons
.
link
),
constraints:
const
BoxConstraints
(),
),
),
);
final
RenderBox
iconButton
=
tester
.
renderObject
(
find
.
byType
(
IconButton
));
// By default IconButton has a padding of 8.0 on all sides, so both
// width and height are 10.0 + 2 * 8.0 = 26.0
expect
(
iconButton
.
size
,
const
Size
(
26.0
,
26.0
));
});
testWidgets
(
'Small icons with non-null constraints and custom padding can be <48dp'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
wrap
(
child:
IconButton
(
iconSize:
10.0
,
padding:
const
EdgeInsets
.
all
(
3.0
),
onPressed:
mockOnPressedFunction
,
icon:
const
Icon
(
Icons
.
link
),
constraints:
const
BoxConstraints
(),
),
),
);
final
RenderBox
iconButton
=
tester
.
renderObject
(
find
.
byType
(
IconButton
));
// This IconButton has a padding of 3.0 on all sides, so both
// width and height are 10.0 + 2 * 3.0 = 16.0
expect
(
iconButton
.
size
,
const
Size
(
16.0
,
16.0
));
});
testWidgets
(
'Small icons comply with VisualDensity requirements'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
wrap
(
child:
Theme
(
data:
ThemeData
(
visualDensity:
const
VisualDensity
(
horizontal:
1
,
vertical:
-
1
)),
child:
IconButton
(
iconSize:
10.0
,
onPressed:
mockOnPressedFunction
,
icon:
const
Icon
(
Icons
.
link
),
constraints:
const
BoxConstraints
(
minWidth:
32.0
,
minHeight:
32.0
),
),
),
),
);
final
RenderBox
iconButton
=
tester
.
renderObject
(
find
.
byType
(
IconButton
));
// VisualDensity(horizontal: 1, vertical: -1) increases the icon's
// width by 4 pixels and decreases its height by 4 pixels, giving
// final width 32.0 + 4.0 = 36.0 and
// final height 32.0 - 4.0 = 28.0
expect
(
iconButton
.
size
,
const
Size
(
36.0
,
28.0
));
});
testWidgets
(
'test default icon buttons are constrained'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
wrap
(
...
...
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