From 8154731aab85a7329189e6e1c0ffb0ba7646f84f Mon Sep 17 00:00:00 2001 From: John Castronuovo Date: Sat, 20 Mar 2021 16:56:43 +0100 Subject: [PATCH] chore(example): add example of how to use the children parameter of the BarTooltipItem, LineTooltipItem, and ScatterTooltipItem --- example/.vim/coc-settings.json | 3 ++ .../bar_chart/samples/bar_chart_sample1.dart | 18 ++++++++- .../samples/line_chart_sample3.dart | 29 ++++++++++++++- .../samples/scatter_chart_sample2.dart | 37 +++++++++++++++++++ 4 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 example/.vim/coc-settings.json diff --git a/example/.vim/coc-settings.json b/example/.vim/coc-settings.json new file mode 100644 index 000000000..99d6732c2 --- /dev/null +++ b/example/.vim/coc-settings.json @@ -0,0 +1,3 @@ +{ + "flutter.selectedDeviceId": "emulator-5554" +} \ No newline at end of file diff --git a/example/lib/bar_chart/samples/bar_chart_sample1.dart b/example/lib/bar_chart/samples/bar_chart_sample1.dart index dfef24d6c..5f72fb5ef 100644 --- a/example/lib/bar_chart/samples/bar_chart_sample1.dart +++ b/example/lib/bar_chart/samples/bar_chart_sample1.dart @@ -177,7 +177,23 @@ class BarChartSample1State extends State { break; } return BarTooltipItem( - weekDay + '\n' + (rod.y - 1).toString(), TextStyle(color: Colors.yellow)); + weekDay + '\n', + TextStyle( + color: Colors.white, + fontWeight: FontWeight.bold, + fontSize: 18, + ), + children: [ + TextSpan( + text: (rod.y - 1).toString(), + style: TextStyle( + color: Colors.yellow, + fontSize: 16, + fontWeight: FontWeight.w500, + ), + ), + ], + ); }), touchCallback: (barTouchResponse) { setState(() { diff --git a/example/lib/line_chart/samples/line_chart_sample3.dart b/example/lib/line_chart/samples/line_chart_sample3.dart index 4b7f77f4b..3a98bdacc 100644 --- a/example/lib/line_chart/samples/line_chart_sample3.dart +++ b/example/lib/line_chart/samples/line_chart_sample3.dart @@ -90,8 +90,33 @@ class _LineChartSample3State extends State { } return LineTooltipItem( - '${widget.weekDays[flSpot.x.toInt()]} \n${flSpot.y} k calories', - const TextStyle(color: Colors.white), + '${widget.weekDays[flSpot.x.toInt()]} \n', + const TextStyle( + color: Colors.white, + fontWeight: FontWeight.bold, + ), + children: [ + TextSpan( + text: flSpot.y.toString(), + style: TextStyle( + color: Colors.grey[100], + fontWeight: FontWeight.normal, + ), + ), + TextSpan( + text: ' k ', + style: TextStyle( + fontStyle: FontStyle.italic, + fontWeight: FontWeight.normal, + ), + ), + TextSpan( + text: 'calories', + style: TextStyle( + fontWeight: FontWeight.normal, + ), + ), + ], ); }).toList(); }), diff --git a/example/lib/scatter_chart/samples/scatter_chart_sample2.dart b/example/lib/scatter_chart/samples/scatter_chart_sample2.dart index 342107ee2..59d18a93e 100644 --- a/example/lib/scatter_chart/samples/scatter_chart_sample2.dart +++ b/example/lib/scatter_chart/samples/scatter_chart_sample2.dart @@ -97,6 +97,43 @@ class _ScatterChartSample2State extends State { handleBuiltInTouches: false, touchTooltipData: ScatterTouchTooltipData( tooltipBgColor: Colors.black, + getTooltipItems: (ScatterSpot touchedBarSpot) { + return ScatterTooltipItem( + 'X: ', + TextStyle( + height: 1.2, + color: Colors.grey[100], + fontStyle: FontStyle.italic, + ), + 10, + children: [ + TextSpan( + text: '${touchedBarSpot.x.toInt()} \n', + style: TextStyle( + color: Colors.white, + fontStyle: FontStyle.normal, + fontWeight: FontWeight.bold, + ), + ), + TextSpan( + text: 'Y: ', + style: TextStyle( + height: 1.2, + color: Colors.grey[100], + fontStyle: FontStyle.italic, + ), + ), + TextSpan( + text: touchedBarSpot.y.toInt().toString(), + style: TextStyle( + color: Colors.white, + fontStyle: FontStyle.normal, + fontWeight: FontWeight.bold, + ), + ), + ], + ); + }, ), touchCallback: (ScatterTouchResponse touchResponse) { if (touchResponse.touchInput is FlPanStart) {