Skip to content

Text widget to change its colour and fontSize without using TextStyle #61690

Closed

Description

@happyharis

Use case

I believe new developers has benefitted from the readability of the 'out of the box' colour parameter in container. Therefore, I am proposing the same with the commonly used Text widget.

Colour changes in Container widget has been introduced as follows:

Container(color: Colors.red)

// Instead of
Container(decoration: BoxDecoration(color: Colors.red));

Is the reason for container out of the box colour parameter better readability and ease of understanding for new Flutter developers? Otherwise, what's the reason?

However, text widget has no colour parameter out of the box. To change a colour, you have to type an additional object.

Text('example', style: TextStyle(color: Colors.red));

Proposal

Have the text widget to have a colour and fontSize parameters without using TextStyle. These two parameters I believe is the most used parameters in the Text widget.

// Before
Text('example', style: TextStyle(color: Colors.red, fontSize: 30));

// After
Text('example', color: Colors.red, fontSize: 30);

Activity

  1. added
    a: typographyText rendering, possibly libtxt
    p: material_uimaterial_ui package in flutter/packages
    frameworkflutter/packages/flutter repository. See also f: labels.
    c: proposalA detailed proposal for a change to Flutter
    on Jul 17, 2020
  2. Pragya007 commented on Jul 18, 2020

    @Pragya007
    Contributor

    @darshankawar I would like to work on this proposal, can you guide me a bit? TextStyle property should not change, only color and fontSize is to be added for Text, am I right?

  3. flutter-triage-bot commented on Jul 16, 2024

    @flutter-triage-bot

    This issue is missing a priority label. Please set a priority label when adding the triaged-design label.

  4. Piinks commented on Jul 18, 2024

    @Piinks
    Contributor

    I am going to close this since it is very unlikely we will do this. I have added it to the list in #24722 where we keep track of API improvements that would be nice, but we are not likely to make.

  5. feinstein commented on Jul 19, 2024

    @feinstein
    Contributor

    We could have both, and an assert that says "you can't define both, you need to choose only color or a TextStyle". I believe other widgets have mechanisms like this.

    Also the changes on Text should be very small, as we just need to create a TextStyle if a color was defined, and keep the same underlying code unchanged, just the constructor would be affected.

  6. github-actions commented on Aug 2, 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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: typographyText rendering, possibly libtxtc: proposalA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packagesr: solvedIssue is closed as solvedteam-designOwned by Design Languages team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions