Exemple #1
0
        void _paintWithPainter(Canvas canvas, Offset offset, CustomPainter painter)
        {
            int debugPreviousCanvasSaveCount = 0;

            canvas.save();
            D.assert(() => {
                debugPreviousCanvasSaveCount = canvas.getSaveCount();
                return(true);
            });
            if (offset != Offset.zero)
            {
                canvas.translate(offset.dx, offset.dy);
            }

            painter.paint(canvas, size);
            D.assert(() => {
                int debugNewCanvasSaveCount = canvas.getSaveCount();
                if (debugNewCanvasSaveCount > debugPreviousCanvasSaveCount)
                {
                    throw new UIWidgetsError(new List <DiagnosticsNode> {
                        new ErrorSummary(
                            $"The {painter} custom painter called canvas.save() or canvas.saveLayer() at least " +
                            $"{debugNewCanvasSaveCount - debugPreviousCanvasSaveCount} more " +
                            "times than it called canvas.restore()."
                            ),
                        new ErrorDescription("This leaves the canvas in an inconsistent state and will probably result in a broken display."),
                        new ErrorHint("You must pair each call to save()/saveLayer() with a later matching call to restore().")
                    });
                }

                if (debugNewCanvasSaveCount < debugPreviousCanvasSaveCount)
                {
                    throw new UIWidgetsError(new List <DiagnosticsNode> {
                        new ErrorSummary(
                            $"The {painter} custom painter called canvas.restore() " +
                            $"{debugPreviousCanvasSaveCount - debugNewCanvasSaveCount} more " +
                            "times than it called canvas.save() or canvas.saveLayer()."
                            ),
                        new ErrorDescription("This leaves the canvas in an inconsistent state and will result in a broken display."),
                        new ErrorHint("You should only call restore() if you first called save() or saveLayer().")
                    });
                }

                return(debugNewCanvasSaveCount == debugPreviousCanvasSaveCount);
            });
            canvas.restore();
        }
Exemple #2
0
        void _paintWithPainter(Canvas canvas, Offset offset, CustomPainter painter)
        {
            int debugPreviousCanvasSaveCount = 0;

            canvas.save();
            D.assert(() => {
                debugPreviousCanvasSaveCount = canvas.getSaveCount();
                return(true);
            });
            if (offset != Offset.zero)
            {
                canvas.translate(offset.dx, offset.dy);
            }

            painter.paint(canvas, this.size);
            D.assert(() => {
                int debugNewCanvasSaveCount = canvas.getSaveCount();
                if (debugNewCanvasSaveCount > debugPreviousCanvasSaveCount)
                {
                    throw new UIWidgetsError(
                        $"{debugNewCanvasSaveCount - debugPreviousCanvasSaveCount} more " +
                        $"time{((debugNewCanvasSaveCount - debugPreviousCanvasSaveCount == 1) ? "" : "s")} " +
                        "than it called canvas.restore().\n" +
                        "This leaves the canvas in an inconsistent state and will probably result in a broken display.\n" +
                        "You must pair each call to save()/saveLayer() with a later matching call to restore()."
                        );
                }

                if (debugNewCanvasSaveCount < debugPreviousCanvasSaveCount)
                {
                    throw new UIWidgetsError(
                        $"The {painter} custom painter called canvas.restore() " +
                        $"{debugPreviousCanvasSaveCount - debugNewCanvasSaveCount} more " +
                        $"time{(debugPreviousCanvasSaveCount - debugNewCanvasSaveCount == 1 ? "" : "s")} " +
                        "than it called canvas.save() or canvas.saveLayer().\n" +
                        "This leaves the canvas in an inconsistent state and will result in a broken display.\n" +
                        "You should only call restore() if you first called save() or saveLayer()."
                        );
                }

                return(debugNewCanvasSaveCount == debugPreviousCanvasSaveCount);
            });
            canvas.restore();
        }