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