Unverified Commit 505845c5 authored by LongCatIsLooong's avatar LongCatIsLooong Committed by GitHub

Remove textScaleFactor references from flutter/flutter (#142271)

These should the the last remaining `MediaQueryData.textScaleFactor` and `TextScaler.textScaleFactor` references.
parent 5b44596c
......@@ -33,6 +33,10 @@ class ProductCard extends StatelessWidget {
fit: BoxFit.cover,
);
// The fontSize to use for computing the heuristic UI scaling factor.
const double defaultFontSize = 14.0;
final double containerScaingFactor = MediaQuery.textScalerOf(context).scale(defaultFontSize) / defaultFontSize;
return ScopedModelDescendant<AppStateModel>(
builder: (BuildContext context, Widget? child, AppStateModel model) {
return GestureDetector(
......@@ -52,8 +56,7 @@ class ProductCard extends StatelessWidget {
child: imageWidget,
),
SizedBox(
// ignore: deprecated_member_use, https://github.com/flutter/flutter/issues/128825
height: kTextBoxHeight * MediaQuery.textScalerOf(context).textScaleFactor,
height: kTextBoxHeight * containerScaingFactor,
width: 121.0,
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
......
......@@ -178,8 +178,9 @@ class _DemoItem extends StatelessWidget {
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context);
final bool isDark = theme.brightness == Brightness.dark;
// ignore: deprecated_member_use, https://github.com/flutter/flutter/issues/128825
final double textScaleFactor = MediaQuery.textScalerOf(context).textScaleFactor;
// The fontSize to use for computing the heuristic UI scaling factor.
const double defaultFontSize = 14.0;
final double containerScaingFactor = MediaQuery.textScalerOf(context).scale(defaultFontSize) / defaultFontSize;
return RawMaterialButton(
splashColor: theme.primaryColor.withOpacity(0.12),
highlightColor: Colors.transparent,
......@@ -187,7 +188,7 @@ class _DemoItem extends StatelessWidget {
_launchDemo(context);
},
child: Container(
constraints: BoxConstraints(minHeight: _kDemoItemHeight * textScaleFactor),
constraints: BoxConstraints(minHeight: _kDemoItemHeight * containerScaingFactor),
child: Row(
children: <Widget>[
Container(
......
......@@ -126,11 +126,10 @@ class _TimePickerOptionsState extends State<TimePickerOptions> {
children: <Widget>[
Expanded(
child: GridView(
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 350,
mainAxisSpacing: 4,
// ignore: deprecated_member_use, https://github.com/flutter/flutter/issues/128825
mainAxisExtent: 200 * MediaQuery.textScalerOf(context).textScaleFactor,
mainAxisExtent: 200,
crossAxisSpacing: 4,
),
children: <Widget>[
......
......@@ -671,6 +671,10 @@ class _RangeSliderState extends State<RangeSlider> with TickerProviderStateMixin
// in slider.dart.
Size screenSize() => MediaQuery.sizeOf(context);
final double fontSize = sliderTheme.valueIndicatorTextStyle?.fontSize ?? kDefaultFontSize;
final double fontSizeToScale = fontSize == 0.0 ? kDefaultFontSize : fontSize;
final double effectiveTextScale = MediaQuery.textScalerOf(context).scale(fontSizeToScale) / fontSizeToScale;
return FocusableActionDetector(
enabled: _enabled,
onShowHoverHighlight: _handleHoverChanged,
......@@ -683,7 +687,7 @@ class _RangeSliderState extends State<RangeSlider> with TickerProviderStateMixin
divisions: widget.divisions,
labels: widget.labels,
sliderTheme: sliderTheme,
textScaleFactor: MediaQuery.of(context).textScaleFactor,
textScaleFactor: effectiveTextScale,
screenSize: screenSize(),
onChanged: _enabled && (widget.max > widget.min) ? _handleChanged : null,
onChangeStart: widget.onChangeStart != null ? _handleDragStart : null,
......
......@@ -882,13 +882,16 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
shortcutMap = _traditionalNavShortcutMap;
}
final double textScaleFactor = theme.useMaterial3
final double fontSize = sliderTheme.valueIndicatorTextStyle?.fontSize ?? kDefaultFontSize;
final double fontSizeToScale = fontSize == 0.0 ? kDefaultFontSize : fontSize;
final TextScaler textScaler = theme.useMaterial3
// TODO(tahatesser): This is an eye-balled value.
// This needs to be updated when accessibility
// guidelines are available on the material specs page
// https://m3.material.io/components/sliders/accessibility.
? MediaQuery.textScalerOf(context).clamp(maxScaleFactor: 1.3).textScaleFactor
: MediaQuery.textScalerOf(context).textScaleFactor;
? MediaQuery.textScalerOf(context).clamp(maxScaleFactor: 1.3)
: MediaQuery.textScalerOf(context);
final double effectiveTextScale = textScaler.scale(fontSizeToScale) / fontSizeToScale;
return Semantics(
container: true,
......@@ -912,7 +915,7 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
divisions: widget.divisions,
label: widget.label,
sliderTheme: sliderTheme,
textScaleFactor: textScaleFactor,
textScaleFactor: effectiveTextScale,
screenSize: screenSize(),
onChanged: (widget.onChanged != null) && (widget.max > widget.min) ? _handleChanged : null,
onChangeStart: _handleDragStart,
......
......@@ -902,7 +902,7 @@ abstract class SliderComponentShape {
/// The `textScaleFactor` argument can be used to determine whether the
/// component should paint larger or smaller, depending on whether
/// [textScaleFactor] is greater than 1 for larger, and between 0 and 1 for
/// smaller. It usually comes from [MediaQueryData.textScaleFactor].
/// smaller. It's usually computed from [MediaQueryData.textScaler].
/// {@endtemplate}
///
/// {@template flutter.material.SliderComponentShape.paint.sizeWithOverflow}
......
......@@ -5405,11 +5405,7 @@ class _ScribblePlaceholder extends WidgetSpan {
if (hasStyle) {
builder.pushStyle(style!.getTextStyle(textScaler: textScaler));
}
builder.addPlaceholder(
size.width * textScaler.textScaleFactor,
size.height * textScaler.textScaleFactor,
alignment,
);
builder.addPlaceholder(size.width, size.height, alignment);
if (hasStyle) {
builder.pop();
}
......
......@@ -1197,8 +1197,9 @@ void main() {
await tester.pumpWidget(
CupertinoApp(
home: Builder(builder: (BuildContext context) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 99),
return MediaQuery.withClampedTextScaling(
minScaleFactor: 99,
maxScaleFactor: 99,
child: const CupertinoPageScaffold(
child: CustomScrollView(
slivers: <Widget>[
......@@ -1243,8 +1244,9 @@ void main() {
tester.state<NavigatorState>(find.byType(Navigator)).push(CupertinoPageRoute<void>(
title: 'title',
builder: (BuildContext context) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 99),
return MediaQuery.withClampedTextScaling(
minScaleFactor: 99,
maxScaleFactor: 99,
child: const CupertinoPageScaffold(
child: CustomScrollView(
slivers: <Widget>[
......
......@@ -1098,8 +1098,9 @@ void main() {
await tester.pumpWidget(
CupertinoApp(
home: Builder(builder: (BuildContext context) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 99),
return MediaQuery.withClampedTextScaling(
minScaleFactor: 99,
maxScaleFactor: 99,
child: CupertinoTabScaffold(
tabBar: CupertinoTabBar(
items: List<BottomNavigationBarItem>.generate(
......
......@@ -30,8 +30,9 @@ MaterialApp _buildAppWithDialog(
context: context,
traversalEdgeBehavior: traversalEdgeBehavior,
builder: (BuildContext context) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: textScaleFactor),
return MediaQuery.withClampedTextScaling(
minScaleFactor: textScaleFactor,
maxScaleFactor: textScaleFactor,
child: dialog,
);
},
......
......@@ -575,8 +575,9 @@ void main() {
TestApp(
textDirection: TextDirection.ltr,
child: Builder(
builder: (BuildContext context) => MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 3.0),
builder: (BuildContext context) => MediaQuery.withClampedTextScaling(
minScaleFactor: 3.0,
maxScaleFactor: 3.0,
child: Material(
child: Center(
child: DropdownButtonFormField<String>(
......
......@@ -1058,10 +1058,9 @@ void main() {
),
home: Builder(
builder: (BuildContext context) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(
textScaleFactor: textScaleFactor,
),
return MediaQuery.withClampedTextScaling(
minScaleFactor: textScaleFactor,
maxScaleFactor: textScaleFactor,
child: Directionality(
textDirection: textDirection,
child: Scaffold(
......@@ -1225,10 +1224,9 @@ void main() {
theme: ThemeData.from(colorScheme: const ColorScheme.light()),
home: Builder(
builder: (BuildContext context) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(
textScaleFactor: 2,
),
return MediaQuery.withClampedTextScaling(
minScaleFactor: 2,
maxScaleFactor: 2,
child: Scaffold(
body: Center(
child: ElevatedButton(
......
......@@ -1203,10 +1203,9 @@ void main() {
),
home: Builder(
builder: (BuildContext context) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(
textScaleFactor: textScaleFactor,
),
return MediaQuery.withClampedTextScaling(
minScaleFactor: textScaleFactor,
maxScaleFactor: textScaleFactor,
child: Directionality(
textDirection: textDirection,
child: Scaffold(
......@@ -1339,10 +1338,9 @@ void main() {
theme: ThemeData.from(colorScheme: const ColorScheme.light()),
home: Builder(
builder: (BuildContext context) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(
textScaleFactor: 2,
),
return MediaQuery.withClampedTextScaling(
minScaleFactor: 2,
maxScaleFactor: 2,
child: Scaffold(
body: Center(
child: FilledButton(
......
......@@ -1856,8 +1856,9 @@ void main() {
return Scaffold(
body: Row(
children: <Widget>[
MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 3.0),
MediaQuery.withClampedTextScaling(
minScaleFactor: 3.0,
maxScaleFactor: 3.0,
child: NavigationRail(
selectedIndex: 0,
destinations: const <NavigationRailDestination>[
......@@ -5135,8 +5136,9 @@ void main() {
return Scaffold(
body: Row(
children: <Widget>[
MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 3.0),
MediaQuery.withClampedTextScaling(
minScaleFactor: 3.0,
maxScaleFactor: 3.0,
child: NavigationRail(
selectedIndex: 0,
destinations: const <NavigationRailDestination>[
......@@ -5511,8 +5513,9 @@ Future<void> _pumpNavigationRail(
),
home: Builder(
builder: (BuildContext context) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: textScaleFactor),
return MediaQuery.withClampedTextScaling(
minScaleFactor: textScaleFactor,
maxScaleFactor: textScaleFactor,
child: Scaffold(
body: Row(
children: <Widget>[
......
......@@ -1310,10 +1310,9 @@ void main() {
),
home: Builder(
builder: (BuildContext context) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(
textScaleFactor: textScaleFactor,
),
return MediaQuery.withClampedTextScaling(
minScaleFactor: textScaleFactor,
maxScaleFactor: textScaleFactor,
child: Directionality(
textDirection: textDirection,
child: Scaffold(
......@@ -1449,10 +1448,9 @@ void main() {
theme: ThemeData(useMaterial3: false),
home: Builder(
builder: (BuildContext context) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(
textScaleFactor: 2,
),
return MediaQuery.withClampedTextScaling(
minScaleFactor: 2,
maxScaleFactor: 2,
child: Scaffold(
body: Center(
child: OutlinedButton(
......
......@@ -1084,10 +1084,9 @@ void main() {
),
home: Builder(
builder: (BuildContext context) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(
textScaleFactor: textScaleFactor,
),
return MediaQuery.withClampedTextScaling(
minScaleFactor: textScaleFactor,
maxScaleFactor: textScaleFactor,
child: Directionality(
textDirection: textDirection,
child: Scaffold(
......@@ -1226,10 +1225,9 @@ void main() {
theme: ThemeData.from(colorScheme: const ColorScheme.light()),
home: Builder(
builder: (BuildContext context) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(
textScaleFactor: 2,
),
return MediaQuery.withClampedTextScaling(
minScaleFactor: 2,
maxScaleFactor: 2,
child: Scaffold(
body: Center(
child: TextButton(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment