Skip to content

Consider Theme.of()! and other related topics #67163

Closed

Description

@Hixie

With the null safety migration, we've added a lot of !s near of methods. This issue is to track what we should do about it.

cc @goderbauer @HansMuller @gspencergoog @a14n

Activity

  1. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    P3Issues that are less important to the Flutter project
    on Oct 2, 2020
  2. goderbauer commented on Oct 2, 2020

    @goderbauer
    Member

    For Theme.of it can only return null when the shadowThemeOnly is set to true. My suggestion: Splitting this up into two methods:

    • Theme.of(BuildContect context) never returns null. This is the most common usage.
    • Theme.shadowThemeOf(BuildContext context) may return null.
  3. HansMuller commented on Oct 5, 2020

    @HansMuller
    Contributor

    Outside of the ~half dozen internal uses of this API, locally there's just one. Maybe we should remove it, rather than perpetuating it? It appears to just be a hack to get around the fact that new routes don't see the same inherited widgets that the caller who's built the route does (it's a hack because it only deals with the special case of Theme). The InheritedTheme.wrap method is supposed to be a more general way of dealing with this issue. https://api.flutter.dev/flutter/widgets/InheritedTheme/wrap.html

  4. tvolkert commented on Oct 23, 2020

    @tvolkert
    Contributor

    If most callers are going to have to migrate their Theme.of(context) calls to be Theme.of(context)! after we launch null safety, should we make this change before the null safety launch? (in which case it should probably be something higher than P5)

  5. gspencergoog commented on Oct 23, 2020

    @gspencergoog
    Contributor

    @tvolkert I agree, probably should be higher priority. I already have a design doc for doing this, among others: https://flutter.dev/go/eliminating-nullok-paramters (I know, I'm fixing the name typo in the go link).

  6. added
    P1High-priority issues at the top of the work list
    and removed
    P3Issues that are less important to the Flutter project
    on Oct 23, 2020
  7. self-assigned this
    on Oct 23, 2020
  8. gspencergoog commented on Oct 23, 2020

    @gspencergoog
    Contributor

    Oh, actually, I just realized that Theme.of doesn't actually have a nullOk parameter. I mean, it's a similar problem, so maybe it should be linked, but I was just trying to address the nullOk problem.

  9. HansMuller commented on Oct 23, 2020

    @HansMuller
    Contributor

    Per #67163 (comment) we don't need a nullable Theme.of(), we need to fix the one code path that uses Theme.shadowThemeOf(BuildContext context).

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

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

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work listframeworkflutter/packages/flutter repository. See also f: labels.

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions