From e170af81cba9f61d2625dcf52b123d06747cdd5b Mon Sep 17 00:00:00 2001 From: imaNNeoFighT Date: Fri, 29 Mar 2024 01:28:17 +0330 Subject: [PATCH] Fix scatter_chart_sample2 color contrast --- .../scatter/scatter_chart_sample2.dart | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/example/lib/presentation/samples/scatter/scatter_chart_sample2.dart b/example/lib/presentation/samples/scatter/scatter_chart_sample2.dart index 8ce83961e..25b3ad4a9 100644 --- a/example/lib/presentation/samples/scatter/scatter_chart_sample2.dart +++ b/example/lib/presentation/samples/scatter/scatter_chart_sample2.dart @@ -130,19 +130,37 @@ class _ScatterChartSample2State extends State { return touchedBarSpot.dotPainter.mainColor; }, getTooltipItems: (ScatterSpot touchedBarSpot) { + final bool isBgDark = + switch ((touchedBarSpot.x, touchedBarSpot.y)) { + (4.0, 4.0) => false, + (2.0, 5.0) => false, + (4.0, 5.0) => true, + (8.0, 6.0) => true, + (5.0, 7.0) => true, + (7.0, 2.0) => true, + (3.0, 2.0) => true, + (2.0, 8.0) => false, + (8.0, 8.0) => true, + (5.0, 2.5) => false, + (3.0, 7.0) => true, + _ => false, + }; + + final color1 = isBgDark ? Colors.grey[100] : Colors.black87; + final color2 = isBgDark ? Colors.white : Colors.black; return ScatterTooltipItem( 'X: ', textStyle: TextStyle( height: 1.2, - color: Colors.grey[100], + color: color1, fontStyle: FontStyle.italic, ), bottomMargin: 10, children: [ TextSpan( text: '${touchedBarSpot.x.toInt()} \n', - style: const TextStyle( - color: Colors.white, + style: TextStyle( + color: color2, fontStyle: FontStyle.normal, fontWeight: FontWeight.bold, ), @@ -151,14 +169,14 @@ class _ScatterChartSample2State extends State { text: 'Y: ', style: TextStyle( height: 1.2, - color: Colors.grey[100], + color: color1, fontStyle: FontStyle.italic, ), ), TextSpan( text: touchedBarSpot.y.toInt().toString(), - style: const TextStyle( - color: Colors.white, + style: TextStyle( + color: color2, fontStyle: FontStyle.normal, fontWeight: FontWeight.bold, ),