google / charts

https://pub.dev/packages/charts_flutter
Apache License 2.0
2.8k stars 1.2k forks source link

Don't import implementation files from another package #726

Open NguyenDinhThai opened 2 years ago

NguyenDinhThai commented 2 years ago

Recently, I customized my line charts to show point when clicking on chart

My code: I created CustomCircleSymbolRenderer()

import 'package:charts_flutter/flutter.dart as charts'; import 'package:charts_flutter/src/text_element.dart' as te; import 'package:charts_flutter/src/text_style.dart' as style;

......Line chart code ..... @override Widget build(BuildContext context) { .....//...... behaviors: [ charts.LinePointHighlighter( symbolRenderer: CustomCircleSymbolRenderer() // add this line in behaviours ) ], selectionModels: [ charts.SelectionModelConfig( changedListener: (charts.SelectionModel model) { if (model.hasDatumSelection) { // print(model.selectedSeries[0].measureFn(model.selectedDatum[0].index)); final value = model.selectedSeries[0].measureFn(model.selectedDatum[0].index).toString(); CustomCircleSymbolRenderer.value = value; } }) ], ......//.... } ....another code......

class CustomCircleSymbolRenderer extends CircleSymbolRenderer { static String value;

@override void paint(ChartCanvas canvas, Rectangle bounds, {List dashPattern, Color fillColor, FillPatternType fillPattern, Color strokeColor, double strokeWidthPx}) { super.paint(canvas, bounds, dashPattern: dashPattern, fillColor: fillColor, fillPattern: fillPattern, strokeColor: strokeColor, strokeWidthPx: strokeWidthPx); canvas.drawRect( Rectangle(bounds.left - 5, bounds.top - 30, bounds.width + 15, bounds.height + 15), fill: Color.transparent ); var myStyle = style.TextStyle(); myStyle.color = Color.black; myStyle.fontSize = 15; canvas.drawText(te.TextElement("$value",style: myStyle), (bounds.left).round(), (bounds.top - 28).round());

} } When I draw canvas.drawText, I have to use: import 'package:charts_flutter/src/text_element.dart' as te; import 'package:charts_flutter/src/text_style.dart' as style; Android Studio recommend that "Don't import implementation files from another package"

---> Is it safe if I continue using? Or others way I can use instead, Pls response me as soon as. Thank you.