-
Notifications
You must be signed in to change notification settings - Fork 6k
[web] Prevent crash when restore is called incorrectly after recording ends. #19948
Conversation
mdebbar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after addressing assertionsEnabled comment.
| if (assertionsEnabled) { | ||
| _debugRecordingEnded = true; | ||
| _recordingEnded = true; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check for assertionsEnabled should be removed, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for spotting that!. Done.
| final RecordingCanvas rc = RecordingCanvas(Rect.fromLTRB(0, 0, 200, 400)); | ||
| rc.endRecording(); | ||
| // Should not throw exception on restore. | ||
| rc.restore(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using expect will probably show a nicer error on failure:
expect(() => rc.restore(), returnsNormally);There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
| expect(mockCanvas.methodCallLog[2].methodName, 'restore'); | ||
| expect(mockCanvas.methodCallLog[3].methodName, 'endOfPaint'); | ||
| }); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nit: doc comment on the method.
Description
This PR makes web consistent with mobile platforms.
When PaintingContext is used with a painter and component such as TextField, the painter itself causes paintContext.canvas to change to a new instance since one recording ends and another one starts. The code in ClipContext currently is calling save and restore on different Canvas(s) causing an exception on web since it has extra checks.
Related Issues
Fixed flutter/flutter#61697
Tests
Updated recording_canvas_test to cover case.
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]). This will ensure a smooth and quick review process.Breaking Change
Did any tests fail when you ran them? Please read [handling breaking changes].