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
489d29c1
Unverified
Commit
489d29c1
authored
Jan 13, 2021
by
Hans Muller
Committed by
GitHub
Jan 13, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added ButtonStyle.alignment property (#73894)
parent
abb48f49
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
64 additions
and
2 deletions
+64
-2
button_style.dart
packages/flutter/lib/src/material/button_style.dart
+19
-1
button_style_button.dart
packages/flutter/lib/src/material/button_style_button.dart
+3
-1
elevated_button.dart
packages/flutter/lib/src/material/elevated_button.dart
+4
-0
outlined_button.dart
packages/flutter/lib/src/material/outlined_button.dart
+4
-0
text_button.dart
packages/flutter/lib/src/material/text_button.dart
+4
-0
elevated_button_test.dart
packages/flutter/test/material/elevated_button_test.dart
+3
-0
elevated_button_theme_test.dart
...ges/flutter/test/material/elevated_button_theme_test.dart
+7
-0
outlined_button_test.dart
packages/flutter/test/material/outlined_button_test.dart
+3
-0
outlined_button_theme_test.dart
...ges/flutter/test/material/outlined_button_theme_test.dart
+7
-0
text_button_test.dart
packages/flutter/test/material/text_button_test.dart
+3
-0
text_button_theme_test.dart
packages/flutter/test/material/text_button_theme_test.dart
+7
-0
No files found.
packages/flutter/lib/src/material/button_style.dart
View file @
489d29c1
...
...
@@ -114,6 +114,7 @@ class ButtonStyle with Diagnosticable {
this
.
tapTargetSize
,
this
.
animationDuration
,
this
.
enableFeedback
,
this
.
alignment
,
});
/// The style for a button's [Text] widget descendants.
...
...
@@ -208,6 +209,16 @@ class ButtonStyle with Diagnosticable {
/// * [Feedback] for providing platform-specific feedback to certain actions.
final
bool
?
enableFeedback
;
/// The alignment of the button's child.
///
/// Typically buttons are sized to be just big enough to contain the child and its
/// padding. If the button's size is constrained to a fixed size, for example by
/// enclosing it with a [SizedBox], this property defines how the child is aligned
/// within the available space.
///
/// Always defaults to [Alignment.center].
final
AlignmentGeometry
?
alignment
;
/// Returns a copy of this ButtonStyle with the given fields replaced with
/// the new values.
ButtonStyle
copyWith
({
...
...
@@ -226,6 +237,7 @@ class ButtonStyle with Diagnosticable {
MaterialTapTargetSize
?
tapTargetSize
,
Duration
?
animationDuration
,
bool
?
enableFeedback
,
AlignmentGeometry
?
alignment
,
})
{
return
ButtonStyle
(
textStyle:
textStyle
??
this
.
textStyle
,
...
...
@@ -243,6 +255,7 @@ class ButtonStyle with Diagnosticable {
tapTargetSize:
tapTargetSize
??
this
.
tapTargetSize
,
animationDuration:
animationDuration
??
this
.
animationDuration
,
enableFeedback:
enableFeedback
??
this
.
enableFeedback
,
alignment:
alignment
??
this
.
alignment
,
);
}
...
...
@@ -270,6 +283,7 @@ class ButtonStyle with Diagnosticable {
tapTargetSize:
tapTargetSize
??
style
.
tapTargetSize
,
animationDuration:
animationDuration
??
style
.
animationDuration
,
enableFeedback:
enableFeedback
??
style
.
enableFeedback
,
alignment:
alignment
??
style
.
alignment
,
);
}
...
...
@@ -291,6 +305,7 @@ class ButtonStyle with Diagnosticable {
tapTargetSize
,
animationDuration
,
enableFeedback
,
alignment
,
);
}
...
...
@@ -315,7 +330,8 @@ class ButtonStyle with Diagnosticable {
&&
other
.
visualDensity
==
visualDensity
&&
other
.
tapTargetSize
==
tapTargetSize
&&
other
.
animationDuration
==
animationDuration
&&
other
.
enableFeedback
==
enableFeedback
;
&&
other
.
enableFeedback
==
enableFeedback
&&
other
.
alignment
==
alignment
;
}
@override
...
...
@@ -336,6 +352,7 @@ class ButtonStyle with Diagnosticable {
properties
.
add
(
EnumProperty
<
MaterialTapTargetSize
>(
'tapTargetSize'
,
tapTargetSize
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
Duration
>(
'animationDuration'
,
animationDuration
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
bool
>(
'enableFeedback'
,
enableFeedback
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
AlignmentGeometry
>(
'alignment'
,
alignment
,
defaultValue:
null
));
}
/// Linearly interpolate between two [ButtonStyle]s.
...
...
@@ -359,6 +376,7 @@ class ButtonStyle with Diagnosticable {
tapTargetSize:
t
<
0.5
?
a
?.
tapTargetSize
:
b
?.
tapTargetSize
,
animationDuration:
t
<
0.5
?
a
?.
animationDuration
:
b
?.
animationDuration
,
enableFeedback:
t
<
0.5
?
a
?.
enableFeedback
:
b
?.
enableFeedback
,
alignment:
AlignmentGeometry
.
lerp
(
a
?.
alignment
,
b
?.
alignment
,
t
),
);
}
...
...
packages/flutter/lib/src/material/button_style_button.dart
View file @
489d29c1
...
...
@@ -283,6 +283,7 @@ class _ButtonStyleState extends State<ButtonStyleButton> with TickerProviderStat
final
MaterialTapTargetSize
?
resolvedTapTargetSize
=
effectiveValue
((
ButtonStyle
?
style
)
=>
style
?.
tapTargetSize
);
final
Duration
?
resolvedAnimationDuration
=
effectiveValue
((
ButtonStyle
?
style
)
=>
style
?.
animationDuration
);
final
bool
?
resolvedEnableFeedback
=
effectiveValue
((
ButtonStyle
?
style
)
=>
style
?.
enableFeedback
);
final
AlignmentGeometry
?
resolvedAlignment
=
effectiveValue
((
ButtonStyle
?
style
)
=>
style
?.
alignment
);
final
Offset
densityAdjustment
=
resolvedVisualDensity
!.
baseSizeAdjustment
;
final
BoxConstraints
effectiveConstraints
=
resolvedVisualDensity
.
effectiveConstraints
(
BoxConstraints
(
...
...
@@ -360,7 +361,8 @@ class _ButtonStyleState extends State<ButtonStyleButton> with TickerProviderStat
data:
IconThemeData
(
color:
resolvedForegroundColor
),
child:
Padding
(
padding:
padding
,
child:
Center
(
child:
Align
(
alignment:
resolvedAlignment
!,
widthFactor:
1.0
,
heightFactor:
1.0
,
child:
widget
.
child
,
...
...
packages/flutter/lib/src/material/elevated_button.dart
View file @
489d29c1
...
...
@@ -147,6 +147,7 @@ class ElevatedButton extends ButtonStyleButton {
MaterialTapTargetSize
?
tapTargetSize
,
Duration
?
animationDuration
,
bool
?
enableFeedback
,
AlignmentGeometry
?
alignment
,
})
{
final
MaterialStateProperty
<
Color
?>?
backgroundColor
=
(
onSurface
==
null
&&
primary
==
null
)
?
null
...
...
@@ -180,6 +181,7 @@ class ElevatedButton extends ButtonStyleButton {
tapTargetSize:
tapTargetSize
,
animationDuration:
animationDuration
,
enableFeedback:
enableFeedback
,
alignment:
alignment
,
);
}
...
...
@@ -238,6 +240,7 @@ class ElevatedButton extends ButtonStyleButton {
/// * `tapTargetSize` - theme.materialTapTargetSize
/// * `animationDuration` - kThemeChangeDuration
/// * `enableFeedback` - true
/// * `alignment` - Alignment.center
///
/// The default padding values for the [ElevatedButton.icon] factory are slightly different:
///
...
...
@@ -280,6 +283,7 @@ class ElevatedButton extends ButtonStyleButton {
tapTargetSize:
theme
.
materialTapTargetSize
,
animationDuration:
kThemeChangeDuration
,
enableFeedback:
true
,
alignment:
Alignment
.
center
,
);
}
...
...
packages/flutter/lib/src/material/outlined_button.dart
View file @
489d29c1
...
...
@@ -139,6 +139,7 @@ class OutlinedButton extends ButtonStyleButton {
MaterialTapTargetSize
?
tapTargetSize
,
Duration
?
animationDuration
,
bool
?
enableFeedback
,
AlignmentGeometry
?
alignment
,
})
{
final
MaterialStateProperty
<
Color
?>?
foregroundColor
=
(
onSurface
==
null
&&
primary
==
null
)
?
null
...
...
@@ -166,6 +167,7 @@ class OutlinedButton extends ButtonStyleButton {
tapTargetSize:
tapTargetSize
,
animationDuration:
animationDuration
,
enableFeedback:
enableFeedback
,
alignment:
alignment
,
);
}
...
...
@@ -217,6 +219,7 @@ class OutlinedButton extends ButtonStyleButton {
/// * `tapTargetSize` - theme.materialTapTargetSize
/// * `animationDuration` - kThemeChangeDuration
/// * `enableFeedback` - true
/// * `alignment` - Alignment.center
@override
ButtonStyle
defaultStyleOf
(
BuildContext
context
)
{
final
ThemeData
theme
=
Theme
.
of
(
context
);
...
...
@@ -249,6 +252,7 @@ class OutlinedButton extends ButtonStyleButton {
tapTargetSize:
theme
.
materialTapTargetSize
,
animationDuration:
kThemeChangeDuration
,
enableFeedback:
true
,
alignment:
Alignment
.
center
,
);
}
...
...
packages/flutter/lib/src/material/text_button.dart
View file @
489d29c1
...
...
@@ -145,6 +145,7 @@ class TextButton extends ButtonStyleButton {
MaterialTapTargetSize
?
tapTargetSize
,
Duration
?
animationDuration
,
bool
?
enableFeedback
,
AlignmentGeometry
?
alignment
,
})
{
final
MaterialStateProperty
<
Color
?>?
foregroundColor
=
(
onSurface
==
null
&&
primary
==
null
)
?
null
...
...
@@ -172,6 +173,7 @@ class TextButton extends ButtonStyleButton {
tapTargetSize:
tapTargetSize
,
animationDuration:
animationDuration
,
enableFeedback:
enableFeedback
,
alignment:
alignment
,
);
}
...
...
@@ -226,6 +228,7 @@ class TextButton extends ButtonStyleButton {
/// * `tapTargetSize` - theme.materialTapTargetSize
/// * `animationDuration` - kThemeChangeDuration
/// * `enableFeedback` - true
/// * `alignment` - Alignment.center
///
/// The default padding values for the [TextButton.icon] factory are slightly different:
///
...
...
@@ -267,6 +270,7 @@ class TextButton extends ButtonStyleButton {
tapTargetSize:
theme
.
materialTapTargetSize
,
animationDuration:
kThemeChangeDuration
,
enableFeedback:
true
,
alignment:
Alignment
.
center
,
);
}
...
...
packages/flutter/test/material/elevated_button_test.dart
View file @
489d29c1
...
...
@@ -48,6 +48,9 @@ void main() {
expect
(
material
.
textStyle
!.
fontWeight
,
FontWeight
.
w500
);
expect
(
material
.
type
,
MaterialType
.
button
);
final
Align
align
=
tester
.
firstWidget
<
Align
>(
find
.
ancestor
(
of:
find
.
text
(
'button'
),
matching:
find
.
byType
(
Align
)));
expect
(
align
.
alignment
,
Alignment
.
center
);
final
Offset
center
=
tester
.
getCenter
(
find
.
byType
(
ElevatedButton
));
final
TestGesture
gesture
=
await
tester
.
startGesture
(
center
);
await
tester
.
pump
();
// start the splash animation
...
...
packages/flutter/test/material/elevated_button_theme_test.dart
View file @
489d29c1
...
...
@@ -39,6 +39,9 @@ void main() {
expect
(
material
.
textStyle
!.
fontFamily
,
'Roboto'
);
expect
(
material
.
textStyle
!.
fontSize
,
14
);
expect
(
material
.
textStyle
!.
fontWeight
,
FontWeight
.
w500
);
final
Align
align
=
tester
.
firstWidget
<
Align
>(
find
.
ancestor
(
of:
find
.
text
(
'button'
),
matching:
find
.
byType
(
Align
)));
expect
(
align
.
alignment
,
Alignment
.
center
);
});
group
(
'[Theme, TextTheme, ElevatedButton style overrides]'
,
()
{
...
...
@@ -57,6 +60,7 @@ void main() {
const
MaterialTapTargetSize
tapTargetSize
=
MaterialTapTargetSize
.
shrinkWrap
;
const
Duration
animationDuration
=
Duration
(
milliseconds:
25
);
const
bool
enableFeedback
=
false
;
const
AlignmentGeometry
alignment
=
Alignment
.
centerLeft
;
final
ButtonStyle
style
=
ElevatedButton
.
styleFrom
(
primary:
primaryColor
,
...
...
@@ -74,6 +78,7 @@ void main() {
tapTargetSize:
tapTargetSize
,
animationDuration:
animationDuration
,
enableFeedback:
enableFeedback
,
alignment:
alignment
,
);
Widget
buildFrame
({
ButtonStyle
?
buttonStyle
,
ButtonStyle
?
themeStyle
,
ButtonStyle
?
overallStyle
})
{
...
...
@@ -137,6 +142,8 @@ void main() {
expect
(
material
.
shape
,
shape
);
expect
(
material
.
animationDuration
,
animationDuration
);
expect
(
tester
.
getSize
(
find
.
byType
(
ElevatedButton
)),
const
Size
(
200
,
200
));
final
Align
align
=
tester
.
firstWidget
<
Align
>(
find
.
ancestor
(
of:
find
.
text
(
'button'
),
matching:
find
.
byType
(
Align
)));
expect
(
align
.
alignment
,
alignment
);
}
testWidgets
(
'Button style overrides defaults'
,
(
WidgetTester
tester
)
async
{
...
...
packages/flutter/test/material/outlined_button_test.dart
View file @
489d29c1
...
...
@@ -52,6 +52,9 @@ void main() {
expect
(
material
.
textStyle
!.
fontWeight
,
FontWeight
.
w500
);
expect
(
material
.
type
,
MaterialType
.
button
);
final
Align
align
=
tester
.
firstWidget
<
Align
>(
find
.
ancestor
(
of:
find
.
text
(
'button'
),
matching:
find
.
byType
(
Align
)));
expect
(
align
.
alignment
,
Alignment
.
center
);
final
Offset
center
=
tester
.
getCenter
(
find
.
byType
(
OutlinedButton
));
final
TestGesture
gesture
=
await
tester
.
startGesture
(
center
);
await
tester
.
pump
();
// start the splash animation
...
...
packages/flutter/test/material/outlined_button_theme_test.dart
View file @
489d29c1
...
...
@@ -44,6 +44,9 @@ void main() {
expect
(
material
.
textStyle
!.
fontFamily
,
'Roboto'
);
expect
(
material
.
textStyle
!.
fontSize
,
14
);
expect
(
material
.
textStyle
!.
fontWeight
,
FontWeight
.
w500
);
final
Align
align
=
tester
.
firstWidget
<
Align
>(
find
.
ancestor
(
of:
find
.
text
(
'button'
),
matching:
find
.
byType
(
Align
)));
expect
(
align
.
alignment
,
Alignment
.
center
);
});
group
(
'[Theme, TextTheme, OutlinedButton style overrides]'
,
()
{
...
...
@@ -62,6 +65,7 @@ void main() {
const
MaterialTapTargetSize
tapTargetSize
=
MaterialTapTargetSize
.
shrinkWrap
;
const
Duration
animationDuration
=
Duration
(
milliseconds:
25
);
const
bool
enableFeedback
=
false
;
const
AlignmentGeometry
alignment
=
Alignment
.
centerLeft
;
final
ButtonStyle
style
=
OutlinedButton
.
styleFrom
(
primary:
primaryColor
,
...
...
@@ -79,6 +83,7 @@ void main() {
tapTargetSize:
tapTargetSize
,
animationDuration:
animationDuration
,
enableFeedback:
enableFeedback
,
alignment:
alignment
,
);
Widget
buildFrame
({
ButtonStyle
?
buttonStyle
,
ButtonStyle
?
themeStyle
,
ButtonStyle
?
overallStyle
})
{
...
...
@@ -140,6 +145,8 @@ void main() {
expect
(
material
.
shape
,
shape
);
expect
(
material
.
animationDuration
,
animationDuration
);
expect
(
tester
.
getSize
(
find
.
byType
(
OutlinedButton
)),
const
Size
(
200
,
200
));
final
Align
align
=
tester
.
firstWidget
<
Align
>(
find
.
ancestor
(
of:
find
.
text
(
'button'
),
matching:
find
.
byType
(
Align
)));
expect
(
align
.
alignment
,
alignment
);
}
testWidgets
(
'Button style overrides defaults'
,
(
WidgetTester
tester
)
async
{
...
...
packages/flutter/test/material/text_button_test.dart
View file @
489d29c1
...
...
@@ -47,6 +47,9 @@ void main() {
expect
(
material
.
textStyle
!.
fontWeight
,
FontWeight
.
w500
);
expect
(
material
.
type
,
MaterialType
.
button
);
final
Align
align
=
tester
.
firstWidget
<
Align
>(
find
.
ancestor
(
of:
find
.
text
(
'button'
),
matching:
find
.
byType
(
Align
)));
expect
(
align
.
alignment
,
Alignment
.
center
);
final
Offset
center
=
tester
.
getCenter
(
find
.
byType
(
TextButton
));
final
TestGesture
gesture
=
await
tester
.
startGesture
(
center
);
await
tester
.
pump
();
// start the splash animation
...
...
packages/flutter/test/material/text_button_theme_test.dart
View file @
489d29c1
...
...
@@ -39,6 +39,9 @@ void main() {
expect
(
material
.
textStyle
!.
fontFamily
,
'Roboto'
);
expect
(
material
.
textStyle
!.
fontSize
,
14
);
expect
(
material
.
textStyle
!.
fontWeight
,
FontWeight
.
w500
);
final
Align
align
=
tester
.
firstWidget
<
Align
>(
find
.
ancestor
(
of:
find
.
text
(
'button'
),
matching:
find
.
byType
(
Align
)));
expect
(
align
.
alignment
,
Alignment
.
center
);
});
group
(
'[Theme, TextTheme, TextButton style overrides]'
,
()
{
...
...
@@ -57,6 +60,7 @@ void main() {
const
MaterialTapTargetSize
tapTargetSize
=
MaterialTapTargetSize
.
shrinkWrap
;
const
Duration
animationDuration
=
Duration
(
milliseconds:
25
);
const
bool
enableFeedback
=
false
;
const
AlignmentGeometry
alignment
=
Alignment
.
centerLeft
;
final
ButtonStyle
style
=
TextButton
.
styleFrom
(
primary:
primaryColor
,
...
...
@@ -74,6 +78,7 @@ void main() {
tapTargetSize:
tapTargetSize
,
animationDuration:
animationDuration
,
enableFeedback:
enableFeedback
,
alignment:
alignment
,
);
Widget
buildFrame
({
ButtonStyle
?
buttonStyle
,
ButtonStyle
?
themeStyle
,
ButtonStyle
?
overallStyle
})
{
...
...
@@ -135,6 +140,8 @@ void main() {
expect
(
material
.
shape
,
shape
);
expect
(
material
.
animationDuration
,
animationDuration
);
expect
(
tester
.
getSize
(
find
.
byType
(
TextButton
)),
const
Size
(
200
,
200
));
final
Align
align
=
tester
.
firstWidget
<
Align
>(
find
.
ancestor
(
of:
find
.
text
(
'button'
),
matching:
find
.
byType
(
Align
)));
expect
(
align
.
alignment
,
alignment
);
}
testWidgets
(
'Button style overrides defaults'
,
(
WidgetTester
tester
)
async
{
...
...
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