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
dd9169ec
Unverified
Commit
dd9169ec
authored
Aug 30, 2021
by
Rami
Committed by
GitHub
Aug 30, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow for custom alignment for Dialogs (#88984)
parent
bce36620
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
98 additions
and
2 deletions
+98
-2
dialog.dart
packages/flutter/lib/src/material/dialog.dart
+21
-1
dialog_theme.dart
packages/flutter/lib/src/material/dialog_theme.dart
+12
-1
dialog_test.dart
packages/flutter/test/material/dialog_test.dart
+22
-0
dialog_theme_test.dart
packages/flutter/test/material/dialog_theme_test.dart
+43
-0
No files found.
packages/flutter/lib/src/material/dialog.dart
View file @
dd9169ec
...
...
@@ -47,6 +47,7 @@ class Dialog extends StatelessWidget {
this
.
insetPadding
=
_defaultInsetPadding
,
this
.
clipBehavior
=
Clip
.
none
,
this
.
shape
,
this
.
alignment
,
this
.
child
,
})
:
assert
(
clipBehavior
!=
null
),
super
(
key:
key
);
...
...
@@ -114,6 +115,14 @@ class Dialog extends StatelessWidget {
/// {@endtemplate}
final
ShapeBorder
?
shape
;
/// {@template flutter.material.dialog.alignment}
/// How to align the [Dialog].
///
/// If null, then [DialogTheme.alignment] is used. If that is also null, the
/// default is [Alignment.center].
/// {@endtemplate}
final
AlignmentGeometry
?
alignment
;
/// The widget below this widget in the tree.
///
/// {@macro flutter.widgets.ProxyWidget.child}
...
...
@@ -137,7 +146,8 @@ class Dialog extends StatelessWidget {
removeRight:
true
,
removeBottom:
true
,
context:
context
,
child:
Center
(
child:
Align
(
alignment:
alignment
??
dialogTheme
.
alignment
??
Alignment
.
center
,
child:
ConstrainedBox
(
constraints:
const
BoxConstraints
(
minWidth:
280.0
),
child:
Material
(
...
...
@@ -260,6 +270,7 @@ class AlertDialog extends StatelessWidget {
this
.
insetPadding
=
_defaultInsetPadding
,
this
.
clipBehavior
=
Clip
.
none
,
this
.
shape
,
this
.
alignment
,
this
.
scrollable
=
false
,
})
:
assert
(
contentPadding
!=
null
),
assert
(
clipBehavior
!=
null
),
...
...
@@ -437,6 +448,9 @@ class AlertDialog extends StatelessWidget {
/// {@macro flutter.material.dialog.shape}
final
ShapeBorder
?
shape
;
/// {@macro flutter.material.dialog.shape}
final
AlignmentGeometry
?
alignment
;
/// Determines whether the [title] and [content] widgets are wrapped in a
/// scrollable.
///
...
...
@@ -577,6 +591,7 @@ class AlertDialog extends StatelessWidget {
insetPadding:
insetPadding
,
clipBehavior:
clipBehavior
,
shape:
shape
,
alignment:
alignment
,
child:
dialogChild
,
);
}
...
...
@@ -742,6 +757,7 @@ class SimpleDialog extends StatelessWidget {
this
.
insetPadding
=
_defaultInsetPadding
,
this
.
clipBehavior
=
Clip
.
none
,
this
.
shape
,
this
.
alignment
,
})
:
assert
(
titlePadding
!=
null
),
assert
(
contentPadding
!=
null
),
super
(
key:
key
);
...
...
@@ -818,6 +834,9 @@ class SimpleDialog extends StatelessWidget {
/// {@macro flutter.material.dialog.shape}
final
ShapeBorder
?
shape
;
/// {@macro flutter.material.dialog.shape}
final
AlignmentGeometry
?
alignment
;
@override
Widget
build
(
BuildContext
context
)
{
assert
(
debugCheckHasMaterialLocalizations
(
context
));
...
...
@@ -908,6 +927,7 @@ class SimpleDialog extends StatelessWidget {
insetPadding:
insetPadding
,
clipBehavior:
clipBehavior
,
shape:
shape
,
alignment:
alignment
,
child:
dialogChild
,
);
}
...
...
packages/flutter/lib/src/material/dialog_theme.dart
View file @
dd9169ec
...
...
@@ -34,6 +34,7 @@ class DialogTheme with Diagnosticable {
this
.
backgroundColor
,
this
.
elevation
,
this
.
shape
,
this
.
alignment
,
this
.
titleTextStyle
,
this
.
contentTextStyle
,
});
...
...
@@ -52,6 +53,11 @@ class DialogTheme with Diagnosticable {
/// Default value for [Dialog.shape].
final
ShapeBorder
?
shape
;
/// Default value for [Dialog.alignment].
///
/// If null, the [Dialog] alignment defaults to [Alignment.center].
final
AlignmentGeometry
?
alignment
;
/// Used to configure the [DefaultTextStyle] for the [AlertDialog.title] widget.
///
/// If null, defaults to [TextTheme.headline6] of [ThemeData.textTheme].
...
...
@@ -68,6 +74,7 @@ class DialogTheme with Diagnosticable {
Color
?
backgroundColor
,
double
?
elevation
,
ShapeBorder
?
shape
,
AlignmentGeometry
?
alignment
,
TextStyle
?
titleTextStyle
,
TextStyle
?
contentTextStyle
,
})
{
...
...
@@ -75,6 +82,7 @@ class DialogTheme with Diagnosticable {
backgroundColor:
backgroundColor
??
this
.
backgroundColor
,
elevation:
elevation
??
this
.
elevation
,
shape:
shape
??
this
.
shape
,
alignment:
alignment
??
this
.
alignment
,
titleTextStyle:
titleTextStyle
??
this
.
titleTextStyle
,
contentTextStyle:
contentTextStyle
??
this
.
contentTextStyle
,
);
...
...
@@ -96,6 +104,7 @@ class DialogTheme with Diagnosticable {
backgroundColor:
Color
.
lerp
(
a
?.
backgroundColor
,
b
?.
backgroundColor
,
t
),
elevation:
lerpDouble
(
a
?.
elevation
,
b
?.
elevation
,
t
),
shape:
ShapeBorder
.
lerp
(
a
?.
shape
,
b
?.
shape
,
t
),
alignment:
AlignmentGeometry
.
lerp
(
a
?.
alignment
,
b
?.
alignment
,
t
),
titleTextStyle:
TextStyle
.
lerp
(
a
?.
titleTextStyle
,
b
?.
titleTextStyle
,
t
),
contentTextStyle:
TextStyle
.
lerp
(
a
?.
contentTextStyle
,
b
?.
contentTextStyle
,
t
),
);
...
...
@@ -114,6 +123,7 @@ class DialogTheme with Diagnosticable {
&&
other
.
backgroundColor
==
backgroundColor
&&
other
.
elevation
==
elevation
&&
other
.
shape
==
shape
&&
other
.
alignment
==
alignment
&&
other
.
titleTextStyle
==
titleTextStyle
&&
other
.
contentTextStyle
==
contentTextStyle
;
}
...
...
@@ -122,8 +132,9 @@ class DialogTheme with Diagnosticable {
void
debugFillProperties
(
DiagnosticPropertiesBuilder
properties
)
{
super
.
debugFillProperties
(
properties
);
properties
.
add
(
ColorProperty
(
'backgroundColor'
,
backgroundColor
));
properties
.
add
(
DiagnosticsProperty
<
ShapeBorder
>(
'shape'
,
shape
,
defaultValue:
null
));
properties
.
add
(
DoubleProperty
(
'elevation'
,
elevation
));
properties
.
add
(
DiagnosticsProperty
<
ShapeBorder
>(
'shape'
,
shape
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
AlignmentGeometry
>(
'alignment'
,
alignment
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
TextStyle
>(
'titleTextStyle'
,
titleTextStyle
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
TextStyle
>(
'contentTextStyle'
,
contentTextStyle
,
defaultValue:
null
));
}
...
...
packages/flutter/test/material/dialog_test.dart
View file @
dd9169ec
...
...
@@ -113,6 +113,11 @@ void main() {
expect
(
materialWidget
.
color
,
Colors
.
grey
[
800
]);
expect
(
materialWidget
.
shape
,
_defaultDialogShape
);
expect
(
materialWidget
.
elevation
,
24.0
);
final
Offset
bottomLeft
=
tester
.
getBottomLeft
(
find
.
descendant
(
of:
find
.
byType
(
Dialog
),
matching:
find
.
byType
(
Material
)),
);
expect
(
bottomLeft
.
dy
,
360.0
);
});
testWidgets
(
'Custom dialog elevation'
,
(
WidgetTester
tester
)
async
{
...
...
@@ -237,6 +242,23 @@ void main() {
expect
(
materialWidget
.
shape
,
customBorder
);
});
testWidgets
(
'Custom dialog alignment'
,
(
WidgetTester
tester
)
async
{
const
AlertDialog
dialog
=
AlertDialog
(
actions:
<
Widget
>[
],
alignment:
Alignment
.
bottomLeft
,
);
await
tester
.
pumpWidget
(
_buildAppWithDialog
(
dialog
));
await
tester
.
tap
(
find
.
text
(
'X'
));
await
tester
.
pumpAndSettle
();
final
Offset
bottomLeft
=
tester
.
getBottomLeft
(
find
.
descendant
(
of:
find
.
byType
(
Dialog
),
matching:
find
.
byType
(
Material
)),
);
expect
(
bottomLeft
.
dx
,
40.0
);
expect
(
bottomLeft
.
dy
,
576.0
);
});
testWidgets
(
'Simple dialog control test'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
const
MaterialApp
(
...
...
packages/flutter/test/material/dialog_theme_test.dart
View file @
dd9169ec
...
...
@@ -48,6 +48,7 @@ void main() {
backgroundColor:
Color
(
0xff123456
),
elevation:
8.0
,
shape:
null
,
alignment:
Alignment
.
bottomLeft
,
titleTextStyle:
TextStyle
(
color:
Color
(
0xffffffff
)),
contentTextStyle:
TextStyle
(
color:
Color
(
0xff000000
)),
).
debugFillProperties
(
builder
);
...
...
@@ -57,6 +58,7 @@ void main() {
expect
(
description
,
<
String
>[
'backgroundColor: Color(0xff123456)'
,
'elevation: 8.0'
,
'alignment: Alignment.bottomLeft'
,
'titleTextStyle: TextStyle(inherit: true, color: Color(0xffffffff))'
,
'contentTextStyle: TextStyle(inherit: true, color: Color(0xff000000))'
,
]);
...
...
@@ -115,6 +117,47 @@ void main() {
expect
(
materialWidget
.
shape
,
customBorder
);
});
testWidgets
(
'Custom dialog alignment'
,
(
WidgetTester
tester
)
async
{
const
AlertDialog
dialog
=
AlertDialog
(
title:
Text
(
'Title'
),
actions:
<
Widget
>[
],
);
final
ThemeData
theme
=
ThemeData
(
dialogTheme:
const
DialogTheme
(
alignment:
Alignment
.
bottomLeft
));
await
tester
.
pumpWidget
(
_appWithDialog
(
tester
,
dialog
,
theme:
theme
),
);
await
tester
.
tap
(
find
.
text
(
'X'
));
await
tester
.
pumpAndSettle
();
final
Offset
bottomLeft
=
tester
.
getBottomLeft
(
find
.
descendant
(
of:
find
.
byType
(
Dialog
),
matching:
find
.
byType
(
Material
)),
);
expect
(
bottomLeft
.
dx
,
40.0
);
expect
(
bottomLeft
.
dy
,
576.0
);
});
testWidgets
(
'Dialog alignment takes priority over theme'
,
(
WidgetTester
tester
)
async
{
const
AlertDialog
dialog
=
AlertDialog
(
title:
Text
(
'Title'
),
actions:
<
Widget
>[
],
alignment:
Alignment
.
topRight
,
);
final
ThemeData
theme
=
ThemeData
(
dialogTheme:
const
DialogTheme
(
alignment:
Alignment
.
bottomLeft
));
await
tester
.
pumpWidget
(
_appWithDialog
(
tester
,
dialog
,
theme:
theme
),
);
await
tester
.
tap
(
find
.
text
(
'X'
));
await
tester
.
pumpAndSettle
();
final
Offset
bottomLeft
=
tester
.
getBottomLeft
(
find
.
descendant
(
of:
find
.
byType
(
Dialog
),
matching:
find
.
byType
(
Material
)),
);
expect
(
bottomLeft
.
dx
,
480.0
);
expect
(
bottomLeft
.
dy
,
104.0
);
});
testWidgets
(
'Custom dialog shape matches golden'
,
(
WidgetTester
tester
)
async
{
const
RoundedRectangleBorder
customBorder
=
RoundedRectangleBorder
(
borderRadius:
BorderRadius
.
all
(
Radius
.
circular
(
16.0
)));
...
...
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