Skip to content

Line created using canvas.drawPoints() disappears partially when a widget is placed above it #106187

@SheenaJacob

Description

@SheenaJacob

Steps to Reproduce

  1. Execute flutter run (device: macOS(desktop)) on the code sample
  2. Tap on the TextField and hover the mouse on the screen

Expected results: Line below the text field should remain the same length and not get cut off on hovering above it.

Actual results: Part of the line below disappears from time to time when clicking the text box and hovering the mouse over the screen.

Code sample
import 'dart:ui';

import 'package:flutter/material.dart';

void main() async {
  runApp(
      const MaterialApp(
      debugShowCheckedModeBanner: false,
      home: DistanceProvider()));
}

class DistanceProvider extends StatelessWidget {
  const DistanceProvider({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // Finds the center of the screen
    final width = MediaQuery.of(context).size.width / 2;
    final height = MediaQuery.of(context).size.height / 2;

    return Scaffold(
      body: Stack(
        children: [
          // Draws a line using the Custom painter at the center of the screen (width :400 px)
          CustomPaint(
            size: Size.infinite,
            painter: _DrawPath(
              offsetPoints: [
                Offset(width - 200, height),
                Offset(width + 200, height)
              ],
            ),
          ),
          // Places a text box to enter the distance between the two points
          Center(
            child: Container(
                width: 50,
                decoration: const BoxDecoration(color: Colors.white),
                child: TextField(
                  onChanged: (String value) {},
                )),
          ),
        ],
      ),
    );
  }
}

///Creates a path by drawing a line from one consecutive point to the next
class _DrawPath extends CustomPainter {
  _DrawPath({
    required this.offsetPoints,
  });

  final List<Offset> offsetPoints;

  @override
  void paint(Canvas canvas, Size size) {
    canvas.drawPoints(PointMode.polygon, offsetPoints, Paint());
  }

  @override
  bool shouldRepaint(_DrawPath oldDelegate) => true;
}
Logs

flutter analyze

Analyzing disappearing_line_bug...
No issues found! (ran in 4.6s)

Doctor summary :

[✓] Flutter (Channel stable, 3.0.2, on macOS 12.4 21F79 darwin-x64, locale en-DE)
• Flutter version 3.0.2 at /Users/jshe/Developer/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision cd41fdd (9 days ago), 2022-06-08 09:52:13 -0700
• Engine revision f15f824b57
• Dart version 2.17.3
• DevTools version 2.12.2

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /Users/jshe/Library/Android/sdk
• Platform android-31, build-tools 30.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• CocoaPods version 1.11.3

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

[✓] Android Studio (version 4.2)
• 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 11.0.8+10-b944.6916264)

[✓] VS Code (version 1.57.0)
• VS Code at /Users/jshe/Downloads/Visual Studio Code.app/Contents
• Flutter extension can be installed from:
🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (2 available)
• macOS (desktop) • macos • darwin-x64 • macOS 12.4 21F79 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 102.0.5005.115

[✓] HTTP Host Availability
• All required HTTP hosts are available

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    r: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions