Beispiel #1
0
        _allHeroesFor(BuildContext context, bool isUserGestureTransition, NavigatorState navigator)
        {
            D.assert(context != null);
            D.assert(navigator != null);
            Dictionary <object, _HeroState> result = new Dictionary <object, _HeroState> {
            };

            void addHero(StatefulElement hero, object tag)
            {
                D.assert(() => {
                    if (result.ContainsKey(tag))
                    {
                        throw new UIWidgetsError(
                            "There are multiple heroes that share the same tag within a subtree.\n" +
                            "Within each subtree for which heroes are to be animated (typically a PageRoute subtree), " +
                            "each Hero must have a unique non-null tag.\n" +
                            $"In this case, multiple heroes had the following tag: {tag}\n" +
                            "Here is the subtree for one of the offending heroes:\n" +
                            $"{hero.toStringDeep(prefixLineOne: "# ")}"
                            );
                    }

                    return(true);
                });
                _HeroState heroState = (_HeroState)hero.state;

                result[tag] = heroState;
            }

            void visitor(Element element)
            {
                if (element.widget is Hero)
                {
                    StatefulElement hero       = (StatefulElement)element;
                    Hero            heroWidget = (Hero)element.widget;
                    if (!isUserGestureTransition || heroWidget.transitionOnUserGestures)
                    {
                        object tag = heroWidget.tag;
                        D.assert(tag != null);
                        if (Navigator.of(hero) == navigator)
                        {
                            addHero(hero, tag);
                        }
                        else
                        {
                            ModalRoute heroRoute = ModalRoute.of(hero);
                            if (heroRoute != null && heroRoute is PageRoute && heroRoute.isCurrent)
                            {
                                addHero(hero, tag);
                            }
                        }
                    }
                }

                element.visitChildren(visitor);
            }

            context.visitChildElements(visitor);
            return(result);
        }
Beispiel #2
0
        public static bool canPop(BuildContext context)
        {
            NavigatorState navigator = Navigator.of(context, nullOk: true);

            return(navigator != null && navigator.canPop());
        }
Beispiel #3
0
 protected internal virtual void dispose()
 {
     this._navigator = null;
 }
Beispiel #4
0
        internal static Dictionary <object, _HeroState> _allHeroesFor(
            BuildContext context,
            bool isUserGestureTransition,
            NavigatorState navigator)
        {
            D.assert(context != null);
            D.assert(navigator != null);

            Dictionary <object, _HeroState> result = new Dictionary <object, _HeroState> {
            };

            void inviteHero(StatefulElement hero, object tag)
            {
                D.assert(() => {
                    if (result.ContainsKey(tag))
                    {
                        throw new UIWidgetsError(
                            new List <DiagnosticsNode>()
                        {
                            new ErrorSummary("There are multiple heroes that share the same tag within a subtree."),
                            new ErrorDescription(
                                "Within each subtree for which heroes are to be animated (i.e. a PageRoute subtree), " +
                                "each Hero must have a unique non-null tag.\n" +
                                $"In this case, multiple heroes had the following tag: {tag}\n"
                                ),
                            new DiagnosticsProperty <StatefulElement>("Here is the subtree for one of the offending heroes", hero, linePrefix: "# ", style: DiagnosticsTreeStyle.dense),
                        });
                    }
                    return(true);
                });
                Hero       heroWidget = hero.widget as Hero;
                _HeroState heroState  = hero.state as _HeroState;

                if (!isUserGestureTransition || heroWidget.transitionOnUserGestures)
                {
                    result[tag] = heroState;
                }
                else
                {
                    heroState.ensurePlaceholderIsHidden();
                }
            }

            void visitor(Element element)
            {
                Widget widget = element.widget;

                if (widget is Hero)
                {
                    StatefulElement hero = element as StatefulElement;
                    object          tag  = ((Hero)widget).tag;
                    D.assert(tag != null);
                    if (Navigator.of(hero) == navigator)
                    {
                        inviteHero(hero, tag);
                    }
                    else
                    {
                        ModalRoute heroRoute = ModalRoute.of(hero);
                        if (heroRoute != null && heroRoute is PageRoute && heroRoute.isCurrent)
                        {
                            inviteHero(hero, tag);
                        }
                    }
                }

                element.visitChildren(visitor);
            }

            context.visitChildElements(visitor);
            return(result);
        }