wire bold text flag to text widget (#21325)
This commit is contained in:
@@ -46,6 +46,7 @@ class MediaQueryData {
|
||||
this.accessibleNavigation = false,
|
||||
this.invertColors = false,
|
||||
this.disableAnimations = false,
|
||||
this.boldText = false,
|
||||
});
|
||||
|
||||
/// Creates data for a media query based on the given window.
|
||||
@@ -63,6 +64,7 @@ class MediaQueryData {
|
||||
accessibleNavigation = window.accessibilityFeatures.accessibleNavigation,
|
||||
invertColors = window.accessibilityFeatures.accessibleNavigation,
|
||||
disableAnimations = window.accessibilityFeatures.disableAnimations,
|
||||
boldText = window.accessibilityFeatures.boldText,
|
||||
alwaysUse24HourFormat = window.alwaysUse24HourFormat;
|
||||
|
||||
/// The size of the media in logical pixel (e.g, the size of the screen).
|
||||
@@ -149,10 +151,20 @@ class MediaQueryData {
|
||||
/// Whether the platform is requesting that animations be disabled or reduced
|
||||
/// as much as possible.
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [Window.AccessibilityFeatures], where the setting originates.
|
||||
///
|
||||
final bool disableAnimations;
|
||||
|
||||
/// Whether the platform is requesting that text be drawn with a bold font
|
||||
/// weight.
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [Window.AccessibilityFeatures], where the setting originates.
|
||||
final bool boldText;
|
||||
|
||||
/// The orientation of the media (e.g., whether the device is in landscape or portrait mode).
|
||||
Orientation get orientation {
|
||||
return size.width > size.height ? Orientation.landscape : Orientation.portrait;
|
||||
@@ -170,6 +182,7 @@ class MediaQueryData {
|
||||
bool disableAnimations,
|
||||
bool invertColors,
|
||||
bool accessibleNavigation,
|
||||
bool boldText,
|
||||
}) {
|
||||
return new MediaQueryData(
|
||||
size: size ?? this.size,
|
||||
@@ -181,6 +194,7 @@ class MediaQueryData {
|
||||
invertColors: invertColors ?? this.invertColors,
|
||||
disableAnimations: disableAnimations ?? this.disableAnimations,
|
||||
accessibleNavigation: accessibleNavigation ?? this.accessibleNavigation,
|
||||
boldText: boldText ?? this.boldText,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -221,6 +235,7 @@ class MediaQueryData {
|
||||
disableAnimations: disableAnimations,
|
||||
invertColors: invertColors,
|
||||
accessibleNavigation: accessibleNavigation,
|
||||
boldText: boldText,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -259,6 +274,7 @@ class MediaQueryData {
|
||||
disableAnimations: disableAnimations,
|
||||
invertColors: invertColors,
|
||||
accessibleNavigation: accessibleNavigation,
|
||||
boldText: boldText,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -275,7 +291,8 @@ class MediaQueryData {
|
||||
&& typedOther.alwaysUse24HourFormat == alwaysUse24HourFormat
|
||||
&& typedOther.disableAnimations == disableAnimations
|
||||
&& typedOther.invertColors == invertColors
|
||||
&& typedOther.accessibleNavigation == accessibleNavigation;
|
||||
&& typedOther.accessibleNavigation == accessibleNavigation
|
||||
&& typedOther.boldText == boldText;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -290,6 +307,7 @@ class MediaQueryData {
|
||||
disableAnimations,
|
||||
invertColors,
|
||||
accessibleNavigation,
|
||||
boldText,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -305,6 +323,7 @@ class MediaQueryData {
|
||||
'accessibleNavigation: $accessibleNavigation'
|
||||
'disableAnimations: $disableAnimations'
|
||||
'invertColors: $invertColors'
|
||||
'boldText: $boldText'
|
||||
')';
|
||||
}
|
||||
}
|
||||
@@ -476,6 +495,12 @@ class MediaQuery extends InheritedWidget {
|
||||
return MediaQuery.of(context, nullOk: true)?.textScaleFactor ?? 1.0;
|
||||
}
|
||||
|
||||
/// Returns the boldText accessibility setting for the nearest MediaQuery
|
||||
/// ancestor, or false if no such ancestor exists.
|
||||
static bool boldTextOverride(BuildContext context) {
|
||||
return MediaQuery.of(context, nullOk: true)?.boldText ?? false;
|
||||
}
|
||||
|
||||
@override
|
||||
bool updateShouldNotify(MediaQuery oldWidget) => data != oldWidget.data;
|
||||
|
||||
|
||||
@@ -327,7 +327,7 @@ class Text extends StatelessWidget {
|
||||
/// If present, the semantics of this widget will contain this value instead
|
||||
/// of the actual text.
|
||||
///
|
||||
/// This is useful for replacing abbreviations or shorthands will the full
|
||||
/// This is useful for replacing abbreviations or shorthands with the full
|
||||
/// text value:
|
||||
///
|
||||
/// ```dart
|
||||
@@ -342,6 +342,8 @@ class Text extends StatelessWidget {
|
||||
TextStyle effectiveTextStyle = style;
|
||||
if (style == null || style.inherit)
|
||||
effectiveTextStyle = defaultTextStyle.style.merge(style);
|
||||
if (MediaQuery.boldTextOverride(context))
|
||||
effectiveTextStyle = effectiveTextStyle.merge(const TextStyle(fontWeight: FontWeight.bold));
|
||||
Widget result = new RichText(
|
||||
textAlign: textAlign ?? defaultTextStyle.textAlign ?? TextAlign.start,
|
||||
textDirection: textDirection, // RichText uses Directionality.of to obtain a default if this is null.
|
||||
|
||||
@@ -46,6 +46,7 @@ void main() {
|
||||
expect(data.accessibleNavigation, false);
|
||||
expect(data.invertColors, false);
|
||||
expect(data.disableAnimations, false);
|
||||
expect(data.boldText, false);
|
||||
});
|
||||
|
||||
testWidgets('MediaQueryData.copyWith defaults to source', (WidgetTester tester) async {
|
||||
@@ -60,6 +61,7 @@ void main() {
|
||||
expect(copied.accessibleNavigation, data.accessibleNavigation);
|
||||
expect(copied.invertColors, data.invertColors);
|
||||
expect(copied.disableAnimations, data.disableAnimations);
|
||||
expect(copied.boldText, data.boldText);
|
||||
});
|
||||
|
||||
testWidgets('MediaQuery.copyWith copies specified values', (WidgetTester tester) async {
|
||||
@@ -74,6 +76,7 @@ void main() {
|
||||
accessibleNavigation: true,
|
||||
invertColors: true,
|
||||
disableAnimations: true,
|
||||
boldText: true,
|
||||
);
|
||||
expect(copied.size, const Size(3.14, 2.72));
|
||||
expect(copied.devicePixelRatio, 1.41);
|
||||
@@ -84,6 +87,7 @@ void main() {
|
||||
expect(copied.accessibleNavigation, true);
|
||||
expect(copied.invertColors, true);
|
||||
expect(copied.disableAnimations, true);
|
||||
expect(copied.boldText, true);
|
||||
});
|
||||
|
||||
testWidgets('MediaQuery.removePadding removes specified padding', (WidgetTester tester) async {
|
||||
@@ -106,6 +110,7 @@ void main() {
|
||||
accessibleNavigation: true,
|
||||
invertColors: true,
|
||||
disableAnimations: true,
|
||||
boldText: true,
|
||||
),
|
||||
child: new Builder(
|
||||
builder: (BuildContext context) {
|
||||
@@ -136,6 +141,7 @@ void main() {
|
||||
expect(unpadded.accessibleNavigation, true);
|
||||
expect(unpadded.invertColors, true);
|
||||
expect(unpadded.disableAnimations, true);
|
||||
expect(unpadded.boldText, true);
|
||||
});
|
||||
|
||||
testWidgets('MediaQuery.removeViewInsets removes specified viewInsets', (WidgetTester tester) async {
|
||||
@@ -158,6 +164,7 @@ void main() {
|
||||
accessibleNavigation: true,
|
||||
invertColors: true,
|
||||
disableAnimations: true,
|
||||
boldText: true,
|
||||
),
|
||||
child: new Builder(
|
||||
builder: (BuildContext context) {
|
||||
@@ -188,6 +195,7 @@ void main() {
|
||||
expect(unpadded.accessibleNavigation, true);
|
||||
expect(unpadded.invertColors, true);
|
||||
expect(unpadded.disableAnimations, true);
|
||||
expect(unpadded.boldText, true);
|
||||
});
|
||||
|
||||
testWidgets('MediaQuery.textScaleFactorOf', (WidgetTester tester) async {
|
||||
@@ -216,4 +224,31 @@ void main() {
|
||||
expect(outsideTextScaleFactor, 1.0);
|
||||
expect(insideTextScaleFactor, 4.0);
|
||||
});
|
||||
|
||||
testWidgets('MediaQuery.boldTextOverride', (WidgetTester tester) async {
|
||||
bool outsideBoldTextOverride;
|
||||
bool insideBoldTextOverride;
|
||||
|
||||
await tester.pumpWidget(
|
||||
new Builder(
|
||||
builder: (BuildContext context) {
|
||||
outsideBoldTextOverride = MediaQuery.boldTextOverride(context);
|
||||
return new MediaQuery(
|
||||
data: const MediaQueryData(
|
||||
boldText: true,
|
||||
),
|
||||
child: new Builder(
|
||||
builder: (BuildContext context) {
|
||||
insideBoldTextOverride = MediaQuery.boldTextOverride(context);
|
||||
return new Container();
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
expect(outsideBoldTextOverride, false);
|
||||
expect(insideBoldTextOverride, true);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user