Skip to content

Widgets inserted to an Overlay have different ancestral InheritedWidget(s) than commonly expected #36220

Description

@LongCatIsLooong

This seems to be a very common source of bugs when using the Hero API:

and in the framework:

Workaround

As a temporary workaround, manually wrap whatever is missing inside the hero, or in its shuttleBuilder.
See: #30647 (comment)

additional context:
#6072 (comment)

Activity

  1. esDotDev commented on Oct 20, 2019

    @esDotDev

    I've implemented the workaround, but am still getting a line-wrap during transition, that causes my text to flicker:
    http://treefortress.com/shared/2019-10-20_09-49-24.mp4

    Tried wrapping the content in Material, and DefaultTextStyle, both still result in this flicker.

    I can manually size the container to get rid of it, but these containers are variable width, depending on the size of their text, so that's not ideal.

  2. LongCatIsLooong commented on Oct 20, 2019

    @LongCatIsLooong
    ContributorAuthor

    @esDotDev thanks for reporting the issue! So the workaround works for you (i.e. the text is getting the correct TextStyle), expect that it flickers during transition? That reminds me of #42988.
    Could you post a minimal code sample that reproduces the problem in that thread?

  3. added a commit that references this issue on Dec 6, 2019
  4. pdf commented on Dec 22, 2019

    @pdf

    We'd like to wrap a BottomAppBar in a Hero, but since BottomAppBar depends on having a Scaffold available via the context, it throws an exception on every transition, and I suspect that is due to this issue. I cannot see a viable workaround.

  5. Skquark commented on Jan 23, 2020

    @Skquark

    Was still having trouble with the fix for a Text Hero using the suggested flightShuttleBuilder because it wasn't taking my from/to style font with the DefaultTextStyle, so I had to tweak it a bit and got it working for my needs. I made it as an extension on Text just because it's prettier to use. Here's my code:

    extension HeroText on Text {
      Widget hero(Object tag) {
        return Hero(
          flightShuttleBuilder: (_, Animation<double> animation, HeroFlightDirection flightDirection, BuildContext fromHeroContext, BuildContext toHeroContext) {
            return AnimatedBuilder(
              animation: animation,
              child: this,
              builder: (_, _child) {
                return DefaultTextStyle.merge(
                  child: _child,
                  style: TextStyle.lerp(((fromHeroContext.widget as Hero).child as Text).style, ((toHeroContext.widget as Hero).child as Text).style,
                      flightDirection == HeroFlightDirection.pop ? 1 - animation.value : animation.value),
                );
              },
            );
          },
          tag: tag,
          transitionOnUserGestures: true,
          child: this,
        );
      }
    }
    

    So on the from page, you have something like:
    Text("Title as Hero", style: TextStyle(fontSize: 16.0, fontFamily: "Fira", color: Colors.blue.shade800)).hero("title"),
    and the same on the to page
    Text("Title as Hero", style: TextStyle(fontSize: 22.0, fontFamily: "Fira", color: Colors.blue.shade500)).hero("title"),
    Now lerps the TextStyle nicely enough, but still should be fixed on the Flutter side so we don't have to hack it..

  6. removed their assignment
    on Jun 19, 2020
  7. rrousselGit commented on Jun 24, 2020

    @rrousselGit
    Contributor

    Happens with package:animation too rrousselGit/riverpod#10 (comment)

  8. added
    customer: crowdAffects or could affect many people, though not necessarily a specific customer.
    f: routesNavigator, Router, and related APIs.
    on Aug 6, 2020
  9. diego-lipinski-de-castro commented on Aug 30, 2020

    @diego-lipinski-de-castro

    Gravacao-de-Tela-2020-08-30-as-0

    wtf is happening to my text when its transitioning?

  10. esDotDev commented on Aug 30, 2020

    @esDotDev

    Try a " hack " fix. Something to do with Flutter measuring it like 1px diffently while in motion, putting in padding spaces seemed to work for me like 6mths ago, ymmv

  11. diego-lipinski-de-castro commented on Aug 30, 2020

    @diego-lipinski-de-castro

    It kinda works. But it flashes the text, like a blinking

  12. 10 remaining items

  13. LongCatIsLooong commented on May 26, 2022

    @LongCatIsLooong
    ContributorAuthor

    Hi @rrousselGit @fzyzcjy I checked out the https://github.com/fzyzcjy/flutter_portal project and it looks like a really promising solution to this problem. Are you ok with integrating some of its APIs into Overlay, as an addition to the OverlayEntry API? I'll be happy to create a pull request and attribute the idea to you/the flutter_portal package, and let you review it if you're ok with that.

  14. rrousselGit commented on May 26, 2022

    @rrousselGit
    Contributor

    That'd be lovely! In fact, I proposed that a long time ago (#50961)

    It'd be awesome to have that be an official solution.

  15. fzyzcjy commented on May 26, 2022

    @fzyzcjy
    Contributor

    @LongCatIsLooong Sure! It would be great to be in official package!

  16. LongCatIsLooong commented on Jun 1, 2022

    @LongCatIsLooong
    ContributorAuthor

    After trying to port Portal to Overlay, I wonder would the PortalTarget's RenderObject (a _RenderPortalTargetTheater) re-layout when the incoming constraints on the portal (RenderPortalTheater I assume) changes? For instance when you have a widget tree like this:

    Portal (RenderPortalTheater)
        |
    Center
        |
    SizedBox.square(dimension: 50)
        |
    PortalTarget (filled)
    

    It seems to me that PortalTarget won't resize if Portal is resized from 150x150 to 100x100? With the SizedBox the incoming constraints on the PortalTarget would still be 50x50, and PortalTarget is also not marked needs layout.

  17. rrousselGit commented on Jun 1, 2022

    @rrousselGit
    Contributor

    I'm not sure if it does, but it should.

    The Portal should have access to the list of associated entries, so it should be able to make them relayout right?

  18. fzyzcjy commented on Jun 1, 2022

    @fzyzcjy
    Contributor

    +1

    When PortalTarget feels its environment changes, it will tell Portal about it.

  19. added
    P1High-priority issues at the top of the work list
    on Jan 24, 2023
  20. flutter-triage-bot commented on Nov 25, 2023

    @flutter-triage-bot

    This issue is marked P1 but has had no recent status updates.

    The P1 label indicates high-priority issues that are at the top of the work list. This is the highest priority level a bug can have if it isn't affecting a top-tier customer or breaking the build. Bugs marked P1 are generally actively being worked on unless the assignee is dealing with a P0 bug (or another P1 bug). Issues at this level should be resolved in a matter of months and should have monthly updates on GitHub.

    Please consider where this bug really falls in our current priorities, and label it or assign it accordingly. This allows people to have a clearer picture of what work is actually planned. Thanks!

  21. github-actions commented on Dec 10, 2023

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

  22. locked as resolved and limited conversation to collaborators on Dec 10, 2023
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

    P1High-priority issues at the top of the work listcustomer: crowdAffects or could affect many people, though not necessarily a specific customer.f: routesNavigator, Router, and related APIs.frameworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions