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
a02568b3
Unverified
Commit
a02568b3
authored
May 10, 2018
by
Hans Muller
Committed by
GitHub
May 10, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added MediaQuery.textScaleFactorOf() (#17450)
parent
7809651c
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
85 additions
and
47 deletions
+85
-47
home.dart
examples/flutter_gallery/lib/gallery/home.dart
+1
-1
options.dart
examples/flutter_gallery/lib/gallery/options.dart
+1
-1
dialog.dart
packages/flutter/lib/src/cupertino/dialog.dart
+1
-1
editable_text.dart
packages/flutter/lib/src/widgets/editable_text.dart
+1
-1
media_query.dart
packages/flutter/lib/src/widgets/media_query.dart
+11
-0
text.dart
packages/flutter/lib/src/widgets/text.dart
+1
-1
media_query_test.dart
packages/flutter/test/widgets/media_query_test.dart
+69
-42
No files found.
examples/flutter_gallery/lib/gallery/home.dart
View file @
a02568b3
...
...
@@ -174,7 +174,7 @@ class _DemoItem extends StatelessWidget {
Widget
build
(
BuildContext
context
)
{
final
ThemeData
theme
=
Theme
.
of
(
context
);
final
bool
isDark
=
theme
.
brightness
==
Brightness
.
dark
;
final
double
textScaleFactor
=
MediaQuery
.
of
(
context
)?.
textScaleFactor
??
1.0
;
final
double
textScaleFactor
=
MediaQuery
.
textScaleFactorOf
(
context
)
;
final
List
<
Widget
>
titleChildren
=
<
Widget
>[
new
Text
(
...
...
examples/flutter_gallery/lib/gallery/options.dart
View file @
a02568b3
...
...
@@ -93,7 +93,7 @@ class _OptionsItem extends StatelessWidget {
@override
Widget
build
(
BuildContext
context
)
{
final
double
textScaleFactor
=
MediaQuery
.
of
(
context
)?.
textScaleFactor
??
1.0
;
final
double
textScaleFactor
=
MediaQuery
.
textScaleFactorOf
(
context
)
;
return
new
MergeSemantics
(
child:
new
Container
(
...
...
packages/flutter/lib/src/cupertino/dialog.dart
View file @
a02568b3
...
...
@@ -270,7 +270,7 @@ class CupertinoDialogAction extends StatelessWidget {
style
=
style
.
copyWith
(
color:
style
.
color
.
withOpacity
(
0.5
));
}
final
double
textScaleFactor
=
MediaQuery
.
of
(
context
,
nullOk:
true
)?.
textScaleFactor
??
1.0
;
final
double
textScaleFactor
=
MediaQuery
.
textScaleFactorOf
(
context
)
;
return
new
GestureDetector
(
onTap:
onPressed
,
behavior:
HitTestBehavior
.
opaque
,
...
...
packages/flutter/lib/src/widgets/editable_text.dart
View file @
a02568b3
...
...
@@ -684,7 +684,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
hasFocus:
_hasFocus
,
maxLines:
widget
.
maxLines
,
selectionColor:
widget
.
selectionColor
,
textScaleFactor:
widget
.
textScaleFactor
??
MediaQuery
.
of
(
context
,
nullOk:
true
)?.
textScaleFactor
??
1.0
,
textScaleFactor:
widget
.
textScaleFactor
??
MediaQuery
.
textScaleFactorOf
(
context
)
,
textAlign:
widget
.
textAlign
,
textDirection:
_textDirection
,
obscureText:
widget
.
obscureText
,
...
...
packages/flutter/lib/src/widgets/media_query.dart
View file @
a02568b3
...
...
@@ -76,6 +76,11 @@ class MediaQueryData {
///
/// For example, if the text scale factor is 1.5, text will be 50% larger than
/// the specified font size.
///
/// See also:
///
/// * [MediaQuery.textScaleFactorOf], a convenience method which returns the
/// textScaleFactor defined for a [BuildContext].
final
double
textScaleFactor
;
/// The number of physical pixels on each side of the display rectangle into
...
...
@@ -402,6 +407,12 @@ class MediaQuery extends InheritedWidget {
);
}
/// Returns textScaleFactor for the nearest MediaQuery ancestor or 1.0, if
/// no such ancestor exists.
static
double
textScaleFactorOf
(
BuildContext
context
)
{
return
MediaQuery
.
of
(
context
,
nullOk:
true
)?.
textScaleFactor
??
1.0
;
}
@override
bool
updateShouldNotify
(
MediaQuery
oldWidget
)
=>
data
!=
oldWidget
.
data
;
...
...
packages/flutter/lib/src/widgets/text.dart
View file @
a02568b3
...
...
@@ -305,7 +305,7 @@ class Text extends StatelessWidget {
textDirection:
textDirection
,
// RichText uses Directionality.of to obtain a default if this is null.
softWrap:
softWrap
??
defaultTextStyle
.
softWrap
,
overflow:
overflow
??
defaultTextStyle
.
overflow
,
textScaleFactor:
textScaleFactor
??
MediaQuery
.
of
(
context
,
nullOk:
true
)?.
textScaleFactor
??
1.0
,
textScaleFactor:
textScaleFactor
??
MediaQuery
.
textScaleFactorOf
(
context
)
,
maxLines:
maxLines
??
defaultTextStyle
.
maxLines
,
text:
new
TextSpan
(
style:
effectiveTextStyle
,
...
...
packages/flutter/test/widgets/media_query_test.dart
View file @
a02568b3
...
...
@@ -74,50 +74,50 @@ void main() {
expect
(
copied
.
alwaysUse24HourFormat
,
true
);
});
testWidgets
(
'MediaQuery.removePadding removes specified padding'
,
(
WidgetTester
tester
)
async
{
const
Size
size
=
const
Size
(
2.0
,
4.0
);
const
double
devicePixelRatio
=
2.0
;
const
double
textScaleFactor
=
1.2
;
const
EdgeInsets
padding
=
const
EdgeInsets
.
only
(
top:
1.0
,
right:
2.0
,
left:
3.0
,
bottom:
4.0
);
const
EdgeInsets
viewInsets
=
const
EdgeInsets
.
only
(
top:
5.0
,
right:
6.0
,
left:
7.0
,
bottom:
8.0
);
testWidgets
(
'MediaQuery.removePadding removes specified padding'
,
(
WidgetTester
tester
)
async
{
const
Size
size
=
const
Size
(
2.0
,
4.0
);
const
double
devicePixelRatio
=
2.0
;
const
double
textScaleFactor
=
1.2
;
const
EdgeInsets
padding
=
const
EdgeInsets
.
only
(
top:
1.0
,
right:
2.0
,
left:
3.0
,
bottom:
4.0
);
const
EdgeInsets
viewInsets
=
const
EdgeInsets
.
only
(
top:
5.0
,
right:
6.0
,
left:
7.0
,
bottom:
8.0
);
MediaQueryData
unpadded
;
await
tester
.
pumpWidget
(
new
MediaQuery
(
data:
const
MediaQueryData
(
size:
size
,
devicePixelRatio:
devicePixelRatio
,
textScaleFactor:
textScaleFactor
,
padding:
padding
,
viewInsets:
viewInsets
,
alwaysUse24HourFormat:
true
,
),
child:
new
Builder
(
builder:
(
BuildContext
context
)
{
return
new
MediaQuery
.
removePadding
(
context:
context
,
removeLeft:
true
,
removeTop:
true
,
removeRight:
true
,
removeBottom:
true
,
child:
new
Builder
(
builder:
(
BuildContext
context
)
{
unpadded
=
MediaQuery
.
of
(
context
);
return
new
Container
();
}
),
);
},
),
)
);
MediaQueryData
unpadded
;
await
tester
.
pumpWidget
(
new
MediaQuery
(
data:
const
MediaQueryData
(
size:
size
,
devicePixelRatio:
devicePixelRatio
,
textScaleFactor:
textScaleFactor
,
padding:
padding
,
viewInsets:
viewInsets
,
alwaysUse24HourFormat:
true
,
),
child:
new
Builder
(
builder:
(
BuildContext
context
)
{
return
new
MediaQuery
.
removePadding
(
context:
context
,
removeLeft:
true
,
removeTop:
true
,
removeRight:
true
,
removeBottom:
true
,
child:
new
Builder
(
builder:
(
BuildContext
context
)
{
unpadded
=
MediaQuery
.
of
(
context
);
return
new
Container
();
}
),
);
},
),
)
);
expect
(
unpadded
.
size
,
size
);
expect
(
unpadded
.
devicePixelRatio
,
devicePixelRatio
);
expect
(
unpadded
.
textScaleFactor
,
textScaleFactor
);
expect
(
unpadded
.
padding
,
EdgeInsets
.
zero
);
expect
(
unpadded
.
viewInsets
,
viewInsets
);
expect
(
unpadded
.
alwaysUse24HourFormat
,
true
);
expect
(
unpadded
.
size
,
size
);
expect
(
unpadded
.
devicePixelRatio
,
devicePixelRatio
);
expect
(
unpadded
.
textScaleFactor
,
textScaleFactor
);
expect
(
unpadded
.
padding
,
EdgeInsets
.
zero
);
expect
(
unpadded
.
viewInsets
,
viewInsets
);
expect
(
unpadded
.
alwaysUse24HourFormat
,
true
);
});
testWidgets
(
'MediaQuery.removeViewInsets removes specified viewInsets'
,
(
WidgetTester
tester
)
async
{
...
...
@@ -165,4 +165,31 @@ void main() {
expect
(
unpadded
.
viewInsets
,
EdgeInsets
.
zero
);
expect
(
unpadded
.
alwaysUse24HourFormat
,
true
);
});
testWidgets
(
'MediaQuery.textScaleFactorOf'
,
(
WidgetTester
tester
)
async
{
double
outsideTextScaleFactor
;
double
insideTextScaleFactor
;
await
tester
.
pumpWidget
(
new
Builder
(
builder:
(
BuildContext
context
)
{
outsideTextScaleFactor
=
MediaQuery
.
textScaleFactorOf
(
context
);
return
new
MediaQuery
(
data:
const
MediaQueryData
(
textScaleFactor:
4.0
,
),
child:
new
Builder
(
builder:
(
BuildContext
context
)
{
insideTextScaleFactor
=
MediaQuery
.
textScaleFactorOf
(
context
);
return
new
Container
();
},
),
);
},
),
);
expect
(
outsideTextScaleFactor
,
1.0
);
expect
(
insideTextScaleFactor
,
4.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