Skip to content

Define TextStyle with dynamic values #38584

Closed

Description

@feinstein

TextStyle only has a const constructor, so I can't create one using a runtime value like:

TextStyle(
        color: Theme.of(context).primaryColor, // Error as this is not a const Color
        fontWeight: FontWeight.w500,
        fontSize: 20
);

Activity

  1. jonahwilliams commented on Aug 14, 2019

    @jonahwilliams
    Contributor

    TextStyle only has a const constructor, so I can't create one using a runtime value like:

    That's not true, just don't use const. const constructor means "may be constructed const," it's not required. In the example you posted, it is likely that some parent is const placing you in a const context

  2. feinstein commented on Aug 14, 2019

    @feinstein
    ContributorAuthor

    Sorry, you are right, I was editing old code and didn't see it, my apologies.

  3. github-actions commented on Aug 28, 2021

    @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.

  4. locked as resolved and limited conversation to collaborators on Aug 28, 2021
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions