Skip to content

Drawing a path results in an unexpected behavior with Impeller #146648

@ueman

Description

@ueman

Steps to reproduce

Run the following code on iOS (simulator or phyiscal device, it doesn't matter) (complete code can be found in the collapsed block later)

final legLength = size.width * 0.3;
final paint = Paint();
paint.color = const Color(0xFFFF69b4);
paint.style = PaintingStyle.stroke;
paint.strokeCap = StrokeCap.round;
paint.strokeWidth = lineWidth;

final path = Path()
  // top left
  ..moveTo(0, legLength)
  ..lineTo(0, borderRadius)
  ..arcToPoint(
    Offset(borderRadius, 0),
    radius: Radius.circular(borderRadius),
  )
  ..lineTo(legLength, 0)
  // top right
  ..moveTo(size.width - legLength, 0)
  ..lineTo(size.width - borderRadius, 0)
  ..arcToPoint(
    Offset(size.width, borderRadius),
    radius: Radius.circular(borderRadius),
  )
  ..lineTo(size.width, legLength)
  // bottom right
  ..moveTo(size.width, size.height - legLength)
  ..lineTo(size.width, size.height - borderRadius)
  ..arcToPoint(
    Offset(size.width - borderRadius, size.height),
    radius: Radius.circular(borderRadius),
  )
  ..lineTo(size.width - legLength, size.height)
  // bottom right
  ..moveTo(legLength, size.height)
  ..lineTo(borderRadius, size.height)
  ..arcToPoint(
    Offset(0, size.height - borderRadius),
    radius: Radius.circular(borderRadius),
  )
  ..lineTo(0, size.height - legLength)
  ..moveTo(0, legLength)
  ..close();

canvas.drawPath(path, paint);

Expected results

With Impeller disabled (the following code added to Info.plist)

<key>FLTEnableImpeller</key>
<false/>

Simulator Screenshot - iPhone 15 Pro Max - 2024-04-11 at 19 46 27

Actual results

With Impeller
Simulator Screenshot - iPhone 15 Pro Max - 2024-04-11 at 19 43 51

Code sample

Code sample
import 'package:flutter/material.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      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> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
          child: _FrameSquare(
        height: 200,
        width: 200,
        borderRadius: 4,
        lineWidth: 4,
      )),
    );
  }
}

class _FrameSquare extends StatelessWidget {
  const _FrameSquare({
    required this.height,
    required this.width,
    required this.borderRadius,
    required this.lineWidth,
  });
  final double height;
  final double width;
  final double borderRadius;
  final double lineWidth;
  @override
  Widget build(BuildContext context) {
    return Center(
      child: CustomPaint(
        size: Size(width, height),
        painter: _FrameBorderPainter(
          borderRadius: borderRadius,
          lineWidth: lineWidth,
        ),
      ),
    );
  }
}

class _FrameBorderPainter extends CustomPainter {
  _FrameBorderPainter({required this.borderRadius, required this.lineWidth});
  final double borderRadius;
  final double lineWidth;
  @override
  void paint(Canvas canvas, Size size) {
    final legLength = size.width * 0.3;
    final paint = Paint();
    paint.color = const Color(0xFFFF69b4);
    paint.style = PaintingStyle.stroke;
    paint.strokeCap = StrokeCap.round;
    paint.strokeWidth = lineWidth;

    final path = Path()
      // top left
      ..moveTo(0, legLength)
      ..lineTo(0, borderRadius)
      ..arcToPoint(
        Offset(borderRadius, 0),
        radius: Radius.circular(borderRadius),
      )
      ..lineTo(legLength, 0)
      // top right
      ..moveTo(size.width - legLength, 0)
      ..lineTo(size.width - borderRadius, 0)
      ..arcToPoint(
        Offset(size.width, borderRadius),
        radius: Radius.circular(borderRadius),
      )
      ..lineTo(size.width, legLength)
      // bottom right
      ..moveTo(size.width, size.height - legLength)
      ..lineTo(size.width, size.height - borderRadius)
      ..arcToPoint(
        Offset(size.width - borderRadius, size.height),
        radius: Radius.circular(borderRadius),
      )
      ..lineTo(size.width - legLength, size.height)
      // bottom right
      ..moveTo(legLength, size.height)
      ..lineTo(borderRadius, size.height)
      ..arcToPoint(
        Offset(0, size.height - borderRadius),
        radius: Radius.circular(borderRadius),
      )
      ..lineTo(0, size.height - legLength)
      ..moveTo(0, legLength)
      ..close();

    canvas.drawPath(path, paint);
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) {
    return false;
  }
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs

There are no logs

Flutter Doctor output

Doctor output
 flutter doctor -v
[✓] Flutter (Channel stable, 3.19.3, on macOS 14.3.1 23D60 darwin-arm64, locale en-DE)
    • Flutter version 3.19.3 on channel stable at /Users/ueman/Developer/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ba39319843 (5 weeks ago), 2024-03-07 15:22:21 -0600
    • Engine revision 2e4ba9c6fb
    • Dart version 3.3.1
    • DevTools version 2.31.1

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/ueman/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15E204a
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)

[✓] VS Code (version 1.88.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.86.0

[✓] Connected device (4 available)
    • iPhone-GWTGT1UTPLJQ (mobile) • 00008030-000E4D310CD3402E            • ios            • iOS 17.4.1 21E236
    • iPhone 15 Pro Max (mobile)   • 4E4B3D83-EAA8-490B-B699-90A09831AC06 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-17-4 (simulator)
    • macOS (desktop)              • macos                                • darwin-arm64   • macOS 14.3.1 23D60 darwin-arm64
    • Chrome (web)                 • chrome                               • web-javascript • Google Chrome 123.0.6312.107

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Assignees

Labels

e: impellerImpeller rendering backend issues and features requestsengineflutter/engine related. See also e: labels.found in release: 3.19Found to occur in 3.19found in release: 3.22Found to occur in 3.22has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionteam-engineOwned by Engine team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions