protected void invokeCallback(string name, RecognizerVoidCallvack callback, Func <string> debugReport = null)
        {
            D.assert(callback != null);
            try {
                D.assert(() => {
                    if (D.debugPrintRecognizerCallbacksTrace)
                    {
                        var report = debugReport != null ? debugReport() : null;
                        var prefix = D.debugPrintGestureArenaDiagnostics ? new string(' ', 19) + "❙ " : "";
                        Debug.LogFormat("{0}this calling {1} callback.{2}",
                                        prefix, name, report.isNotEmpty() ? " " + report : "");
                    }

                    return(true);
                });
            }
            catch (Exception ex) {
                IEnumerable <DiagnosticsNode> infoCollector()
                {
                    yield return(new StringProperty("Handler", name));

                    yield return(new DiagnosticsProperty <GestureRecognizer>("Recognizer", this, style: DiagnosticsTreeStyle.errorProperty));
                }

                UIWidgetsError.reportError(new UIWidgetsErrorDetails(
                                               exception: ex,
                                               library: "gesture",
                                               context: new ErrorDescription("while handling a gesture"),
                                               informationCollector: infoCollector
                                               ));
            }
        }
        public void resolve(PointerSignalEvent evt)
        {
            if (this._firstRegisteredCallback == null)
            {
                D.assert(this._currentEvent == null);
                return;
            }

            D.assert(this._currentEvent == evt);
            try {
                this._firstRegisteredCallback(evt);
            }
            catch (Exception exception) {
                UIWidgetsError.reportError(new UIWidgetsErrorDetails(
                                               exception: exception,
                                               library: "gesture library",
                                               context: "while resolving a PointerSignalEvent",
                                               informationCollector: information => {
                    information.AppendLine("Event: ");
                    information.AppendFormat(" {0}", evt);
                }
                                               )
                                           );
            }

            this._firstRegisteredCallback = null;
            this._currentEvent            = null;
        }
Beispiel #3
0
        void _executeTimingsCallbacks(List<FrameTiming> timings) {
            var clonedCallbacks =
                new List<TimingsCallback>(collection: _timingsCallbacks);
            foreach (var callback in clonedCallbacks) {
                try {
                    if (_timingsCallbacks.Contains(item: callback)) {
                        callback(timings: timings);
                    }
                }
                catch (Exception ex) {
                    InformationCollector collector = null;
                    D.assert(() => {
                        IEnumerable<DiagnosticsNode> infoCollect() {
                            yield return new DiagnosticsProperty<TimingsCallback>(
                                "The TimingsCallback that gets executed was",
                                value: callback,
                                style: DiagnosticsTreeStyle.errorProperty);
                        }

                        collector = infoCollect;
                        return true;
                    });

                    UIWidgetsError.reportError(new UIWidgetsErrorDetails(
                        exception: ex,
                        context: new ErrorDescription("while executing callbacks for FrameTiming"),
                        informationCollector: collector
                    ));
                }
            }
        }
Beispiel #4
0
        public void notifyListeners()
        {
            var localListeners = new List <VoidCallback>(this._listeners);

            foreach (VoidCallback listener in localListeners)
            {
                try {
                    if (this._listeners.Contains(listener))
                    {
                        listener();
                    }
                }
                catch (Exception exception) {
                    UIWidgetsError.reportError(new UIWidgetsErrorDetails(
                                                   exception: exception,
                                                   library: "animation library",
                                                   context: "while notifying listeners for " + this.GetType(),
                                                   informationCollector: information => {
                        information.AppendLine("The " + this.GetType() + " notifying listeners was:");
                        information.Append("  " + this);
                    }
                                                   ));
                }
            }
        }
        public virtual void addListener(ImageListener listener, ImageErrorListener onError = null)
        {
            this._listeners.Add(new _ImageListenerPair {
                listener = listener, errorListener = onError
            });

            if (this.currentImage != null)
            {
                try {
                    listener(this.currentImage, true);
                }
                catch (Exception ex) {
                    this.reportError(
                        context: "by a synchronously-called image listener",
                        exception: ex
                        );
                }
            }

            if (this.currentError != null && onError != null)
            {
                try {
                    onError(this.currentError.exception);
                }
                catch (Exception ex) {
                    UIWidgetsError.reportError(
                        new UIWidgetsErrorDetails(
                            exception: ex,
                            library: "image resource service",
                            context: "when reporting an error to an image listener"
                            )
                        );
                }
            }
        }
Beispiel #6
0
        public void resolve(PointerSignalEvent evt)
        {
            if (_firstRegisteredCallback == null)
            {
                D.assert(_currentEvent == null);
                return;
            }

            D.assert(_isSameEvent(_currentEvent, evt));
            try {
                _firstRegisteredCallback(_currentEvent);
            }
            catch (Exception exception) {
                IEnumerable <DiagnosticsNode> infoCollector()
                {
                    yield return(new DiagnosticsProperty <PointerSignalEvent>("Event", evt, style: DiagnosticsTreeStyle.errorProperty));
                }

                UIWidgetsError.reportError(new UIWidgetsErrorDetails(
                                               exception: exception,
                                               library: "gesture library",
                                               context: new ErrorDescription("while resolving a PointerSignalEvent"),
                                               informationCollector: infoCollector
                                               )
                                           );
            }

            _firstRegisteredCallback = null;
            _currentEvent            = null;
        }
Beispiel #7
0
        public void dispatchEvent(PointerEvent evt, HitTestResult result)
        {
            if (result == null)
            {
                D.assert(evt is PointerHoverEvent || evt is PointerAddedEvent || evt is PointerRemovedEvent);
                try {
                    this.pointerRouter.route(evt);
                }
                catch (Exception ex) {
                    UIWidgetsError.reportError(new UIWidgetsErrorDetails(
                                                   exception: ex,
                                                   library: "gesture library",
                                                   context: "while dispatching a non-hit-tested pointer event",
                                                   informationCollector: information => {
                        information.AppendLine("Event: ");
                        information.AppendFormat(" {0}", evt);
                    }
                                                   )
                                               );
                }

                return;
            }

            foreach (HitTestEntry entry in result.path)
            {
                try {
                    entry.target.handleEvent(evt, entry);
                }
                catch (Exception ex) {
                    D.logError("Error while dispatching a pointer event: ", ex);
                }
            }
        }
Beispiel #8
0
        public virtual void addListener(ImageStreamListener listener)
        {
            _listeners.Add(listener);
            if (_currentImage != null)
            {
                try {
                    listener.onImage(_currentImage, true);
                }
                catch (Exception exception) {
                    reportError(
                        context: new ErrorDescription("by a synchronously-called image listener"),
                        exception: exception
                        );
                }
            }

            if (_currentError != null && listener.onError != null)
            {
                try {
                    listener.onError(_currentError.exception);
                }
                catch (Exception exception) {
                    UIWidgetsError.reportError(
                        new UIWidgetsErrorDetails(
                            exception: exception,
                            library: "image resource service",
                            context: new ErrorDescription("by a synchronously-called image error listener")
                            )
                        );
                }
            }
        }
Beispiel #9
0
        public void notifyListeners()
        {
            var localListeners = new List <VoidCallback>(_listeners);

            foreach (VoidCallback listener in localListeners)
            {
                InformationCollector collector = null;
                D.assert(() => {
                    IEnumerable <DiagnosticsNode> infoCollector()
                    {
                        yield return(new DiagnosticsProperty <AnimationLocalListenersMixinAnimationLazyListenerMixinAnimation <T> >(
                                         "The " + GetType() + " notifying listeners was",
                                         this,
                                         style: DiagnosticsTreeStyle.errorProperty
                                         ));
                    }
                    collector = infoCollector;
                    return(true);
                });
                try {
                    if (_listeners.Contains(listener))
                    {
                        listener();
                    }
                } catch (Exception exception) {
                    UIWidgetsError.reportError(new UIWidgetsErrorDetails(
                                                   exception: exception,
                                                   library: "animation library",
                                                   context: new ErrorDescription("while notifying listeners for " + GetType()),
                                                   informationCollector: collector
                                                   ));
                }
            }
        }
Beispiel #10
0
        void _invokeFrameCallback(FrameCallback callback, TimeSpan timeStamp, StackTrace callbackStack = null)
        {
            D.assert(callback != null);
            D.assert(_FrameCallbackEntry.debugCurrentCallbackStack == null);
            D.assert(() => {
                _FrameCallbackEntry.debugCurrentCallbackStack = callbackStack;
                return(true);
            });

            try {
                callback(timeStamp);
            } catch (Exception ex) {
                UIWidgetsError.reportError(new UIWidgetsErrorDetails(
                                               exception: ex,
                                               library: "scheduler library",
                                               context: "during a scheduler callback",
                                               informationCollector: callbackStack == null
                        ? (InformationCollector)null
                        : information => {
                    information.AppendLine(
                        "\nThis exception was thrown in the context of a scheduler callback. " +
                        "When the scheduler callback was _registered_ (as opposed to when the " +
                        "exception was thrown), this was the stack:"
                        );
                    UIWidgetsError.defaultStackFilter(callbackStack.ToString().TrimEnd().Split('\n'))
                    .Each((line) => information.AppendLine(line));
                }
                                               ));
            }

            D.assert(() => {
                _FrameCallbackEntry.debugCurrentCallbackStack = null;
                return(true);
            });
        }
Beispiel #11
0
        public Future handlePlatformMessage(
            string channel, byte[] data,
            PlatformMessageResponseCallback callback)
        {
            MessageHandler handler = _handlers[channel];

            if (handler == null)
            {
                ui_.channelBuffers.push(channel, data, callback);
                return(Future.value());
            }

            return(handler(data).then(bytes => {
                var response = (byte[])bytes;
                callback(response);
                return FutureOr.nil;
            }, onError: exception => {
                UIWidgetsError.reportError(new UIWidgetsErrorDetails(
                                               exception: exception,
                                               library: "services library",
                                               context: new ErrorDescription("during a platform message callback"))
                                           );
                callback(null);
                return FutureOr.nil;
            }));
        }
Beispiel #12
0
        void _show()
        {
            D.assert(this._mode != _RefreshIndicatorMode.refresh);
            D.assert(this._mode != _RefreshIndicatorMode.snap);
            Promise completer = new Promise();

            this._pendingRefreshFuture = completer;
            this._mode = _RefreshIndicatorMode.snap;
            this._positionController
            .animateTo(1.0f / RefreshIndicatorUtils._kDragSizeFactorLimit,
                       duration: RefreshIndicatorUtils._kIndicatorSnapDuration)
            .Then(() => {
                if (this.mounted && this._mode == _RefreshIndicatorMode.snap)
                {
                    D.assert(this.widget.onRefresh != null);
                    this.setState(() => { this._mode = _RefreshIndicatorMode.refresh; });

                    Promise refreshResult = this.widget.onRefresh();
                    D.assert(() => {
                        if (refreshResult == null)
                        {
                            UIWidgetsError.reportError(new UIWidgetsErrorDetails(
                                                           exception: new UIWidgetsError(
                                                               "The onRefresh callback returned null.\n" +
                                                               "The RefreshIndicator onRefresh callback must return a Promise."
                                                               ),
                                                           context: "when calling onRefresh",
                                                           library: "material library"
                                                           ));
                        }

                        return(true);
                    });
                    if (refreshResult == null)
                    {
                        return;
                    }

                    refreshResult.Then(() => {
                        if (this.mounted && this._mode == _RefreshIndicatorMode.refresh)
                        {
                            completer.Resolve();
                            this._dismiss(_RefreshIndicatorMode.done);
                        }
                    });
                }
            });
        }
Beispiel #13
0
        void _show()
        {
            D.assert(_mode != _RefreshIndicatorMode.refresh);
            D.assert(_mode != _RefreshIndicatorMode.snap);
            Completer completer = Completer.create();

            _pendingRefreshFuture = completer.future;
            _mode = _RefreshIndicatorMode.snap;
            _positionController
            .animateTo(1.0f / RefreshIndicatorUtils._kDragSizeFactorLimit,
                       duration: RefreshIndicatorUtils._kIndicatorSnapDuration)
            .then((value) => {
                if (mounted && _mode == _RefreshIndicatorMode.snap)
                {
                    D.assert(widget.onRefresh != null);
                    setState(() => { _mode = _RefreshIndicatorMode.refresh; });

                    Future refreshResult = widget.onRefresh();
                    D.assert(() => {
                        if (refreshResult == null)
                        {
                            UIWidgetsError.reportError(new UIWidgetsErrorDetails(
                                                           exception: new UIWidgetsError(
                                                               "The onRefresh callback returned null.\n" +
                                                               "The RefreshIndicator onRefresh callback must return a Promise."
                                                               ),
                                                           context: new ErrorDescription("when calling onRefresh"),
                                                           library: "material library"
                                                           ));
                        }

                        return(true);
                    });
                    if (refreshResult == null)
                    {
                        return;
                    }

                    refreshResult.whenComplete(() => {
                        if (mounted && _mode == _RefreshIndicatorMode.refresh)
                        {
                            completer.complete();
                            _dismiss(_RefreshIndicatorMode.done);
                        }
                    });
                }
            });
        }
Beispiel #14
0
        internal static UIWidgetsErrorDetails _debugReportException(
            string context,
            Exception exception,
            InformationCollector informationCollector = null
            )
        {
            var details = new UIWidgetsErrorDetails(
                exception: exception,
                library: "widgets library",
                context: context,
                informationCollector: informationCollector
                );

            UIWidgetsError.reportError(details);
            return(details);
        }
Beispiel #15
0
        void _invokeFrameCallback(FrameCallback callback, TimeSpan timeStamp, string callbackStack = null)
        {
            D.assert(callback != null);
            D.assert(_FrameCallbackEntry.debugCurrentCallbackStack == null);
            D.assert(() => {
                _FrameCallbackEntry.debugCurrentCallbackStack = callbackStack;
                return(true);
            });

            try {
                callback(timeStamp: timeStamp);
            }
            catch (Exception ex) {
                IEnumerable <DiagnosticsNode> infoCollector()
                {
                    yield return(DiagnosticsNode.message(
                                     "\nThis exception was thrown in the context of a scheduler callback. " +
                                     "When the scheduler callback was _registered_ (as opposed to when the " +
                                     "exception was thrown), this was the stack:"));

                    var builder = new StringBuilder();

                    foreach (var line in UIWidgetsError.defaultStackFilter(
                                 callbackStack.TrimEnd().Split('\n')))
                    {
                        builder.AppendLine(value: line);
                    }

                    yield return(DiagnosticsNode.message(builder.ToString()));
                }

                UIWidgetsError.reportError(new UIWidgetsErrorDetails(
                                               exception: ex,
                                               "scheduler library",
                                               new ErrorDescription("during a scheduler callback"),
                                               informationCollector: callbackStack == null
                        ? (InformationCollector)null
                        : infoCollector
                                               ));
            }

            D.assert(() => {
                _FrameCallbackEntry.debugCurrentCallbackStack = null;
                return(true);
            });
        }
Beispiel #16
0
        bool handleEventLoopCallback()
        {
            if (_taskQueue.isEmpty || locked)
            {
                return(false);
            }

            var entry = _taskQueue.first;

            if (schedulingStrategy(priority: entry.priority, this))
            {
                try {
                    _taskQueue.removeFirst();
                    entry.run();
                }
                catch (Exception exception) {
                    string callbackStack = null;
                    D.assert(() => {
                        callbackStack = entry.debugStack;
                        return(true);
                    });

                    IEnumerable <DiagnosticsNode> infoCollector()
                    {
                        yield return(DiagnosticsNode.message(
                                         "\nThis exception was thrown in the context of a scheduler callback. " +
                                         "When the scheduler callback was _registered_ (as opposed to when the " +
                                         "exception was thrown), this was the stack: " + callbackStack));
                    }

                    UIWidgetsError.reportError(new UIWidgetsErrorDetails(
                                                   exception: exception,
                                                   "scheduler library",
                                                   new ErrorDescription("during a task callback"),
                                                   informationCollector: callbackStack == null
                            ? (InformationCollector)null
                            : infoCollector
                                                   ));
                }

                return(_taskQueue.isNotEmpty);
            }

            return(false);
        }
Beispiel #17
0
        void _rebuild()
        {
            try {
                _child = updateChild(_child, widget.child,
                                     _rootChildSlot);
                // allow
            }
            catch (Exception ex) {
                var details = new UIWidgetsErrorDetails(
                    exception: ex,
                    library: "widgets library",
                    context: new ErrorDescription("attaching to the render tree")
                    );
                UIWidgetsError.reportError(details);

                Widget error = ErrorWidget.builder(details);
                _child = updateChild(null, error, _rootChildSlot);
            }
        }
Beispiel #18
0
        Future <byte[]> _sendPlatformMessage(string channel, byte[] message)
        {
            Completer completer = Completer.create();

            Window.instance.sendPlatformMessage(channel, message, (reply) => {
                try {
                    completer.complete(FutureOr.value(reply));
                }
                catch (Exception exception) {
                    UIWidgetsError.reportError(new UIWidgetsErrorDetails(
                                                   exception: exception,
                                                   library: "services library",
                                                   context: new ErrorDescription("during a platform message response callback")
                                                   ));
                }
            });

            return(completer.future.to <byte[]>());
        }
Beispiel #19
0
 List <PictureLayer> _processConflictingPhysicalLayers(PhysicalModelLayer predecessor, PhysicalModelLayer child)
 {
     UIWidgetsError.reportError(new UIWidgetsErrorDetails(
                                    exception: new UIWidgetsError("Painting order is out of order with respect to elevation.\n" +
                                                                  "See https://api.flutter.dev/flutter/rendering/debugCheckElevations.html " +
                                                                  "for more details."),
                                    context: "during compositing",
                                    informationCollector: (StringBuilder builder) => {
         builder.AppendLine("Attempted to composite layer");
         builder.AppendLine(child.ToString());
         builder.AppendLine("after layer");
         builder.AppendLine(predecessor.ToString());
         builder.AppendLine("which occupies the same area at a higher elevation.");
     }
                                    ));
     return(new List <PictureLayer> {
         this._highlightConflictingLayer(predecessor),
         this._highlightConflictingLayer(child)
     });
 }
Beispiel #20
0
        protected void reportError(
            DiagnosticsNode context = null,
            Exception exception     = null,
            InformationCollector informationCollector = null,
            bool silent = false)
        {
            _currentError = new UIWidgetsErrorDetails(
                exception: exception,
                library: "image resource service",
                context: context,
                informationCollector: informationCollector,
                silent: silent
                );

            var localErrorListeners = LinqUtils <ImageErrorListener> .WhereList(
                LinqUtils <ImageErrorListener, ImageStreamListener> .SelectList(_listeners, (l => l.onError)),
                (l => l != null));

            if (localErrorListeners.isEmpty())
            {
                UIWidgetsError.reportError(_currentError);
            }
            else
            {
                foreach (var errorListener in localErrorListeners)
                {
                    try {
                        errorListener(exception);
                    }
                    catch (Exception ex) {
                        UIWidgetsError.reportError(
                            new UIWidgetsErrorDetails(
                                context: new ErrorDescription("when reporting an error to an image listener"),
                                library: "image resource service",
                                exception: ex
                                )
                            );
                    }
                }
            }
        }
Beispiel #21
0
        public void dispatchEvent(PointerEvent evt, HitTestResult hitTestResult)
        {
            if (hitTestResult == null)
            {
                D.assert(evt is PointerHoverEvent ||
                         evt is PointerAddedEvent ||
                         evt is PointerRemovedEvent ||
                         evt is PointerDragFromEditorHoverEvent ||
                         evt is PointerDragFromEditorReleaseEvent
                         );
                try {
                    pointerRouter.route(evt);
                }
                catch (Exception ex) {
                    IEnumerable <DiagnosticsNode> infoCollector()
                    {
                        yield return(new DiagnosticsProperty <PointerEvent>("Event", evt, style: DiagnosticsTreeStyle.errorProperty));
                    }

                    UIWidgetsError.reportError(new UIWidgetsErrorDetails(
                                                   exception: ex,
                                                   library: "gesture library",
                                                   context: new ErrorDescription("while dispatching a non-hit-tested pointer event"),
                                                   informationCollector: infoCollector
                                                   )
                                               );
                }

                return;
            }

            foreach (HitTestEntry entry in hitTestResult.path)
            {
                try {
                    entry.target.handleEvent(evt.transformed(entry.transform), entry);
                }
                catch (Exception ex) {
                    D.logError("Error while dispatching a pointer event: ", ex);
                }
            }
        }
Beispiel #22
0
        public static Future precacheImage(
            ImageProvider provider,
            BuildContext context,
            Size size = null,
            ImageErrorListener onError = null
            )
        {
            var config    = createLocalImageConfiguration(context: context, size: size);
            var completer = Completer.create();
            var stream    = provider.resolve(configuration: config);
            ImageStreamListener listener = null;

            listener = new ImageStreamListener(
                (image, sync) => {
                if (!completer.isCompleted)
                {
                    completer.complete();
                }

                SchedulerBinding.instance.addPostFrameCallback(timeStamp => {
                    stream.removeListener(listener: listener);
                });
            },
                onError: error => {
                if (!completer.isCompleted)
                {
                    completer.complete();
                }

                stream.removeListener(listener: listener);
                UIWidgetsError.reportError(new UIWidgetsErrorDetails(
                                               context: new ErrorDescription("image failed to precache"),
                                               library: "image resource service",
                                               silent: true));
            }
                );
            stream.addListener(listener: listener);
            return(completer.future);
        }
        protected void reportError(
            string context      = null,
            Exception exception = null,
            InformationCollector informationCollector = null,
            bool silent = false)
        {
            this.currentError = new UIWidgetsErrorDetails(
                exception: exception,
                library: "image resource service",
                context: context,
                informationCollector: informationCollector,
                silent: silent
                );

            var localErrorListeners = this._listeners.Select(l => l.errorListener).Where(l => l != null).ToList();

            if (localErrorListeners.isEmpty())
            {
                UIWidgetsError.reportError(this.currentError);
            }
            else
            {
                foreach (var errorListener in localErrorListeners)
                {
                    try {
                        errorListener(exception);
                    }
                    catch (Exception ex) {
                        UIWidgetsError.reportError(
                            new UIWidgetsErrorDetails(
                                context: "when reporting an error to an image listener",
                                library: "image resource service",
                                exception: ex
                                )
                            );
                    }
                }
            }
        }
Beispiel #24
0
        public IPromise precacheImage(
            ImageProvider provider,
            BuildContext context,
            Size size = null,
            ImageErrorListener onError = null
            )
        {
            ImageConfiguration config = createLocalImageConfiguration(context, size: size);
            var         completer     = new Promise();
            ImageStream stream        = provider.resolve(config);

            void listener(ImageInfo image, bool sync)
            {
                completer.Resolve();
                stream.removeListener(listener);
            }

            void errorListener(Exception exception)
            {
                completer.Resolve();
                stream.removeListener(listener);
                if (onError != null)
                {
                    onError(exception);
                }
                else
                {
                    UIWidgetsError.reportError(new UIWidgetsErrorDetails(
                                                   context: "image failed to precache",
                                                   library: "image resource service",
                                                   exception: exception,
                                                   silent: true
                                                   ));
                }
            }

            stream.addListener(listener, onError: errorListener);
            return(completer);
        }
Beispiel #25
0
        protected T invokeCallback <T>(string name, RecognizerCallback <T> callback, Func <string> debugReport = null)
        {
            D.assert(callback != null);

            T result = default(T);

            try {
                D.assert(() => {
                    if (D.debugPrintRecognizerCallbacksTrace)
                    {
                        var report = debugReport != null ? debugReport() : null;
                        // The 19 in the line below is the width of the prefix used by
                        // _debugLogDiagnostic in arena.dart.
                        var prefix = D.debugPrintGestureArenaDiagnostics ? new string(' ', 19) + "❙ " : "";
                        Debug.LogFormat("{0}this calling {1} callback.{2}",
                                        prefix, name, report.isNotEmpty() ? " " + report : "");
                    }

                    return(true);
                });

                result = callback();
            }
            catch (Exception ex) {
                UIWidgetsError.reportError(new UIWidgetsErrorDetails(
                                               exception: ex,
                                               library: "gesture",
                                               context: "while handling a gesture",
                                               informationCollector: information => {
                    information.AppendLine("Handler: " + name);
                    information.AppendLine("Recognizer:");
                    information.AppendLine("  " + this);
                }
                                               ));
            }

            return(result);
        }
        static void _reportOverflow(RenderObject renderObject, RelativeRect overflow, string overflowHints)
        {
            overflowHints = overflowHints ?? $"The edge of the {renderObject.GetType()} that is " +
                            "overflowing has been marked in the rendering with a yellow and black " +
                            "striped pattern. This is usually caused by the contents being too big " +
                            $"for the {renderObject.GetType()}.\n" +
                            "This is considered an error condition because it indicates that there " +
                            "is content that cannot be seen. If the content is legitimately bigger " +
                            "than the available space, consider clipping it with a ClipRect widget " +
                            $"before putting it in the {renderObject.GetType()}, or using a scrollable " +
                            "container, like a ListView.";

            List <string> overflows = new List <string> {
            };

            if (overflow.left > 0.0f)
            {
                overflows.Add($"{_formatPixels(overflow.left)} pixels on the left");
            }

            if (overflow.top > 0.0f)
            {
                overflows.Add($"{_formatPixels(overflow.top)} pixels on the top");
            }

            if (overflow.bottom > 0.0f)
            {
                overflows.Add($"{_formatPixels(overflow.bottom)} pixels on the bottom");
            }

            if (overflow.right > 0.0f)
            {
                overflows.Add($"{_formatPixels(overflow.right)} pixels on the right");
            }

            string overflowText = "";

            D.assert(overflows.isNotEmpty(),
                     () => $"Somehow {renderObject.GetType()} didn't actually overflow like it thought it did.");
            switch (overflows.Count)
            {
            case 1:
                overflowText = overflows.first();
                break;

            case 2:
                overflowText = $"{overflows.first()} and {overflows.last()}";
                break;

            default:
                overflows[overflows.Count - 1] = $"and {overflows[overflows.Count - 1]}";
                overflowText = string.Join(", ", overflow);
                break;
            }

            UIWidgetsError.reportError(
                new UIWidgetsErrorDetails(
                    exception: new Exception($"A {renderObject.GetType()} overflowed by {overflowText}."),
                    library: "rendering library",
                    context: "during layout",
                    informationCollector: (information) => {
                information.AppendLine(overflowHints);
                information.AppendLine($"The specific {renderObject.GetType()} in question is:");
                information.AppendLine($"  {renderObject.toStringShallow(joiner: "\n  ")}");
                information.AppendLine(string.Concat(Enumerable.Repeat("◢◤", 32)));
            }
                    )
                );
        }
Beispiel #27
0
        public override void initState()
        {
            base.initState();
            foreach (var observer in this.widget.observers)
            {
                D.assert(observer.navigator == null);
                observer._navigator = this;
            }

            var initialRouteName = this.widget.initialRoute ?? Navigator.defaultRouteName;

            if (initialRouteName.StartsWith("/") && initialRouteName.Length > 1)
            {
                initialRouteName = initialRouteName.Substring(1);
                D.assert(Navigator.defaultRouteName == "/");
                var plannedInitialRouteNames = new List <string> {
                    Navigator.defaultRouteName
                };
                var plannedInitialRoutes = new List <Route> {
                    this._routeNamed(Navigator.defaultRouteName, true)
                };

                var routeParts = initialRouteName.Split('/');
                if (initialRouteName.isNotEmpty())
                {
                    var routeName = "";
                    foreach (var part in routeParts)
                    {
                        routeName += $"/{part}";
                        plannedInitialRouteNames.Add(routeName);
                        plannedInitialRoutes.Add(this._routeNamed(routeName, true));
                    }
                }

                if (plannedInitialRoutes.Contains(null))
                {
                    D.assert(() => {
                        UIWidgetsError.reportError(new UIWidgetsErrorDetails(
                                                       exception: new Exception(
                                                           "Could not navigate to initial route.\n" +
                                                           $"The requested route name was: \"{initialRouteName}\n" +
                                                           "The following routes were therefore attempted:\n" +
                                                           $" * {string.Join("\n * ", plannedInitialRouteNames)}\n" +
                                                           "This resulted in the following objects:\n" +
                                                           $" * {string.Join("\n * ", plannedInitialRoutes)}\n" +
                                                           "One or more of those objects was null, and therefore the initial route specified will be " +
                                                           $"ignored and \"{Navigator.defaultRouteName}\" will be used instead.")));
                        return(true);
                    });
                    this.push(this._routeNamed(Navigator.defaultRouteName));
                }
                else
                {
                    plannedInitialRoutes.Each(route => { this.push(route); });
                }
            }
            else
            {
                Route route = null;
                if (initialRouteName != Navigator.defaultRouteName)
                {
                    route = this._routeNamed(initialRouteName, true);
                }

                route = route ?? this._routeNamed(Navigator.defaultRouteName);
                this.push(route);
            }

            foreach (var route in this._history)
            {
                this._initialOverlayEntries.AddRange(route.overlayEntries);
            }
        }