Skip to content

TextStyle with existing height cannot be copied with height=null #58765

Closed

Description

@daohoangson

Use case

If a TextStyle has some non-null height, it's impossible to make a copy with height=null because of this line:

      height: height ?? this.height,

Proposal

Adding a new param in TextStyle.copyWith should work.

Activity

  1. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    P3Issues that are less important to the Flutter project
    c: proposalA detailed proposal for a change to Flutter
    c: new featureNothing broken; request for a new capability
    on Jun 5, 2020
  2. daohoangson commented on Jan 31, 2022

    @daohoangson
    ContributorAuthor

    Another way to do this without introducing a new param: use a private constant as the default value for height. That way we can determine exactly whether the caller specified some value for height during copy. There is one downsize though, the method signature will have to replace double? height with dynamic height = _default.

  3. daohoangson commented on Jun 10, 2023

    @daohoangson
    ContributorAuthor

    TextStyle.height shouldn't be negative (it won't render anything), can we use a magic value of -1 to reset the height to null? Better yet, we can do an assert for TextStyle.new to disallow negative value and in TextStyle.copyWith, any negative value will reset the height.

  4. added
    P2Important issues not at the top of the work list
    and removed
    P3Issues that are less important to the Flutter project
    on Jan 12, 2024
  5. LongCatIsLooong commented on Jan 12, 2024

    @LongCatIsLooong
    Contributor

    It's not only copyWith that is not working. The meaning of null is ambiguous in the TextStyle context:

    1. it could mean the value should inherit from the parent span, or be overwritten when TextStyle.merge is called, or
    2. the height multiplier is disabled.

    I think we should follow the TextStyle convention and assume 1, let null represent "inherited", and pick a magic value for "disabled".

    The other TextStyle class from dart:ui has the same problem.

  6. daohoangson commented on Jan 12, 2024

    @daohoangson
    ContributorAuthor

    let null represent "inherited", and pick a magic value for "disabled"

    That would be great. Thank you.

  7. added
    ⏳Bot is counting down the days until it unassigns the issue
    on May 17, 2024
  8. flutter-triage-bot commented on May 17, 2024

    @flutter-triage-bot

    This issue is assigned to @LongCatIsLooong but has had no recent status updates. Please consider unassigning this issue if it is not going to be addressed in the near future. This allows people to have a clearer picture of what work is actually planned. Thanks!

  9. github-actions commented on Jun 12, 2024

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  10. locked as resolved and limited conversation to collaborators on Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

⏳Bot is counting down the days until it unassigns the issueP2Important issues not at the top of the work listc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions