-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
Basic operations on a dart:ui Path compromise the Path.
Steps to Reproduce on DartPad
- Open a new Flutter Project on https://dartpad.dartlang.org/flutter.
- Replace the source code with the following:
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: CustomPaint(
size: Size(300, 300),
painter: _Painter(),
),
),
),
);
}
}
class _Painter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) async {
Path p = Path()
..moveTo(100, 100)
..lineTo(200, 100)
..lineTo(150, 200)
..close();
/* 1 */ //print(p.getBounds().longestSide);
/* 2 */ //canvas.drawPath(p, Paint()..color = Colors.amber);
/* 3 */ canvas.drawPath(p.transform(Matrix4.identity().storage), Paint()..color = Colors.amber);
p = p.transform((Matrix4.identity()..rotateZ(.29)..scale(1.5)).storage);
canvas.drawPath(p, Paint()..color = Colors.red);
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
}
-
Run the DartPad, two triangles are painted on the canvas.
-
Uncomment line
/* 1 */ print(p.getBounds().longestSide); -
Run the DartPad, only the first triangle is painted on the canvas.
In the console, you will also see an Uncaught Error:
Assertion failed: isValid is not true
atflutter_web_sdk/lib/_engine/engine/html/path/path_ref.dart:831:12 -
Comment line
/* 1 */ print(p.getBounds().longestSide); -
Comment line
/* 3 */ canvas.drawPath(p.transform(Matrix4.identity().storage), Paint()..color = Colors.amber); -
Uncomment line
/* 2 */ canvas.drawPath(p, Paint()..color = Colors.amber); -
Run the DartPad, only the first triangle is painted on the canvas.
In the console, you will see the same Uncaught Error:
Assertion failed: isValid is not true
atflutter_web_sdk/lib/_engine/engine/html/path/path_ref.dart:831:12
Expected behavior
Operations on Paths should be immutable and not interfere with further drawing of the Path.