Ejemplo n.º 1
0
        public override Widget build(BuildContext context)
        {
            Widget navigator = null;

            if (this._navigator != null)
            {
                navigator = new Navigator(
                    key: this._navigator,
                    initialRoute: this.widget.initialRoute ?? Navigator.defaultRouteName,
                    onGenerateRoute: this._onGenerateRoute,
                    onUnknownRoute: this._onUnknownRoute,
                    observers: this.widget.navigatorObservers
                    );
            }


            Widget result;

            if (this.widget.builder != null)
            {
                result = new Builder(
                    builder: _context => { return(this.widget.builder(_context, navigator)); }
                    );
            }
            else
            {
                D.assert(navigator != null);
                result = navigator;
            }

            if (this.widget.textStyle != null)
            {
                result = new DefaultTextStyle(
                    style: this.widget.textStyle,
                    child: result
                    );
            }

            PerformanceOverlay performanceOverlay = null;

            if (this.widget.showPerformanceOverlay)
            {
                performanceOverlay = PerformanceOverlay.allEnabled();
            }

            if (performanceOverlay != null)
            {
                result = new Stack(
                    children: new List <Widget> {
                    result,
                    new Positioned(top: 0.0f,
                                   left: 0.0f,
                                   right: 0.0f,
                                   child: performanceOverlay)
                });
            }

            D.assert(() => {
                if (WidgetInspectorService.instance.debugShowInspector)
                {
                    result = new WidgetInspector(null, result, this._InspectorSelectButtonBuilder);
                }

                return(true);
            });

            result = new Directionality(child: result, TextDirection.ltr);
            result = new WindowProvider(
                window: this.widget.window,
                child: result
                );

            Locale appLocale = this.widget.locale != null
                ? this._resolveLocales(new List <Locale> {
                this.widget.locale
            }, this.widget.supportedLocales)
                : this._locale;

            result = new MediaQuery(
                data: MediaQueryData.fromWindow(this.widget.window),
                child: new Localizations(
                    locale: appLocale,
                    delegates: this._localizationsDelegates,
                    child: result)
                );

            return(result);
        }
Ejemplo n.º 2
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);
        }