Skip to content

[Impeller] Nothing drawn for zero length lines. #109077

@flar

Description

@flar

Zero length lines are supposed to draw their end cap decoration axis aligned at their singular point, but Impeller draws nothing. The following test case will demonstrate the problem if run with --enable-impeller

This issue impacts the implementation of drawPoints as well where the PointMode.points mode draws a zero length line at each point in the array. The current implementation uses a workaround of adding kEhCloseEnough to the second point's X location in order to get the points to render (see flutter/engine#35204)

Test case
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                const Text('butt cap'),
                SizedBox(
                  width: 50,
                  height: 50,
                  child: CustomPaint(
                    painter: ZeroLengthLinePainter(StrokeCap.butt),
                  ),
                ),
              ],
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                const Text('square cap'),
                SizedBox(
                  width: 50,
                  height: 50,
                  child: CustomPaint(
                    painter: ZeroLengthLinePainter(StrokeCap.square),
                  ),
                ),
              ],
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                const Text('round cap'),
                SizedBox(
                  width: 50,
                  height: 50,
                  child: CustomPaint(
                    painter: ZeroLengthLinePainter(StrokeCap.round),
                  ),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}

class ZeroLengthLinePainter extends CustomPainter {
  ZeroLengthLinePainter(this.cap);
  final StrokeCap cap;

  @override
  void paint(Canvas canvas, Size size) {
    Paint paint = Paint()
      ..strokeWidth = 10
      ..strokeCap = cap;
    canvas.drawLine(size.center(Offset.zero), size.center(Offset.zero), paint);
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) => true;
}

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work liste: impellerImpeller rendering backend issues and features requestsengineflutter/engine related. See also e: labels.

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions