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
6f56ba45
Unverified
Commit
6f56ba45
authored
Jul 15, 2020
by
Anthony
Committed by
GitHub
Jul 15, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Automatically scale down Dialog padding for larger text scale factors (#58245)
parent
b010f78e
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
479 additions
and
22 deletions
+479
-22
dialog.dart
packages/flutter/lib/src/material/dialog.dart
+80
-20
dialog_test.dart
packages/flutter/test/material/dialog_test.dart
+399
-2
No files found.
packages/flutter/lib/src/material/dialog.dart
View file @
6f56ba45
...
...
@@ -5,6 +5,7 @@
// @dart = 2.8
import
'dart:async'
;
import
'dart:ui'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/widgets.dart'
;
...
...
@@ -310,7 +311,10 @@ class AlertDialog extends StatelessWidget {
/// The (optional) set of actions that are displayed at the bottom of the
/// dialog.
///
/// Typically this is a list of [FlatButton] widgets.
/// Typically this is a list of [FlatButton] widgets. It is recommended to
/// set the [textAlign] to [TextAlign.end] for the [Text] within the
/// [FlatButton], so that buttons whose labels wrap to an extra line align
/// with the overall [ButtonBar]'s alignment within the dialog.
///
/// These widgets will be wrapped in a [ButtonBar], which introduces 8 pixels
/// of padding on each side.
...
...
@@ -466,12 +470,24 @@ class AlertDialog extends StatelessWidget {
}
}
// The paddingScaleFactor is used to adjust the padding of Dialog's
// children.
final
double
paddingScaleFactor
=
_paddingScaleFactor
(
MediaQuery
.
of
(
context
).
textScaleFactor
);
final
TextDirection
textDirection
=
Directionality
.
of
(
context
);
Widget
titleWidget
;
Widget
contentWidget
;
Widget
actionsWidget
;
if
(
title
!=
null
)
titleWidget
=
Padding
(
padding:
titlePadding
??
EdgeInsets
.
fromLTRB
(
24.0
,
24.0
,
24.0
,
content
==
null
?
20.0
:
0.0
),
if
(
title
!=
null
)
{
final
EdgeInsets
defaultTitlePadding
=
EdgeInsets
.
fromLTRB
(
24.0
,
24.0
,
24.0
,
content
==
null
?
20.0
:
0.0
);
final
EdgeInsets
effectiveTitlePadding
=
titlePadding
?.
resolve
(
textDirection
)
??
defaultTitlePadding
;
titleWidget
=
Padding
(
padding:
EdgeInsets
.
only
(
left:
effectiveTitlePadding
.
left
*
paddingScaleFactor
,
right:
effectiveTitlePadding
.
right
*
paddingScaleFactor
,
top:
effectiveTitlePadding
.
top
*
paddingScaleFactor
,
bottom:
effectiveTitlePadding
.
bottom
,
),
child:
DefaultTextStyle
(
style:
titleTextStyle
??
dialogTheme
.
titleTextStyle
??
theme
.
textTheme
.
headline6
,
child:
Semantics
(
...
...
@@ -481,17 +497,26 @@ class AlertDialog extends StatelessWidget {
),
),
);
}
if
(
content
!=
null
)
if
(
content
!=
null
)
{
final
EdgeInsets
effectiveContentPadding
=
contentPadding
.
resolve
(
textDirection
);
contentWidget
=
Padding
(
padding:
contentPadding
,
padding:
EdgeInsets
.
only
(
left:
effectiveContentPadding
.
left
*
paddingScaleFactor
,
right:
effectiveContentPadding
.
right
*
paddingScaleFactor
,
top:
title
==
null
?
effectiveContentPadding
.
top
*
paddingScaleFactor
:
effectiveContentPadding
.
top
,
bottom:
effectiveContentPadding
.
bottom
,
),
child:
DefaultTextStyle
(
style:
contentTextStyle
??
dialogTheme
.
contentTextStyle
??
theme
.
textTheme
.
subtitle1
,
child:
content
,
),
);
}
if
(
actions
!=
null
)
if
(
actions
!=
null
)
{
actionsWidget
=
Padding
(
padding:
actionsPadding
,
child:
ButtonBar
(
...
...
@@ -501,6 +526,7 @@ class AlertDialog extends StatelessWidget {
children:
actions
,
),
);
}
List
<
Widget
>
columnChildren
;
if
(
scrollable
)
{
...
...
@@ -805,6 +831,44 @@ class SimpleDialog extends StatelessWidget {
}
}
// The paddingScaleFactor is used to adjust the padding of Dialog
// children.
final
double
paddingScaleFactor
=
_paddingScaleFactor
(
MediaQuery
.
of
(
context
).
textScaleFactor
);
final
TextDirection
textDirection
=
Directionality
.
of
(
context
);
Widget
titleWidget
;
if
(
title
!=
null
)
{
final
EdgeInsets
effectiveTitlePadding
=
titlePadding
.
resolve
(
textDirection
);
titleWidget
=
Padding
(
padding:
EdgeInsets
.
only
(
left:
effectiveTitlePadding
.
left
*
paddingScaleFactor
,
right:
effectiveTitlePadding
.
right
*
paddingScaleFactor
,
top:
effectiveTitlePadding
.
top
*
paddingScaleFactor
,
bottom:
children
==
null
?
effectiveTitlePadding
.
bottom
*
paddingScaleFactor
:
effectiveTitlePadding
.
bottom
,
),
child:
DefaultTextStyle
(
style:
titleTextStyle
??
DialogTheme
.
of
(
context
).
titleTextStyle
??
theme
.
textTheme
.
headline6
,
child:
Semantics
(
namesRoute:
true
,
child:
title
),
),
);
}
Widget
contentWidget
;
if
(
children
!=
null
)
{
final
EdgeInsets
effectiveContentPadding
=
contentPadding
.
resolve
(
textDirection
);
contentWidget
=
Flexible
(
child:
SingleChildScrollView
(
padding:
EdgeInsets
.
only
(
left:
effectiveContentPadding
.
left
*
paddingScaleFactor
,
right:
effectiveContentPadding
.
right
*
paddingScaleFactor
,
top:
title
==
null
?
effectiveContentPadding
.
top
*
paddingScaleFactor
:
effectiveContentPadding
.
top
,
bottom:
effectiveContentPadding
.
bottom
*
paddingScaleFactor
,
),
child:
ListBody
(
children:
children
),
),
);
}
Widget
dialogChild
=
IntrinsicWidth
(
stepWidth:
56.0
,
child:
ConstrainedBox
(
...
...
@@ -814,20 +878,9 @@ class SimpleDialog extends StatelessWidget {
crossAxisAlignment:
CrossAxisAlignment
.
stretch
,
children:
<
Widget
>[
if
(
title
!=
null
)
Padding
(
padding:
titlePadding
,
child:
DefaultTextStyle
(
style:
titleTextStyle
??
DialogTheme
.
of
(
context
).
titleTextStyle
??
theme
.
textTheme
.
headline6
,
child:
Semantics
(
namesRoute:
true
,
child:
title
),
),
),
titleWidget
,
if
(
children
!=
null
)
Flexible
(
child:
SingleChildScrollView
(
padding:
contentPadding
,
child:
ListBody
(
children:
children
),
),
),
contentWidget
,
],
),
),
...
...
@@ -959,3 +1012,10 @@ Future<T> showDialog<T>({
routeSettings:
routeSettings
,
);
}
double
_paddingScaleFactor
(
double
textScaleFactor
)
{
final
double
clampedTextScaleFactor
=
textScaleFactor
.
clamp
(
1.0
,
2.0
).
toDouble
();
// The final padding scale factor is clamped between 1/3 and 1. For example,
// a non-scaled padding of 24 will produce a padding between 24 and 8.
return
lerpDouble
(
1.0
,
1.0
/
3.0
,
clampedTextScaleFactor
-
1.0
);
}
packages/flutter/test/material/dialog_test.dart
View file @
6f56ba45
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