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
b1146549
Unverified
Commit
b1146549
authored
Mar 04, 2023
by
Qun Cheng
Committed by
GitHub
Mar 04, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add `IconButton.filled`, `IconButton.filledTonal`, `IconButton.outlined` (#121884)
parent
7979d8eb
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
1511 additions
and
249 deletions
+1511
-249
gen_defaults.dart
dev/tools/gen_defaults/bin/gen_defaults.dart
+4
-1
icon_button_template.dart
dev/tools/gen_defaults/lib/icon_button_template.dart
+229
-46
icon_button.2.dart
examples/api/lib/material/icon_button/icon_button.2.dart
+6
-49
icon_button.3.dart
examples/api/lib/material/icon_button/icon_button.3.dart
+96
-144
icon_button.dart
packages/flutter/lib/src/material/icon_button.dart
+573
-9
icon_button_test.dart
packages/flutter/test/material/icon_button_test.dart
+603
-0
No files found.
dev/tools/gen_defaults/bin/gen_defaults.dart
View file @
b1146549
...
...
@@ -158,7 +158,10 @@ Future<void> main(List<String> args) async {
FABTemplate
(
'FAB'
,
'
$materialLib
/floating_action_button.dart'
,
tokens
).
updateFile
();
FilterChipTemplate
(
'ChoiceChip'
,
'
$materialLib
/choice_chip.dart'
,
tokens
).
updateFile
();
FilterChipTemplate
(
'FilterChip'
,
'
$materialLib
/filter_chip.dart'
,
tokens
).
updateFile
();
IconButtonTemplate
(
'IconButton'
,
'
$materialLib
/icon_button.dart'
,
tokens
).
updateFile
();
IconButtonTemplate
(
'md.comp.icon-button'
,
'IconButton'
,
'
$materialLib
/icon_button.dart'
,
tokens
).
updateFile
();
IconButtonTemplate
(
'md.comp.filled-icon-button'
,
'FilledIconButton'
,
'
$materialLib
/icon_button.dart'
,
tokens
).
updateFile
();
IconButtonTemplate
(
'md.comp.filled-tonal-icon-button'
,
'FilledTonalIconButton'
,
'
$materialLib
/icon_button.dart'
,
tokens
).
updateFile
();
IconButtonTemplate
(
'md.comp.outlined-icon-button'
,
'OutlinedIconButton'
,
'
$materialLib
/icon_button.dart'
,
tokens
).
updateFile
();
InputChipTemplate
(
'InputChip'
,
'
$materialLib
/input_chip.dart'
,
tokens
).
updateFile
();
ListTileTemplate
(
'LisTile'
,
'
$materialLib
/list_tile.dart'
,
tokens
).
updateFile
();
InputDecoratorTemplate
(
'InputDecorator'
,
'
$materialLib
/input_decorator.dart'
,
tokens
).
updateFile
();
...
...
dev/tools/gen_defaults/lib/icon_button_template.dart
View file @
b1146549
This diff is collapsed.
Click to expand it.
examples/api/lib/material/icon_button/icon_button.2.dart
View file @
b1146549
...
...
@@ -52,7 +52,6 @@ class ButtonTypesGroup extends StatelessWidget {
@override
Widget
build
(
BuildContext
context
)
{
final
VoidCallback
?
onPressed
=
enabled
?
()
{}
:
null
;
final
ColorScheme
colors
=
Theme
.
of
(
context
).
colorScheme
;
return
Padding
(
padding:
const
EdgeInsets
.
all
(
4.0
),
...
...
@@ -61,56 +60,14 @@ class ButtonTypesGroup extends StatelessWidget {
children:
<
Widget
>[
IconButton
(
icon:
const
Icon
(
Icons
.
filter_drama
),
onPressed:
onPressed
),
// Use a standard IconButton with specific style to implement the
// 'Filled' type.
IconButton
(
icon:
const
Icon
(
Icons
.
filter_drama
),
onPressed:
onPressed
,
style:
IconButton
.
styleFrom
(
foregroundColor:
colors
.
onPrimary
,
backgroundColor:
colors
.
primary
,
disabledBackgroundColor:
colors
.
onSurface
.
withOpacity
(
0.12
),
hoverColor:
colors
.
onPrimary
.
withOpacity
(
0.08
),
focusColor:
colors
.
onPrimary
.
withOpacity
(
0.12
),
highlightColor:
colors
.
onPrimary
.
withOpacity
(
0.12
),
)
),
// Filled icon button
IconButton
.
filled
(
onPressed:
onPressed
,
icon:
const
Icon
(
Icons
.
filter_drama
)),
// Use a standard IconButton with specific style to implement the
// 'Filled Tonal' type.
IconButton
(
icon:
const
Icon
(
Icons
.
filter_drama
),
onPressed:
onPressed
,
style:
IconButton
.
styleFrom
(
foregroundColor:
colors
.
onSecondaryContainer
,
backgroundColor:
colors
.
secondaryContainer
,
disabledBackgroundColor:
colors
.
onSurface
.
withOpacity
(
0.12
),
hoverColor:
colors
.
onSecondaryContainer
.
withOpacity
(
0.08
),
focusColor:
colors
.
onSecondaryContainer
.
withOpacity
(
0.12
),
highlightColor:
colors
.
onSecondaryContainer
.
withOpacity
(
0.12
),
),
),
// Filled tonal icon button
IconButton
.
filledTonal
(
onPressed:
onPressed
,
icon:
const
Icon
(
Icons
.
filter_drama
)),
// Use a standard IconButton with specific style to implement the
// 'Outlined' type.
IconButton
(
icon:
const
Icon
(
Icons
.
filter_drama
),
onPressed:
onPressed
,
style:
IconButton
.
styleFrom
(
focusColor:
colors
.
onSurfaceVariant
.
withOpacity
(
0.12
),
highlightColor:
colors
.
onSurface
.
withOpacity
(
0.12
),
side:
onPressed
==
null
?
BorderSide
(
color:
Theme
.
of
(
context
).
colorScheme
.
onSurface
.
withOpacity
(
0.12
))
:
BorderSide
(
color:
colors
.
outline
),
).
copyWith
(
foregroundColor:
MaterialStateProperty
.
resolveWith
((
Set
<
MaterialState
>
states
)
{
if
(
states
.
contains
(
MaterialState
.
pressed
))
{
return
colors
.
onSurface
;
}
return
null
;
}),
),
),
// Outlined icon button
IconButton
.
outlined
(
onPressed:
onPressed
,
icon:
const
Icon
(
Icons
.
filter_drama
)),
],
),
);
...
...
examples/api/lib/material/icon_button/icon_button.3.dart
View file @
b1146549
...
...
@@ -36,153 +36,105 @@ class DemoIconToggleButtons extends StatefulWidget {
}
class
_DemoIconToggleButtonsState
extends
State
<
DemoIconToggleButtons
>
{
@override
Widget
build
(
BuildContext
context
)
{
return
const
Padding
(
padding:
EdgeInsets
.
all
(
8.0
),
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
spaceEvenly
,
children:
<
Widget
>[
Row
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
// Standard IconButton
children:
<
Widget
>[
DemoIconToggleButton
(
isEnabled:
true
),
SizedBox
(
width:
10
),
DemoIconToggleButton
(
isEnabled:
false
),
]
),
Row
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
<
Widget
>[
// Filled IconButton
DemoIconToggleButton
(
isEnabled:
true
,
getDefaultStyle:
enabledFilledButtonStyle
,),
SizedBox
(
width:
10
),
DemoIconToggleButton
(
isEnabled:
false
,
getDefaultStyle:
disabledFilledButtonStyle
,)
]
),
Row
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
<
Widget
>[
// Filled Tonal IconButton
DemoIconToggleButton
(
isEnabled:
true
,
getDefaultStyle:
enabledFilledTonalButtonStyle
,),
SizedBox
(
width:
10
),
DemoIconToggleButton
(
isEnabled:
false
,
getDefaultStyle:
disabledFilledTonalButtonStyle
,),
]
),
Row
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
<
Widget
>[
// Outlined IconButton
DemoIconToggleButton
(
isEnabled:
true
,
getDefaultStyle:
enabledOutlinedButtonStyle
,),
SizedBox
(
width:
10
),
DemoIconToggleButton
(
isEnabled:
false
,
getDefaultStyle:
disabledOutlinedButtonStyle
,),
]
),
]
),
);
}
}
class
DemoIconToggleButton
extends
StatefulWidget
{
const
DemoIconToggleButton
({
required
this
.
isEnabled
,
this
.
getDefaultStyle
,
super
.
key
});
final
bool
isEnabled
;
final
ButtonStyle
?
Function
(
bool
,
ColorScheme
)?
getDefaultStyle
;
@override
State
<
DemoIconToggleButton
>
createState
()
=>
_DemoIconToggleButtonState
();
}
class
_DemoIconToggleButtonState
extends
State
<
DemoIconToggleButton
>
{
bool
selected
=
false
;
bool
standardSelected
=
false
;
bool
filledSelected
=
false
;
bool
tonalSelected
=
false
;
bool
outlinedSelected
=
false
;
@override
Widget
build
(
BuildContext
context
)
{
final
ColorScheme
colors
=
Theme
.
of
(
context
).
colorScheme
;
final
VoidCallback
?
onPressed
=
widget
.
isEnabled
?
()
{
setState
(()
{
selected
=
!
selected
;
});
}
:
null
;
ButtonStyle
?
style
;
if
(
widget
.
getDefaultStyle
!=
null
)
{
style
=
widget
.
getDefaultStyle
!(
selected
,
colors
);
}
return
IconButton
(
isSelected:
selected
,
icon:
const
Icon
(
Icons
.
settings_outlined
),
selectedIcon:
const
Icon
(
Icons
.
settings
),
onPressed:
onPressed
,
style:
style
,
return
Column
(
mainAxisAlignment:
MainAxisAlignment
.
spaceEvenly
,
children:
<
Widget
>[
Row
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
<
Widget
>[
IconButton
(
isSelected:
standardSelected
,
icon:
const
Icon
(
Icons
.
settings_outlined
),
selectedIcon:
const
Icon
(
Icons
.
settings
),
onPressed:
()
{
setState
(()
{
standardSelected
=
!
standardSelected
;
});
},
),
const
SizedBox
(
width:
10
),
IconButton
(
isSelected:
standardSelected
,
icon:
const
Icon
(
Icons
.
settings_outlined
),
selectedIcon:
const
Icon
(
Icons
.
settings
),
onPressed:
null
,
),
],
),
Row
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
<
Widget
>[
IconButton
.
filled
(
isSelected:
filledSelected
,
icon:
const
Icon
(
Icons
.
settings_outlined
),
selectedIcon:
const
Icon
(
Icons
.
settings
),
onPressed:
()
{
setState
(()
{
filledSelected
=
!
filledSelected
;
});
},
),
const
SizedBox
(
width:
10
),
IconButton
.
filled
(
isSelected:
filledSelected
,
icon:
const
Icon
(
Icons
.
settings_outlined
),
selectedIcon:
const
Icon
(
Icons
.
settings
),
onPressed:
null
,
),
],
),
Row
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
<
Widget
>[
IconButton
.
filledTonal
(
isSelected:
tonalSelected
,
icon:
const
Icon
(
Icons
.
settings_outlined
),
selectedIcon:
const
Icon
(
Icons
.
settings
),
onPressed:
()
{
setState
(()
{
tonalSelected
=
!
tonalSelected
;
});
},
),
const
SizedBox
(
width:
10
),
IconButton
.
filledTonal
(
isSelected:
tonalSelected
,
icon:
const
Icon
(
Icons
.
settings_outlined
),
selectedIcon:
const
Icon
(
Icons
.
settings
),
onPressed:
null
,
),
],
),
Row
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
<
Widget
>[
IconButton
.
outlined
(
isSelected:
outlinedSelected
,
icon:
const
Icon
(
Icons
.
settings_outlined
),
selectedIcon:
const
Icon
(
Icons
.
settings
),
onPressed:
()
{
setState
(()
{
outlinedSelected
=
!
outlinedSelected
;
});
},
),
const
SizedBox
(
width:
10
),
IconButton
.
outlined
(
isSelected:
outlinedSelected
,
icon:
const
Icon
(
Icons
.
settings_outlined
),
selectedIcon:
const
Icon
(
Icons
.
settings
),
onPressed:
null
,
),
],
),
]
);
}
}
ButtonStyle
enabledFilledButtonStyle
(
bool
selected
,
ColorScheme
colors
)
{
return
IconButton
.
styleFrom
(
foregroundColor:
selected
?
colors
.
onPrimary
:
colors
.
primary
,
backgroundColor:
selected
?
colors
.
primary
:
colors
.
surfaceVariant
,
disabledForegroundColor:
colors
.
onSurface
.
withOpacity
(
0.38
),
disabledBackgroundColor:
colors
.
onSurface
.
withOpacity
(
0.12
),
hoverColor:
selected
?
colors
.
onPrimary
.
withOpacity
(
0.08
)
:
colors
.
primary
.
withOpacity
(
0.08
),
focusColor:
selected
?
colors
.
onPrimary
.
withOpacity
(
0.12
)
:
colors
.
primary
.
withOpacity
(
0.12
),
highlightColor:
selected
?
colors
.
onPrimary
.
withOpacity
(
0.12
)
:
colors
.
primary
.
withOpacity
(
0.12
),
);
}
ButtonStyle
disabledFilledButtonStyle
(
bool
selected
,
ColorScheme
colors
)
{
return
IconButton
.
styleFrom
(
disabledForegroundColor:
colors
.
onSurface
.
withOpacity
(
0.38
),
disabledBackgroundColor:
colors
.
onSurface
.
withOpacity
(
0.12
),
);
}
ButtonStyle
enabledFilledTonalButtonStyle
(
bool
selected
,
ColorScheme
colors
)
{
return
IconButton
.
styleFrom
(
foregroundColor:
selected
?
colors
.
onSecondaryContainer
:
colors
.
onSurfaceVariant
,
backgroundColor:
selected
?
colors
.
secondaryContainer
:
colors
.
surfaceVariant
,
hoverColor:
selected
?
colors
.
onSecondaryContainer
.
withOpacity
(
0.08
)
:
colors
.
onSurfaceVariant
.
withOpacity
(
0.08
),
focusColor:
selected
?
colors
.
onSecondaryContainer
.
withOpacity
(
0.12
)
:
colors
.
onSurfaceVariant
.
withOpacity
(
0.12
),
highlightColor:
selected
?
colors
.
onSecondaryContainer
.
withOpacity
(
0.12
)
:
colors
.
onSurfaceVariant
.
withOpacity
(
0.12
),
);
}
ButtonStyle
disabledFilledTonalButtonStyle
(
bool
selected
,
ColorScheme
colors
)
{
return
IconButton
.
styleFrom
(
disabledForegroundColor:
colors
.
onSurface
.
withOpacity
(
0.38
),
disabledBackgroundColor:
colors
.
onSurface
.
withOpacity
(
0.12
),
);
}
ButtonStyle
enabledOutlinedButtonStyle
(
bool
selected
,
ColorScheme
colors
)
{
return
IconButton
.
styleFrom
(
backgroundColor:
selected
?
colors
.
inverseSurface
:
null
,
hoverColor:
selected
?
colors
.
onInverseSurface
.
withOpacity
(
0.08
)
:
colors
.
onSurfaceVariant
.
withOpacity
(
0.08
),
focusColor:
selected
?
colors
.
onInverseSurface
.
withOpacity
(
0.12
)
:
colors
.
onSurfaceVariant
.
withOpacity
(
0.12
),
highlightColor:
selected
?
colors
.
onInverseSurface
.
withOpacity
(
0.12
)
:
colors
.
onSurface
.
withOpacity
(
0.12
),
side:
BorderSide
(
color:
colors
.
outline
),
).
copyWith
(
foregroundColor:
MaterialStateProperty
.
resolveWith
((
Set
<
MaterialState
>
states
)
{
if
(
states
.
contains
(
MaterialState
.
selected
))
{
return
colors
.
onInverseSurface
;
}
if
(
states
.
contains
(
MaterialState
.
pressed
))
{
return
colors
.
onSurface
;
}
return
null
;
}),
);
}
ButtonStyle
disabledOutlinedButtonStyle
(
bool
selected
,
ColorScheme
colors
)
{
return
IconButton
.
styleFrom
(
disabledForegroundColor:
colors
.
onSurface
.
withOpacity
(
0.38
),
disabledBackgroundColor:
selected
?
colors
.
onSurface
.
withOpacity
(
0.12
)
:
null
,
side:
selected
?
null
:
BorderSide
(
color:
colors
.
outline
.
withOpacity
(
0.12
)),
);
}
packages/flutter/lib/src/material/icon_button.dart
View file @
b1146549
This diff is collapsed.
Click to expand it.
packages/flutter/test/material/icon_button_test.dart
View file @
b1146549
This diff is collapsed.
Click to expand it.
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