Skip to content

Draft: add FlDotImagePainter for custom image dot markers#2049

Draft
InsoooooooooJANG wants to merge 1 commit intoimaNNeo:mainfrom
InsoooooooooJANG:feature/fldot-image
Draft

Draft: add FlDotImagePainter for custom image dot markers#2049
InsoooooooooJANG wants to merge 1 commit intoimaNNeo:mainfrom
InsoooooooooJANG:feature/fldot-image

Conversation

@InsoooooooooJANG
Copy link
Copy Markdown

@InsoooooooooJANG InsoooooooooJANG commented Jan 25, 2026

🚧 Draft: Add FlDotImagePainter for custom image dot markers

Status: Work in Progress - Seeking early feedback

Description

This PR adds FlDotImagePainter, a new implementation of FlDotPainter that allows users to display custom images as dot markers on line charts, instead of the default circle, square, or cross shapes.

Motivation

Currently, fl_chart only supports basic geometric shapes for dot markers. Many users want to display custom icons or images (e.g., profile pictures, product icons) as data point markers.

Screenshots

image

Implementation Details

Core Changes

  • FlDotImagePainter class (lib/src/chart/base/axis_chart/axis_chart_data.dart)
    • Extends FlDotPainter to support image rendering
    • Includes loadImageFromAsset() helper for loading images
    • Images must be pre-loaded due to synchronous draw() method

Example

  • LineChartSample14 demonstrates the usage
  • Shows how to load images asynchronously before chart creation
  • Includes comprehensive comments for contributors

Usage Example

// Pre-load the image
final image = await FlDotImagePainter.loadImageFromAsset('assets/dot.png');
final painter = FlDotImagePainter(image: image, size: 20.0);

// Use in chart
LineChart(
  LineChartData(
    lineBarsData: [
      LineChartBarData(
        dotData: FlDotData(
          show: true,
          getDotPainter: (spot, percent, barData, index) => painter,
        ),
      ),
    ],
  ),
)

Related Issue

[Feature Request] Add FlDotImagePainter to support custom image dot markers

- Add FlDotImagePainter class that extends FlDotPainter
- Support rendering custom images as dot markers on charts
- Include static loadImageFromAsset() helper method
- Add LineChartSample14 to demonstrate usage
- Images must be pre-loaded asynchronously before use

This allows users to display custom images (PNG, JPG, etc.)
as dot markers instead of the default circle, square, or cross shapes.
@InsoooooooooJANG InsoooooooooJANG changed the title feat: add FlDotImagePainter for custom image dot markers Draft: add FlDotImagePainter for custom image dot markers Jan 25, 2026
/// final image = await FlDotImagePainter.loadImageFromAsset('assets/dot.png');
/// final painter = FlDotImagePainter(image: image, size: 20.0);
/// ```
static Future<Image> loadImageFromAsset(String assetPath) async {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loadImageFromAsset doesn't belong in the painter.
A static method on a painter that does rootBundle.load() and instantiateImageCodec() mixes asset loading with rendering. This should be the user's responsibility.
They load the image however they want (asset, network, generated) and pass the Image object in. The static helper could live in an example or utility, but not in the library's core data class.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, it seems instantiateImageCodec() is deprecated in Flutter 3.x.
I get this warning as well:
Warning: In index.html:92: "FlutterLoader.loadEntrypoint" is deprecated. Use "FlutterLoader.load" instead. See https://docs.flutter.dev/platform-integration/web/initialization for more details.

So please make sure you're using the new approach to load the image

// Center the image at the offset
final drawOffset = offsetInCanvas - Offset(size / 2, size / 2);
final rect = Rect.fromLTWH(drawOffset.dx, drawOffset.dy, size, size);
paintImage(
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use canvasWrapper.drawImage() instead of paintImage. This way, we keep the consistency and testability. Just like here:

if (line.image != null) {
final centerX = line.image!.width / 2;
final centerY = line.image!.height / 2;
final centeredImageOffset = Offset(centerX, to.dy - centerY);
canvasWrapper.drawImage(
line.image!,
centeredImageOffset,
_imagePaint,
);
}

maxX: 6,
minY: 0,
maxY: 6,
// Configure axis titles
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need these kinds of comments. Please remove the unnecessary comments.

@imaNNeo
Copy link
Copy Markdown
Owner

imaNNeo commented Apr 10, 2026

You also need to write some unit-tests in the end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants