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
2719f65b
Unverified
Commit
2719f65b
authored
Nov 16, 2021
by
Viren Khatri
Committed by
GitHub
Nov 16, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated IconButton.iconSize to get value from theme (#87643)
parent
c7572150
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
123 additions
and
9 deletions
+123
-9
icon_button.dart
packages/flutter/lib/src/material/icon_button.dart
+10
-9
icon_button_test.dart
packages/flutter/test/material/icon_button_test.dart
+113
-0
No files found.
packages/flutter/lib/src/material/icon_button.dart
View file @
2719f65b
...
...
@@ -116,7 +116,7 @@ class IconButton extends StatelessWidget {
/// or an [ImageIcon].
const
IconButton
({
Key
?
key
,
this
.
iconSize
=
24.0
,
this
.
iconSize
,
this
.
visualDensity
,
this
.
padding
=
const
EdgeInsets
.
all
(
8.0
),
this
.
alignment
=
Alignment
.
center
,
...
...
@@ -135,8 +135,7 @@ class IconButton extends StatelessWidget {
this
.
enableFeedback
=
true
,
this
.
constraints
,
required
this
.
icon
,
})
:
assert
(
iconSize
!=
null
),
assert
(
padding
!=
null
),
})
:
assert
(
padding
!=
null
),
assert
(
alignment
!=
null
),
assert
(
splashRadius
==
null
||
splashRadius
>
0
),
assert
(
autofocus
!=
null
),
...
...
@@ -145,7 +144,8 @@ class IconButton extends StatelessWidget {
/// The size of the icon inside the button.
///
/// This property must not be null. It defaults to 24.0.
/// If null, uses [IconThemeData.size]. If it is also null, the default size
/// is 24.0.
///
/// The size given here is passed down to the widget in the [icon] property
/// via an [IconTheme]. Setting the size here instead of in, for example, the
...
...
@@ -153,7 +153,7 @@ class IconButton extends StatelessWidget {
/// fit the [Icon]. If you were to set the size of the [Icon] using
/// [Icon.size] instead, then the [IconButton] would default to 24.0 and then
/// the [Icon] itself would likely get clipped.
final
double
iconSize
;
final
double
?
iconSize
;
/// Defines how compact the icon button's layout will be.
///
...
...
@@ -319,19 +319,20 @@ class IconButton extends StatelessWidget {
minHeight:
_kMinButtonSize
,
);
final
BoxConstraints
adjustedConstraints
=
effectiveVisualDensity
.
effectiveConstraints
(
unadjustedConstraints
);
final
double
effectiveIconSize
=
iconSize
??
IconTheme
.
of
(
context
).
size
??
24.0
;
Widget
result
=
ConstrainedBox
(
constraints:
adjustedConstraints
,
child:
Padding
(
padding:
padding
,
child:
SizedBox
(
height:
i
conSize
,
width:
i
conSize
,
height:
effectiveI
conSize
,
width:
effectiveI
conSize
,
child:
Align
(
alignment:
alignment
,
child:
IconTheme
.
merge
(
data:
IconThemeData
(
size:
i
conSize
,
size:
effectiveI
conSize
,
color:
currentColor
,
),
child:
icon
,
...
...
@@ -364,7 +365,7 @@ class IconButton extends StatelessWidget {
splashColor:
splashColor
??
theme
.
splashColor
,
radius:
splashRadius
??
math
.
max
(
Material
.
defaultSplashRadius
,
(
i
conSize
+
math
.
min
(
padding
.
horizontal
,
padding
.
vertical
))
*
0.7
,
(
effectiveI
conSize
+
math
.
min
(
padding
.
horizontal
,
padding
.
vertical
))
*
0.7
,
// x 0.5 for diameter -> radius and + 40% overflow derived from other Material apps.
),
child:
result
,
...
...
packages/flutter/test/material/icon_button_test.dart
View file @
2719f65b
...
...
@@ -75,6 +75,119 @@ void main() {
expect
(
iconButton
.
size
,
const
Size
(
70.0
,
70.0
));
});
testWidgets
(
'when both iconSize and IconTheme.of(context).size are null, size falls back to 24.0'
,
(
WidgetTester
tester
)
async
{
final
FocusNode
focusNode
=
FocusNode
(
debugLabel:
'Ink Focus'
);
await
tester
.
pumpWidget
(
wrap
(
child:
IconTheme
(
data:
const
IconThemeData
(
size:
null
),
child:
IconButton
(
focusNode:
focusNode
,
onPressed:
mockOnPressedFunction
.
handler
,
icon:
const
Icon
(
Icons
.
link
),
),
)
),
);
final
RenderBox
icon
=
tester
.
renderObject
(
find
.
byType
(
Icon
));
expect
(
icon
.
size
,
const
Size
(
24.0
,
24.0
));
});
testWidgets
(
'when null, iconSize is overridden by closest IconTheme'
,
(
WidgetTester
tester
)
async
{
RenderBox
icon
;
await
tester
.
pumpWidget
(
wrap
(
child:
IconTheme
(
data:
const
IconThemeData
(
size:
10
),
child:
IconButton
(
onPressed:
mockOnPressedFunction
.
handler
,
icon:
const
Icon
(
Icons
.
link
),
),
)
),
);
icon
=
tester
.
renderObject
(
find
.
byType
(
Icon
));
expect
(
icon
.
size
,
const
Size
(
10.0
,
10.0
));
await
tester
.
pumpWidget
(
wrap
(
child:
Theme
(
data:
ThemeData
(
iconTheme:
const
IconThemeData
(
size:
10
),
),
child:
IconButton
(
onPressed:
mockOnPressedFunction
.
handler
,
icon:
const
Icon
(
Icons
.
link
),
),
)
),
);
icon
=
tester
.
renderObject
(
find
.
byType
(
Icon
));
expect
(
icon
.
size
,
const
Size
(
10.0
,
10.0
));
await
tester
.
pumpWidget
(
wrap
(
child:
Theme
(
data:
ThemeData
(
iconTheme:
const
IconThemeData
(
size:
20
),
),
child:
IconTheme
(
data:
const
IconThemeData
(
size:
10
),
child:
IconButton
(
onPressed:
mockOnPressedFunction
.
handler
,
icon:
const
Icon
(
Icons
.
link
),
),
),
)
),
);
icon
=
tester
.
renderObject
(
find
.
byType
(
Icon
));
expect
(
icon
.
size
,
const
Size
(
10.0
,
10.0
));
await
tester
.
pumpWidget
(
wrap
(
child:
IconTheme
(
data:
const
IconThemeData
(
size:
20
),
child:
Theme
(
data:
ThemeData
(
iconTheme:
const
IconThemeData
(
size:
10
),
),
child:
IconButton
(
onPressed:
mockOnPressedFunction
.
handler
,
icon:
const
Icon
(
Icons
.
link
),
),
),
)
),
);
icon
=
tester
.
renderObject
(
find
.
byType
(
Icon
));
expect
(
icon
.
size
,
const
Size
(
10.0
,
10.0
));
});
testWidgets
(
'when non-null, iconSize precedes IconTheme.of(context).size'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
wrap
(
child:
IconTheme
(
data:
const
IconThemeData
(
size:
30.0
),
child:
IconButton
(
iconSize:
10.0
,
onPressed:
mockOnPressedFunction
.
handler
,
icon:
const
Icon
(
Icons
.
link
),
),
)
),
);
final
RenderBox
icon
=
tester
.
renderObject
(
find
.
byType
(
Icon
));
expect
(
icon
.
size
,
const
Size
(
10.0
,
10.0
));
});
testWidgets
(
'Small icons with non-null constraints can be <48dp'
,
(
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