Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
d2c32750
Commit
d2c32750
authored
Feb 12, 2016
by
Ian Hickson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1791 from Hixie/custom-paint-saves
Assert that custom painters balance save/restores.
parents
ffcdd0d1
0d1a3cfc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
2 deletions
+36
-2
proxy_box.dart
packages/flutter/lib/src/rendering/proxy_box.dart
+35
-1
checked_mode_banner.dart
packages/flutter/lib/src/widgets/checked_mode_banner.dart
+1
-1
No files found.
packages/flutter/lib/src/rendering/proxy_box.dart
View file @
d2c32750
...
...
@@ -1264,9 +1264,43 @@ class RenderCustomPaint extends RenderProxyBox {
}
void
_paintWithPainter
(
Canvas
canvas
,
Offset
offset
,
CustomPainter
painter
)
{
int
debugPreviousCanvasSaveCount
;
canvas
.
save
();
assert
(()
{
debugPreviousCanvasSaveCount
=
canvas
.
getSaveCount
();
return
true
;
});
canvas
.
translate
(
offset
.
dx
,
offset
.
dy
);
painter
.
paint
(
canvas
,
size
);
canvas
.
translate
(-
offset
.
dx
,
-
offset
.
dy
);
assert
(()
{
// This isn't perfect. For example, we can't catch the case of
// someone first restoring, then setting a transform or whatnot,
// then saving.
// If this becomes a real problem, we could add logic to the
// Canvas class to lock the canvas at a particular save count
// such that restore() fails if it would take the lock count
// below that number.
int
debugNewCanvasSaveCount
=
canvas
.
getSaveCount
();
if
(
debugNewCanvasSaveCount
>
debugPreviousCanvasSaveCount
)
{
throw
new
RenderingError
(
'The
$painter
custom painter called canvas.save() or canvas.saveLayer() at least '
'
${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
RenderingError
(
'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
();
}
void
paint
(
PaintingContext
context
,
Offset
offset
)
{
...
...
packages/flutter/lib/src/widgets/checked_mode_banner.dart
View file @
d2c32750
...
...
@@ -15,7 +15,7 @@ class _CheckedModeBannerPainter extends CustomPainter {
static
const
kHeight
=
12.0
;
// height of banner
static
const
kTextAlign
=
const
Offset
(
0.0
,
-
3.0
);
// offset to move text up
static
const
kFontSize
=
kHeight
*
0.85
;
static
const
kShadowBlur
=
8
.0
;
// shadow blur sigma
static
const
kShadowBlur
=
4
.0
;
// shadow blur sigma
static
final
Rect
kRect
=
new
Rect
.
fromLTWH
(-
kOffset
,
kOffset
-
kHeight
,
kOffset
*
2.0
,
kHeight
);
static
const
TextStyle
kTextStyles
=
const
TextStyle
(
color:
const
Color
(
0xFFFFFFFF
),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment