Skip to content

[Web] Unstable Path in CustomPainter #68702

@GROOVIZ

Description

@GROOVIZ

Basic operations on a dart:ui Path compromise the Path.

Steps to Reproduce on DartPad

  1. Open a new Flutter Project on https://dartpad.dartlang.org/flutter.
  2. 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;

}
  1. Run the DartPad, two triangles are painted on the canvas.

  2. Uncomment line /* 1 */ print(p.getBounds().longestSide);

  3. 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
    at flutter_web_sdk/lib/_engine/engine/html/path/path_ref.dart:831:12

  4. Comment line /* 1 */ print(p.getBounds().longestSide);

  5. Comment line /* 3 */ canvas.drawPath(p.transform(Matrix4.identity().storage), Paint()..color = Colors.amber);

  6. Uncomment line /* 2 */ canvas.drawPath(p, Paint()..color = Colors.amber);

  7. 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
    at flutter_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.

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work liste: web_htmlHTML rendering backend for Webengineflutter/engine related. See also e: labels.f: material designflutter/packages/flutter/material repository.found in release: 1.24Found to occur in 1.24has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-webWeb applications specifically

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions