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
f5578257
Unverified
Commit
f5578257
authored
Jan 14, 2021
by
Hans Muller
Committed by
GitHub
Jan 14, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added CupertinoButton alignment property (#73900)
parent
277c4d22
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
1 deletion
+43
-1
button.dart
packages/flutter/lib/src/cupertino/button.dart
+16
-1
button_test.dart
packages/flutter/test/cupertino/button_test.dart
+27
-0
No files found.
packages/flutter/lib/src/cupertino/button.dart
View file @
f5578257
...
@@ -40,9 +40,11 @@ class CupertinoButton extends StatefulWidget {
...
@@ -40,9 +40,11 @@ class CupertinoButton extends StatefulWidget {
this
.
minSize
=
kMinInteractiveDimensionCupertino
,
this
.
minSize
=
kMinInteractiveDimensionCupertino
,
this
.
pressedOpacity
=
0.4
,
this
.
pressedOpacity
=
0.4
,
this
.
borderRadius
=
const
BorderRadius
.
all
(
Radius
.
circular
(
8.0
)),
this
.
borderRadius
=
const
BorderRadius
.
all
(
Radius
.
circular
(
8.0
)),
this
.
alignment
=
Alignment
.
center
,
required
this
.
onPressed
,
required
this
.
onPressed
,
})
:
assert
(
pressedOpacity
==
null
||
(
pressedOpacity
>=
0.0
&&
pressedOpacity
<=
1.0
)),
})
:
assert
(
pressedOpacity
==
null
||
(
pressedOpacity
>=
0.0
&&
pressedOpacity
<=
1.0
)),
assert
(
disabledColor
!=
null
),
assert
(
disabledColor
!=
null
),
assert
(
alignment
!=
null
),
_filled
=
false
,
_filled
=
false
,
super
(
key:
key
);
super
(
key:
key
);
...
@@ -60,9 +62,11 @@ class CupertinoButton extends StatefulWidget {
...
@@ -60,9 +62,11 @@ class CupertinoButton extends StatefulWidget {
this
.
minSize
=
kMinInteractiveDimensionCupertino
,
this
.
minSize
=
kMinInteractiveDimensionCupertino
,
this
.
pressedOpacity
=
0.4
,
this
.
pressedOpacity
=
0.4
,
this
.
borderRadius
=
const
BorderRadius
.
all
(
Radius
.
circular
(
8.0
)),
this
.
borderRadius
=
const
BorderRadius
.
all
(
Radius
.
circular
(
8.0
)),
this
.
alignment
=
Alignment
.
center
,
required
this
.
onPressed
,
required
this
.
onPressed
,
})
:
assert
(
pressedOpacity
==
null
||
(
pressedOpacity
>=
0.0
&&
pressedOpacity
<=
1.0
)),
})
:
assert
(
pressedOpacity
==
null
||
(
pressedOpacity
>=
0.0
&&
pressedOpacity
<=
1.0
)),
assert
(
disabledColor
!=
null
),
assert
(
disabledColor
!=
null
),
assert
(
alignment
!=
null
),
color
=
null
,
color
=
null
,
_filled
=
true
,
_filled
=
true
,
super
(
key:
key
);
super
(
key:
key
);
...
@@ -116,6 +120,16 @@ class CupertinoButton extends StatefulWidget {
...
@@ -116,6 +120,16 @@ class CupertinoButton extends StatefulWidget {
/// Defaults to round corners of 8 logical pixels.
/// Defaults to round corners of 8 logical pixels.
final
BorderRadius
?
borderRadius
;
final
BorderRadius
?
borderRadius
;
/// 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
;
final
bool
_filled
;
final
bool
_filled
;
/// Whether the button is enabled or disabled. Buttons are disabled by default. To
/// Whether the button is enabled or disabled. Buttons are disabled by default. To
...
@@ -252,7 +266,8 @@ class _CupertinoButtonState extends State<CupertinoButton> with SingleTickerProv
...
@@ -252,7 +266,8 @@ class _CupertinoButtonState extends State<CupertinoButton> with SingleTickerProv
padding:
widget
.
padding
??
(
backgroundColor
!=
null
padding:
widget
.
padding
??
(
backgroundColor
!=
null
?
_kBackgroundButtonPadding
?
_kBackgroundButtonPadding
:
_kButtonPadding
),
:
_kButtonPadding
),
child:
Center
(
child:
Align
(
alignment:
widget
.
alignment
,
widthFactor:
1.0
,
widthFactor:
1.0
,
heightFactor:
1.0
,
heightFactor:
1.0
,
child:
DefaultTextStyle
(
child:
DefaultTextStyle
(
...
...
packages/flutter/test/cupertino/button_test.dart
View file @
f5578257
...
@@ -101,6 +101,33 @@ void main() {
...
@@ -101,6 +101,33 @@ void main() {
});
});
*/
*/
testWidgets
(
'Button child alignment'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
CupertinoApp
(
home:
CupertinoButton
(
onPressed:
()
{
},
child:
const
Text
(
'button'
),
),
),
);
Align
align
=
tester
.
firstWidget
<
Align
>(
find
.
ancestor
(
of:
find
.
text
(
'button'
),
matching:
find
.
byType
(
Align
)));
expect
(
align
.
alignment
,
Alignment
.
center
);
// default
await
tester
.
pumpWidget
(
CupertinoApp
(
home:
CupertinoButton
(
alignment:
Alignment
.
centerLeft
,
onPressed:
()
{
},
child:
const
Text
(
'button'
),
),
),
);
align
=
tester
.
firstWidget
<
Align
>(
find
.
ancestor
(
of:
find
.
text
(
'button'
),
matching:
find
.
byType
(
Align
)));
expect
(
align
.
alignment
,
Alignment
.
centerLeft
);
});
testWidgets
(
'Button with background is wider'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'Button with background is wider'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
boilerplate
(
child:
const
CupertinoButton
(
await
tester
.
pumpWidget
(
boilerplate
(
child:
const
CupertinoButton
(
child:
Text
(
'X'
,
style:
testStyle
),
child:
Text
(
'X'
,
style:
testStyle
),
...
...
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