Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration of textScaleFactor to textScaler #830

Merged
merged 8 commits into from
Nov 21, 2023

Conversation

hjiangsu
Copy link
Member

Pull Request Description

This PR is mainly under-the-hood changes to migrate the deprecated textScaleFactor to use textScaler. For more information about the deprecation, see here: https://docs.flutter.dev/release/breaking-changes/deprecate-textscalefactor

To accomplish this, I've created a new widget ScalableText which works similar to the regular Text widget, except it accepts a fontScale parameter. The fontScale parameter is defined here. The main reason for creating this new widget is to hopefully simplify the logic for calculating the final fontSize attribute required.

Previously, to apply a textScaleFactor, all we had to do was add the parameter to any Text widget

Text('example', textScaleFactor: MediaQuery.of(context).textScaleFactor * fontScale.textScaleFactor)

To have the equivalent functionality as before using TextScaler, the following changes had to be made. Note that the scaling is dependent on the textTheme we choose (e.g., bodyMedium, titleSmall, etc.)

Text('example', style: theme.textTheme.bodyMedium.copyWith({
    fontSize: MediaQuery.textScalerOf(context).scale(theme.textTheme.bodyMedium.fontSize * fontScale.textScaleFactor),
})

By using the new ScalableText widget, that migration code changes to the following

ScalableText('example', fontScale: fontScale)

ScalableText(
    'example 2',
    style: theme.textTheme.titleSmall.copyWith({ color: Colors. black }),
    fontScale: fontScale
)

The ScalableText takes any existing styling that was initially applied, and appends the appropriate fontSize based on the fontScale that is passed in. This should help simplify things in the future when we want to add more resizable text elements. This approach also considers the system's font size like the previous implementation.

In addition, I've fixed up some linting warnings throughout the whole codebase to clean up warnings and errors. Since some of the code was adjusted for this migration, we should double check and see if the text scaling is roughly the same as it was before, and adjust accordingly if not.

@micahmo could you run through this and see if you notice any changes to the text size from the current develop build vs this change? I'll keep it as a draft until more checks are done to confirm that the general text sizes have not changed much!

Issue Being Fixed

Issue Number: N/A

Screenshots / Recordings

Checklist

  • Did you update CHANGELOG.md?
  • Did you use localized strings where applicable?
  • Did you add semanticLabels where applicable for accessibility?

@hjiangsu
Copy link
Member Author

One thing to note is that we need to use flutter channel beta. This change has not been merged upstream to the stable channel yet (this is why the linter is failing its checks)

Copy link
Member

@micahmo micahmo left a comment

Choose a reason for hiding this comment

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

Very nice, thanks for taking this on! And nice cleanup too. The ScalableText definitely makes this transition easier.

Things look good on Android. The base size is unchanged, which is good. 😊

lib/community/widgets/post_card_view_comfortable.dart Outdated Show resolved Hide resolved
@hjiangsu
Copy link
Member Author

I'll keep this as a draft and wait until this deprecation change reaches the upstream stable channel (likely with the release of Flutter 3.14 to the stable channel)

@hjiangsu hjiangsu marked this pull request as ready for review November 20, 2023 21:38
@hjiangsu
Copy link
Member Author

The deprecation change has made its way to the stable branch, so I'm opening this up for review

@hjiangsu hjiangsu changed the base branch from develop to 0.2.7 November 21, 2023 01:49
@hjiangsu hjiangsu merged commit 9a31358 into 0.2.7 Nov 21, 2023
1 check passed
@hjiangsu hjiangsu deleted the feature/text-scale-factor-migration branch November 21, 2023 01:49
hjiangsu added a commit that referenced this pull request Nov 23, 2023
* Migration of textScaleFactor to textScaler (#830)

* migration of to be deprecated textScalingFactor, and a lot of linter fixes

* added ScalableText to missing instance

* linting

* Added option to collapse post body (#888)

* added option to collapse a post in the post view

* added ability to tap on post preview to expand post, linting

* moved changelog to proper place
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants