Skip to content

Conversation

@LongCatIsLooong
Copy link
Contributor

@LongCatIsLooong LongCatIsLooong commented Jun 8, 2023

Deprecate textScaleFactor in favor of textScaler, in preparation for Android 14 Non-linear font scaling to 200%. The TextScaler class can be moved to dart:ui in the future, if we decide to use the Android platform API or AndroidX to get the scaling curve instead of hard coding the curve in the framework.

I haven't put the Flutter version in the deprecation message so the analyzer checks are failing. Will do so after I finish the migration guide.

Why TextScaler.textScaleFactor
The author of a TextScaler subclass should provide a fallback textScaleFactor. By making TextScaler also contain the textScaleFactor information it also makes it easier to migrate: if a widget overrides MediaQueryData.textScaler in the tree, for unmigrated widgets in the subtree it would also have to override MediaQueryData.textScaleFactor, and that makes it difficult to remove MediaQueryData.textScaleFactor in the future.

A full list of affected APIs in this PR

Deprecated: The method/getter/setter/argument is annotated with a @Deprecated() annotation in this PR, and the caller should replace it with textScaler instead. Unless otherwise specified there will be a Flutter fix available to help with migration but it's still recommended to migrate case-by-case.
Replaced: The method this textScaleFactor argument belongs to is rarely called directly by user code and is not overridden by any of the registered custom tests, so the argument is directly replaced by TextScaler.
To Be Deprecated: The method/getter/setter/argument can't be deprecated in this PR because a registered customer test depends on it and a Flutter fix isn't available (or the test was run without applying flutter fixes first). This method/getter/setter/argument will be deprecated in a followup PR once the registered test is migrated.

Painting Library

Affected API State of textScaleFactor Comment
InlineSpan.build({ double textScaleFactor = 1.0 }) argument Replaced
TextStyle.getParagraphStyle({ double TextScaleFactor = 1.0 }) argument Replaced
TextStyle.getTextStyle({ double TextScaleFactor = 1.0 }) argument Deprecated Can't replace: https://github.com/superlistapp/super_editor/blob/c47fd38dca4b7f43611690913b551a1773c563d7/super_editor/lib/src/infrastructure/super_textfield/desktop/desktop_textfield.dart#L1903-L1905
TextPainter({ double TextScaleFactor = 1.0 }) constructor argument Deprecated
TextPainter.textScaleFactor getter and setter Deprecated No Flutter Fix, not expressible yet
TextPainter.computeWidth({ double TextScaleFactor = 1.0 }) argument Deprecated
TextPainter.computeMaxIntrinsicWidth({ double TextScaleFactor = 1.0 }) argument Deprecated

Rendering Library

Affected API State of textScaleFactor Comment
RenderEditable({ double TextScaleFactor = 1.0 }) constructor argument Deprecated
RenderEditable.textScaleFactor getter and setter Deprecated No Flutter Fix, not expressible yet
RenderParagraph({ double TextScaleFactor = 1.0 }) constructor argument Deprecated
RenderParagraph.textScaleFactor getter and setter Deprecated No Flutter Fix, not expressible yet

Widgets Library

Affected API State of textScaleFactor Comment
MediaQueryData({ double TextScaleFactor = 1.0 }) constructor argument To Be Deprecated https://github.com/flutter/packages/blob/cd7b93532e5cb605a42735e20f1de70fc00adae7/packages/flutter_markdown/test/text_scale_factor_test.dart#LL39C21-L39C35
MediaQueryData.textScaleFactor getter Deprecated
MediaQueryData.copyWith({ double? TextScaleFactor }) argument Deprecated
MediaQuery.maybeTextScaleFactorOf(BuildContext context) static method Deprecated No Flutter Fix, not expressible yet
MediaQuery.textScaleFactorOf(BuildContext context) static method To Be Deprecated https://github.com/flutter/packages/blob/cd7b93532e5cb605a42735e20f1de70fc00adae7/packages/flutter_markdown/lib/src/_functions_io.dart#L68-L70, No Flutter Fix, not expressible yet
RichText({ double TextScaleFactor = 1.0 }) constructor argument To Be Deprecated https://github.com/flutter/packages/blob/cd7b93532e5cb605a42735e20f1de70fc00adae7/packages/flutter_markdown/lib/src/builder.dart#L829-L843
RichText.textScaleFactor getter To Be Deprecated A constructor argument can't be deprecated right away
Text({ double? TextScaleFactor = 1.0 }) constructor argument To Be Deprecated https://github.com/flutter/packages/blob/914d120da12fba458c020210727831c31bd71041/packages/rfw/lib/src/flutter/core_widgets.dart#L647 , No Flutter Fix because of dart-lang/sdk#52664
Text.rich({ double? TextScaleFactor = 1.0 }) constructor argument To Be Deprecated The default constructor has an argument that can't be deprecated right away. No Flutter Fix because of dart-lang/sdk#52664
Text.textScaleFactor getter To Be Deprecated A constructor argument can't be deprecated right away
EditableText({ double? TextScaleFactor = 1.0 }) constructor argument Deprecated No Flutter Fix because of dart-lang/sdk#52664
EditableText.textScaleFactor getter Deprecated

Material Library

Affected API State of textScaleFactor Comment
SelectableText({ double? TextScaleFactor = 1.0 }) constructor argument To Be Deprecated https://github.com/flutter/packages/blob/cd7b93532e5cb605a42735e20f1de70fc00adae7/packages/flutter_markdown/lib/src/builder.dart#L829-L843, No Flutter Fix because of dart-lang/sdk#52664
SelectableText.rich({ double? TextScaleFactor = 1.0 }) constructor argument To Be Deprecated The default constructor has an argument that can't be deprecated right away. No Flutter Fix because of dart-lang/sdk#52664
SelectableText.textScaleFactor getter To Be Deprecated A constructor argument can't be deprecated right away

A lot of material widgets (Slider, RangeSlider, TimePicker, and different types of buttons) also change their layout based on textScaleFactor. These need to be handled in a case-by-case fashion and will be migrated in follow-up PRs.

@github-actions github-actions bot added a: text input Entering text in a text field or keyboard related problems f: cupertino flutter/packages/flutter/cupertino repository f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. c: contributor-productivity Team-specific productivity, code health, technical debt. labels Jun 8, 2023
@LongCatIsLooong LongCatIsLooong force-pushed the text-scale-factor-api-changes branch from 17aa8d7 to 3fe3250 Compare June 8, 2023 22:21
@github-actions github-actions bot added d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos documentation f: scrolling Viewports, list views, slivers, etc. labels Jun 9, 2023
@LongCatIsLooong LongCatIsLooong force-pushed the text-scale-factor-api-changes branch from a10f938 to acadd43 Compare June 9, 2023 05:09
@github-actions github-actions bot added the c: tech-debt Technical debt, code quality, testing, etc. label Jun 9, 2023
@LongCatIsLooong LongCatIsLooong force-pushed the text-scale-factor-api-changes branch from ab55c7f to 84fe8c3 Compare June 10, 2023 02:20
@LongCatIsLooong LongCatIsLooong force-pushed the text-scale-factor-api-changes branch from 84fe8c3 to 2008762 Compare June 10, 2023 05:17
@LongCatIsLooong LongCatIsLooong marked this pull request as ready for review June 10, 2023 07:08
Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No major issues from me, mostly smaller stuff and questions. Thanks for doing all the work to migrate everything.

}

Widget _applyTextScaleFactor(Widget child) {
final double? textScaleFactor = _options!.textScaleFactor!.scale;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Could this go inside the builder method?

data: MediaQuery.of(context).copyWith(textScaleFactor: 1),
// the animation, such as the topLargeTitle. The text scaling is disabled to
// avoid odd transitions between pages.
return MediaQuery.disableTextScaling(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a convenient method 👍

// to follow the behavior of `UISearchTextField`.
final double scaledIconSize =
MediaQuery.textScaleFactorOf(context) * widget.itemSize;
final double scaledIconSize = MediaQuery.textScalerOf(context).textScaleFactor * widget.itemSize;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use .scale here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

widget.itemSize isn't font size. I'll try to migrate it in the future.

return EdgeInsetsGeometry.lerp(geometry1x, geometry2x, textScaleFactor - 1)!;
}
return EdgeInsetsGeometry.lerp(geometry2x, geometry3x, textScaleFactor - 2)!;
return switch (textScaleFactor) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I keep forgetting we can do this now.

child: MediaQuery.withClampedTextScaling(
// Constrain the textScaleFactor to the largest supported value to prevent
// layout issues.
maxScaleFactor: 1.3,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Maybe make 1.3 a constant since it's used a couple of times here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is still unresolved, but looks like a great idea!

expect(richTextList.any((RichText text) => text.textScaleFactor != 1), isFalse);

expect(tester.widget<RichText>(find.descendant(of: find.text('content'), matching: find.byType(RichText))).textScaleFactor, 99);
expect(tester.widget<RichText>(find.descendant(of: find.text('content'), matching: find.byType(RichText))).textScaler, const TextScaler.linear(99.0));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate all of the times in this PR that you added .0 to a double. Doubles without .0 is a pet peeve of mine.

const Size customSize = Size(3.14, 2.72);
const double customDevicePixelRatio = 1.41;
const double customTextScaleFactor = 1.62;
const TextScaler customTextScaler = TextScaler.linear(1.23);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did the scale change here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are random values I think I just copied them over. Shouldn't really matter.

]
));

group('Linear TextScaler', () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: If you do end up creating a separate text_scaler.dart file, you could put these tests in a new text_scaler_test.dart file. But it's fine either way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the TextScaler was moved to its own file. Let's move these tests to their own file as well since they don't relate much to media_quqery_test.dart.

const TextScaler.linear(2.0),
);
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for writing these backwards compatibility tests even though they're short lived!

/// [TextScaler] changes. Consider overridding the [==] operator if applicable
/// to avoid unnecessary rebuilds.
@immutable
abstract class TextScaler {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Could this go into its own new file if you wanted?

@goderbauer
Copy link
Member

lol @ the title of this PR. Isn't this more accurately described as "Implements TextScaler" or "Replaces textScaleFactor with TextScaler"? 😄

# For documentation about this file format, see
# https://dart.dev/go/data-driven-fixes.

# * Fixes in this file are for RichText from the widgets library. *
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RichText (as per this comment) or selectable_text (as per the file name)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugh sorry forgot to change those. Updated.

# For documentation about this file format, see
# https://dart.dev/go/data-driven-fixes.

# * Fixes in this file are for RichText from the widgets library. *
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, widget library (as per this comment) or material (as per the file path)?

- title: "Migrate to 'textScaler'"
date: 2023-06-09
element:
uris: [ 'widgets.dart' ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one isn't re-exported by material and cuppertino? (I believe for most (all?) widget.dart fixes we include those two as well...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to material.dart

# For documentation about this file format, see
# https://dart.dev/go/data-driven-fixes.

# * Fixes in this file are for RichText from the widgets library. *
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RichText or EditableText?

final TextDirection? textDirection;

/// {@macro flutter.widgets.editableText.textScaleFactor}
final double? textScaleFactor;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this property be deprecated?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you list this in the PR description as to be deprecated, would be helpful to mark these with a TODO in the code so we don't forget to do this and people that read this code in the current state are not confused why there are two different ways.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, what is your plan for actually doing the deprecation for the "to be deprecated" items?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll migrate the packages and then add the Deprecated annotation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll migrate the packages

I can't find where we document it, but we guarantee that the packages in https://github.com/flutter/packages are backwards compatible with x old stable versions. So, it will be quite some time before you can actually migrate these packages to the new API. We shouldn't wait that long to deprecate these - it will just be confusing to have to parallel APIs with no clear indicator which one to use. Typically, we just add ignores for the deprecation message to the lines they appear on in https://github.com/flutter/packages and then land the change in the framework that deprecates them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created flutter/packages#4209 to add ignores. But I'm not sure if changes like that needs a version bump or not.

double maxScaleFactor = double.infinity,
required Widget child,
}) {
return Builder(builder: (BuildContext context) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert that minScaleFactor and maxScaleFactor are in a legal range?

Comment on lines 103 to 113
final double? fontSize = switch (span.style?.fontSize) {
final double size when size != fontSizeStack.last => size,
_ => null,
};
if (fontSize != null) {
fontSizeStack.add(fontSize);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isnt' this simply:

final double? fontSize = span.style?.fontSize;
if (fontSize != null && fontSize != fontSizeStack.last) {
  fontSizeStack.add(fontSize);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pushing the fontSize to the stack. Whether fontSize is null also indicates if a pop operation is needed at the end. I guess I'll rename the variable to fontSizeToPush

// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Remove this file once textScaleFactor is removed.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: phrase this as a TODO?

}, skip: kIsWeb); // [intended] CkTextStyle doesn't have a custom toString implementation.
});
group('TextPainter', () {
test('textScaleFactor translates to testScaler', () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
test('textScaleFactor translates to testScaler', () {
test('textScaleFactor translates to textScaler', () {

/// The value of this property is only an estimate, so it may not reflect the
/// exact text scaling strategy this [TextScaler] represents, especially when
/// this [TextScaler] is not linear. Consider using [TextScaler.scale] instead.
/// This property exists solely for backward compatibility purposes, such that
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If so, we should mark this @Deprecated

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise, we should be more confident about the usage of this property. Right now the document sounds like this will probably go away in the future.

inClass: 'RichText'
changes:
- kind: 'rename'
newName: 'textScaler.textScaleFactor'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we going to keep this getter forever? otherwise this fix just place them on a temporary state.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like that textScaler.textScaleFactor is deprecated as well. We should remove this dart fix, otherwise the deprecated warning will persist even after the dart fix.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same applies to other dart fix that migrate people to textScaler.textScaleFactor

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to be a 2-stage deprecation process: RichText.textScaleFactor will be removed, and after a while TextScaler.textScaleFactor will be removed. In a sense RichText.textScaleFactor is more deprecated than TextScaler.textScaleFactor is and will have a shorter deprecation grace period than textScaler.textScaleFactor.

It does look confusing that dart fix replaces a deprecated getter with another, are you OK if the deprecation message of TextScaler.textScaleFactor is changed to something that tells the developer "this is also deprecated but it's better to use this instead of other textscalefactor"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our deprecation policy will remove deprecated field in terms of per stable release, so if they are deprecated in the same stable release, they will also be remove together.

I also suggest we remove them together since it just prolong the time developer will eventually need to migrate to the scale method, and they are already given long enough time to migrate. It also doesn't make it easier to complete the whole migration if they are in this temporary state.

textDirection: _model.rtl ? TextDirection.rtl : TextDirection.ltr,
child: MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: _model.size),
child: MediaQuery.withClampedTextScaling(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a obscure way to create a linear text scalar

should this do a copyWith TextScaler.linear?


return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
return MediaQuery.disableTextScaling(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the disableTextScaling method necessary? It looks like either way of setting textScaleFactor = 1.0 or textScaler.noScaling would work. I assume disableTextScaling is here so that there will just be one way to disable scaling, but once textScaleFactor is removed, this method will be redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a convenience method so yes it doesn't do anything special. But I think the implementation is slightly better than just getting MediaQuery.of from CupertinoDatePicker's context, since when MediaQueryData changes only the Builder widget will rebuild (instead of the date picker widget).

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 17, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 18, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 18, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 18, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 18, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 18, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 18, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 18, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 18, 2023
CaseyHillers added a commit that referenced this pull request Jul 18, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 19, 2023
sfshaza2 added a commit to flutter/website that referenced this pull request Jul 24, 2023
…aler` (#8903)

Corresponds to the framework PR:
flutter/flutter#128522

## Presubmit checklist

- [ ] This PR doesn’t contain automatically generated corrections
(Grammarly or similar).
- [ ] This PR follows the [Google Developer Documentation Style
Guidelines](https://developers.google.com/style) — for example, it
doesn’t use _i.e._ or _e.g._, and it avoids _I_ and _we_ (first person).
- [ ] This PR uses [semantic line
breaks](https://github.com/dart-lang/site-shared/blob/main/doc/writing-for-dart-and-flutter-websites.md#semantic-line-breaks)
of 80 characters or fewer.

---------

Co-authored-by: Shams Zakhour (ignore Sfshaza) <[email protected]>
Co-authored-by: Michael Goderbauer <[email protected]>
LouiseHsu pushed a commit to LouiseHsu/flutter that referenced this pull request Jul 31, 2023
Deprecate `textScaleFactor` in favor of `textScaler`, in preparation for Android 14 [Non-linear font scaling to 200%](https://developer.android.com/about/versions/14/features#non-linear-font-scaling). The `TextScaler` class can be moved to `dart:ui` in the future, if we decide to use the Android platform API or AndroidX to get the scaling curve instead of hard coding the curve in the framework.

I haven't put the Flutter version in the deprecation message so the analyzer checks are failing. Will do so after I finish the migration guide.

**Why `TextScaler.textScaleFactor`**
The author of a `TextScaler` subclass should provide a fallback `textScaleFactor`. By making `TextScaler` also contain the `textScaleFactor` information it also makes it easier to migrate: if a widget overrides `MediaQueryData.textScaler` in the tree, for unmigrated widgets in the subtree it would also have to override `MediaQueryData.textScaleFactor`, and that makes it difficult to remove `MediaQueryData.textScaleFactor` in the future.

## A full list of affected APIs in this PR

Deprecated: The method/getter/setter/argument is annotated with a `@Deprecated()` annotation in this PR, and the caller should replace it with `textScaler` instead. Unless otherwise specified there will be a Flutter fix available to help with migration but it's still recommended to migrate case-by-case.
**Replaced**:  The method this `textScaleFactor` argument belongs to is rarely called directly by user code and is not overridden by any of the registered custom tests, so the argument is directly replaced by `TextScaler`.
**To Be Deprecated**:  The method/getter/setter/argument can't be deprecated in this PR because a registered customer test depends on it and a Flutter fix isn't available (or the test was run without applying flutter fixes first). This method/getter/setter/argument will be deprecated in a followup PR once the registered test is migrated.

### `Painting` Library

| Affected API | State of `textScaleFactor` | Comment | 
| --- | --- | --- |
| `InlineSpan.build({ double textScaleFactor = 1.0 })` argument | **Replaced** | | 
| `TextStyle.getParagraphStyle({ double TextScaleFactor = 1.0 })` argument | **Replaced** | |
| `TextStyle.getTextStyle({ double TextScaleFactor = 1.0 })`  argument| Deprecated | Can't replace: https://github.com/superlistapp/super_editor/blob/c47fd38dca4b7f43611690913b551a1773c563d7/super_editor/lib/src/infrastructure/super_textfield/desktop/desktop_textfield.dart#L1903-L1905|
| `TextPainter({ double TextScaleFactor = 1.0 })` constructor argument | Deprecated | |
| `TextPainter.textScaleFactor` getter and setter | Deprecated | No Flutter Fix, not expressible yet |
| `TextPainter.computeWidth({ double TextScaleFactor = 1.0 })` argument | Deprecated | |
| `TextPainter.computeMaxIntrinsicWidth({ double TextScaleFactor = 1.0 })` argument | Deprecated | |

### `Rendering` Library

| Affected API | State of `textScaleFactor` | Comment | 
| --- | --- | --- |
| `RenderEditable({ double TextScaleFactor = 1.0 })` constructor argument | Deprecated | |
| `RenderEditable.textScaleFactor` getter and setter | Deprecated | No Flutter Fix, not expressible yet |
| `RenderParagraph({ double TextScaleFactor = 1.0 })` constructor argument | Deprecated | |
| `RenderParagraph.textScaleFactor` getter and setter | Deprecated | No Flutter Fix, not expressible yet |

### `Widgets` Library

| Affected API | State of `textScaleFactor` | Comment | 
| --- | --- | --- |
| `MediaQueryData({ double TextScaleFactor = 1.0 })` constructor argument | **To Be Deprecated** | https://github.com/flutter/packages/blob/cd7b93532e5cb605a42735e20f1de70fc00adae7/packages/flutter_markdown/test/text_scale_factor_test.dart#LL39C21-L39C35 |
| `MediaQueryData.textScaleFactor` getter | Deprecated | |
| `MediaQueryData.copyWith({ double? TextScaleFactor })` argument | Deprecated | |
| `MediaQuery.maybeTextScaleFactorOf(BuildContext context)` static method | Deprecated | No Flutter Fix, not expressible yet  |
| `MediaQuery.textScaleFactorOf(BuildContext context)` static method | **To Be Deprecated** | https://github.com/flutter/packages/blob/cd7b93532e5cb605a42735e20f1de70fc00adae7/packages/flutter_markdown/lib/src/_functions_io.dart#L68-L70, No Flutter Fix, not expressible yet |
| `RichText({ double TextScaleFactor = 1.0 })` constructor argument | **To Be Deprecated** | https://github.com/flutter/packages/blob/cd7b93532e5cb605a42735e20f1de70fc00adae7/packages/flutter_markdown/lib/src/builder.dart#L829-L843 |
| `RichText.textScaleFactor` getter | **To Be Deprecated** | A constructor argument can't be deprecated right away|
| `Text({ double? TextScaleFactor = 1.0 })` constructor argument | **To Be Deprecated** | https://github.com/flutter/packages/blob/914d120da12fba458c020210727831c31bd71041/packages/rfw/lib/src/flutter/core_widgets.dart#L647 , No Flutter Fix because of dart-lang/sdk#52664 |
| `Text.rich({ double? TextScaleFactor = 1.0 })` constructor argument | **To Be Deprecated** | The default constructor has an argument that can't be deprecated right away. No Flutter Fix because of dart-lang/sdk#52664 |
| `Text.textScaleFactor` getter | **To Be Deprecated** | A constructor argument can't be deprecated right away |
| `EditableText({ double? TextScaleFactor = 1.0 })` constructor argument | Deprecated | No Flutter Fix because of dart-lang/sdk#52664 |
| `EditableText.textScaleFactor` getter | Deprecated | |

### `Material` Library

| Affected API | State of `textScaleFactor` | Comment | 
| --- | --- | --- |
| `SelectableText({ double? TextScaleFactor = 1.0 })` constructor argument | **To Be Deprecated** | https://github.com/flutter/packages/blob/cd7b93532e5cb605a42735e20f1de70fc00adae7/packages/flutter_markdown/lib/src/builder.dart#L829-L843, No Flutter Fix because of dart-lang/sdk#52664 |
| `SelectableText.rich({ double? TextScaleFactor = 1.0 })` constructor argument | **To Be Deprecated** | The default constructor has an argument that can't be deprecated right away. No Flutter Fix because of dart-lang/sdk#52664 |
| `SelectableText.textScaleFactor` getter | **To Be Deprecated** | A constructor argument can't be deprecated right away |

A lot of material widgets (`Slider`, `RangeSlider`, `TimePicker`, and different types of buttons) also change their layout based on `textScaleFactor`. These need to be handled in a case-by-case fashion and will be migrated in follow-up PRs.
@paulobreim
Copy link

In all my applications, I use things like:
child: Text('My Text', textScaleFactor: 1.0),

This ensures that even if the user changes the font size in the Android configuration, the text will be presented in the default font, without the risk of "overflowing" the screen.

The problem is that I haven't found the solution yet, to do the same thing with textScaler.
Could anyone give me an example?

tks
paulo

@joelrose2
Copy link

The problem is that I haven't found the solution yet, to do the same thing with textScaler. Could anyone give me an example?

See: https://docs.flutter.dev/release/breaking-changes/deprecate-textscalefactor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: text input Entering text in a text field or keyboard related problems autosubmit Merge PR when tree becomes green via auto submit App c: contributor-productivity Team-specific productivity, code health, technical debt. c: tech-debt Technical debt, code quality, testing, etc. d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos f: cupertino flutter/packages/flutter/cupertino repository f: material design flutter/packages/flutter/material repository. f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants