Пример #1
0
        public override Widget build(BuildContext context)
        {
            DefaultTextStyle defaultTextStyle   = DefaultTextStyle.of(context);
            TextStyle        effectiveTextStyle = style;

            if (style == null || style.inherit)
            {
                effectiveTextStyle = defaultTextStyle.style.merge(style);
            }

            return(new RichText(
                       textAlign: textAlign ?? defaultTextStyle.textAlign ?? TextAlign.left,
                       softWrap: softWrap ?? defaultTextStyle.softWrap,
                       overflow: overflow ?? defaultTextStyle.overflow,
                       textScaleFactor: textScaleFactor ?? MediaQuery.textScaleFactorOf(context),
                       maxLines: maxLines ?? defaultTextStyle.maxLines,
                       strutStyle: strutStyle,
                       textWidthBasis: textWidthBasis ?? defaultTextStyle.textWidthBasis,
                       textHeightBehavior: textHeightBehavior ?? defaultTextStyle.textHeightBehavior,
                       text: new TextSpan(
                           style: effectiveTextStyle,
                           text: data,
                           children: textSpan != null ? new List <InlineSpan> {
                textSpan
            } : null
                           )
                       ));
        }
Пример #2
0
 public static Widget merge(
     Widget child,
     Key key                                  = null,
     TextStyle style                          = null,
     TextAlign?textAlign                      = null,
     bool?softWrap                            = null,
     TextOverflow?overflow                    = null,
     int?maxLines                             = null,
     TextWidthBasis?textWidthBasis            = null,
     ui.TextHeightBehavior textHeightBehavior = null
     )
 {
     D.assert(child != null);
     return(new Builder(
                builder: (BuildContext context) => {
         DefaultTextStyle parent = DefaultTextStyle.of(context);
         return new DefaultTextStyle(
             key: key,
             style: parent.style.merge(style),
             textAlign: textAlign ?? parent.textAlign,
             softWrap: softWrap ?? parent.softWrap,
             overflow: overflow ?? parent.overflow,
             maxLines: maxLines ?? parent.maxLines,
             textWidthBasis: textWidthBasis ?? parent.textWidthBasis,
             child: child
             );
     }
                ));
 }
Пример #3
0
        public override Widget build(BuildContext context)
        {
            DefaultTextStyle defaultTextStyle   = DefaultTextStyle.of(context);
            TextStyle        effectiveTextStyle = this.style;

            if (this.style == null || this.style.inherit)
            {
                effectiveTextStyle = defaultTextStyle.style.merge(this.style);
            }

            return(new RichText(
                       textAlign: this.textAlign ?? defaultTextStyle.textAlign ?? TextAlign.left,
                       softWrap: this.softWrap ?? defaultTextStyle.softWrap,
                       overflow: this.overflow ?? defaultTextStyle.overflow,
                       textScaleFactor: this.textScaleFactor ?? MediaQuery.textScaleFactorOf(context),
                       maxLines: this.maxLines ?? defaultTextStyle.maxLines,
                       strutStyle: this.strutStyle,
                       text: new TextSpan(
                           style: effectiveTextStyle,
                           text: this.data,
                           children: this.textSpan != null ? new List <TextSpan> {
                this.textSpan
            } : null
                           )
                       ));
        }
Пример #4
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
                    );
            }

            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
                );

            result = new MediaQuery(
                data: MediaQueryData.fromWindow(this.widget.window),
                child: result
                );

            return(result);
        }
Пример #5
0
        public override bool updateShouldNotify(InheritedWidget oldWidget)
        {
            DefaultTextStyle _oldWidget = (DefaultTextStyle)oldWidget;

            return(style != _oldWidget.style ||
                   textAlign != _oldWidget.textAlign ||
                   softWrap != _oldWidget.softWrap ||
                   overflow != _oldWidget.overflow ||
                   maxLines != _oldWidget.maxLines ||
                   textWidthBasis != _oldWidget.textWidthBasis ||
                   textHeightBehavior != _oldWidget.textHeightBehavior);
        }
Пример #6
0
        public override Widget build(BuildContext context)
        {
            FocusScope.of(context).reparentIfNeeded(this.widget.focusNode);

            DefaultTextStyle defaultTextStyle   = DefaultTextStyle.of(context);
            TextStyle        effectiveTextStyle = this.widget.style;

            if (this.widget.style == null || this.widget.style.inherit)
            {
                effectiveTextStyle = defaultTextStyle.style.merge(this.widget.style);
            }

            Widget child = new RichText(
                key: this._richTextKey,
                textAlign: this.widget.textAlign ?? defaultTextStyle.textAlign ?? TextAlign.left,
                softWrap: this.widget.softWrap ?? defaultTextStyle.softWrap,
                overflow: this.widget.overflow ?? defaultTextStyle.overflow,
                textScaleFactor: this.widget.textScaleFactor ?? MediaQuery.textScaleFactorOf(context),
                maxLines: this.widget.maxLines ?? defaultTextStyle.maxLines,
                text: new TextSpan(
                    style: effectiveTextStyle,
                    text: this.widget.data,
                    children: this.widget.textSpan != null ? new List <TextSpan> {
                this.widget.textSpan
            } : null
                    ),
                onSelectionChanged: () => {
                if (this._hasFocus)
                {
                    return;
                }

                FocusScope.of(this.context).requestFocus(this.widget.focusNode);
            },
                selectionColor: this.widget.selectionColor ?? Colors.blue);

            return(new IgnorePointer(
                       ignoring: false,
                       child: new RichTextSelectionGestureDetector(
                           onTapDown: this._handleTapDown,
                           onSingleTapUp: this._handleSingleTapUp,
                           onSingleTapCancel: this._handleSingleTapCancel,
                           onSingleLongTapStart: this._handleLongPress,
                           onDragSelectionStart: this._handleDragSelectionStart,
                           onDragSelectionUpdate: this._handleDragSelectionUpdate,
                           behavior: HitTestBehavior.translucent,
                           child: child
                           )
                       ));
        }
Пример #7
0
        public override Widget wrap(BuildContext context, Widget child)
        {
            DefaultTextStyle defaultTextStyle = context.findAncestorWidgetOfExactType <DefaultTextStyle>();

            return(this == defaultTextStyle ? child : new DefaultTextStyle(
                       style: style,
                       textAlign: textAlign,
                       softWrap: softWrap,
                       overflow: overflow,
                       maxLines: maxLines,
                       textWidthBasis: textWidthBasis,
                       textHeightBehavior: textHeightBehavior,
                       child: child
                       ));
        }
Пример #8
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);
        }
Пример #9
0
        public override Widget build(BuildContext context)
        {
            Widget navigator = null;

            if (_navigator != null)
            {
                RouteListFactory routeListFactory = (state, route) => {
                    return(widget.onGenerateInitialRoutes(initialRoute: route));
                };
                navigator = new Navigator(
                    key: _navigator,
                    initialRoute: WidgetsBinding.instance.window.defaultRouteName != Navigator.defaultRouteName
                        ? WidgetsBinding.instance.window.defaultRouteName
                        : widget.initialRoute ?? WidgetsBinding.instance.window.defaultRouteName,
                    onGenerateRoute: _onGenerateRoute,
                    onGenerateInitialRoutes: widget.onGenerateInitialRoutes == null
                        ? Navigator.defaultGenerateInitialRoutes
                        : routeListFactory,
                    onUnknownRoute: _onUnknownRoute,
                    observers: widget.navigatorObservers
                    );
            }

            Widget result;

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

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

            PerformanceOverlay performanceOverlay = null;

            if (widget.showPerformanceOverlay || WidgetsApp.showPerformanceOverlayOverride)
            {
                performanceOverlay = PerformanceOverlay.allEnabled(
                    checkerboardRasterCacheImages: widget.checkerboardRasterCacheImages,
                    checkerboardOffscreenLayers: widget.checkerboardOffscreenLayers
                    );
            }
            else if (widget.checkerboardRasterCacheImages || widget.checkerboardOffscreenLayers)
            {
                performanceOverlay = new PerformanceOverlay(
                    checkerboardRasterCacheImages: widget.checkerboardRasterCacheImages,
                    checkerboardOffscreenLayers: widget.checkerboardOffscreenLayers
                    );
            }


            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 (widget.debugShowWidgetInspector || WidgetsApp.debugShowWidgetInspectorOverride)
                {
                    result = new WidgetInspector(
                        child: result,
                        selectButtonBuilder: widget.inspectorSelectButtonBuilder
                        );
                }

                if (widget.debugShowCheckedModeBanner && WidgetsApp.debugAllowBannerOverride)
                {
                    result = new CheckedModeBanner(
                        child: result
                        );
                }

                return(true);
            });

            //Fix Me !!
            //TODO: the following line is a work-around for some potential TextDirection bug
            //In the home page of the Shrine sample, the positions of the buttons are not correct, which is
            //determined by the TextDirection of some widget. we should fix it!
            result = new Directionality(child: result, TextDirection.ltr);

            Widget title = null;

            if (widget.onGenerateTitle != null)
            {
                title = new Builder(
                    builder: context2 => {
                    var _title = widget.onGenerateTitle(context: context2);
                    D.assert(_title != null, () => "onGenerateTitle must return a non-null String");
                    return(new Title(
                               title: _title,
                               color: widget.color,
                               child: result
                               ));
                }
                    );
            }
            else
            {
                title = new Title(
                    title: widget.title,
                    color: widget.color,
                    child: result
                    );
            }

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

            D.assert(_debugCheckLocalizations(appLocale: appLocale));

            return(new Shortcuts(
                       shortcuts: widget.shortcuts ?? WidgetsApp.defaultShortcuts,
                       debugLabel: "<Default WidgetsApp Shortcuts>",
                       child: new Actions(
                           actions: widget.actions ?? WidgetsApp.defaultActions,
                           child: new FocusTraversalGroup(
                               policy: new ReadingOrderTraversalPolicy(),
                               child: new _MediaQueryFromWindow(
                                   child: new Localizations(
                                       locale: appLocale,
                                       delegates: _localizationsDelegates.ToList(),
                                       child: title
                                       )
                                   )
                               )
                           )
                       ));
        }