Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
 public _ModalScope(
     Key key          = null,
     ModalRoute route = null)
     : base(key)
 {
     this.route = route;
 }
Ejemplo n.º 3
0
        public override void didChangeDependencies()
        {
            base.didChangeDependencies();
            if (widget.onWillPop != null)
            {
                _route?.removeScopedWillPopCallback(widget.onWillPop);
            }

            _route = ModalRoute.of(context);
            if (widget.onWillPop != null)
            {
                _route?.addScopedWillPopCallback(widget.onWillPop);
            }
        }
Ejemplo n.º 4
0
        public override void didUpdateWidget(StatefulWidget _oldWidget)
        {
            base.didUpdateWidget(_oldWidget);
            D.assert(_route == ModalRoute.of(context));
            WillPopScope oldWidget = _oldWidget as WillPopScope;

            if (widget.onWillPop != oldWidget.onWillPop && _route != null)
            {
                if (oldWidget.onWillPop != null)
                {
                    _route.removeScopedWillPopCallback(oldWidget.onWillPop);
                }

                if (widget.onWillPop != null)
                {
                    _route.addScopedWillPopCallback(widget.onWillPop);
                }
            }
        }
Ejemplo n.º 5
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);
        }