Skip to content

[syncfusion_flutter_charts] The color of unselected legend was quite dark  #2355

Open
@komhkomh

Description

@komhkomh

Bug description

After I updated syncfusion_flutter_charts to 29.1.39, the color of unselected legend was quite dark and barely to see if legendItemBuilder was applied.

Steps to reproduce

It happened everytime if legendItemBuilder used.

Code sample

class _MyHomePage extends StatefulWidget {
  // ignore: prefer_const_constructors_in_immutables
  _MyHomePage({Key? key}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<_MyHomePage> {
  List<_SalesData> data = [
    _SalesData('Jan', 35),
    _SalesData('Feb', 28),
    _SalesData('Mar', 34),
    _SalesData('Apr', 32),
    _SalesData('May', 40),
  ];

  List<RxBool> isSelected = [true.obs, true.obs, true.obs];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          //Initialize the chart widget
          SfCartesianChart(
            primaryXAxis: const CategoryAxis(),
            onLegendTapped: (legendTapArgs) {
              if (legendTapArgs.seriesIndex is int) {
                isSelected[legendTapArgs.seriesIndex ?? 0].toggle();
              }
            },
            // Enable legend
            legend:  Legend(
              isVisible: true,
              toggleSeriesVisibility: true,
              width: '100%',
              itemPadding: 0,
              alignment: ChartAlignment.near,
              position: LegendPosition.top,
              overflowMode: LegendItemOverflowMode.wrap,
              legendItemBuilder: (legendText, series, point, seriesIndex) {
                return LabeledCheckbox(
                  label: legendText,
                  isShowing: isSelected[seriesIndex],
                  color: series?.color,
                );
              },
            ),
            series: <CartesianSeries<_SalesData, String>>[
              ColumnSeries<_SalesData, String>(
                animationDuration: 0,
                dataSource: data,
                xValueMapper: (_SalesData sales, _) => sales.year,
                yValueMapper: (_SalesData sales, _) => sales.sales,
                name: 'Sales1',
                color: Colors.red,
              ),
              ColumnSeries<_SalesData, String>(
                dataSource: data,
                animationDuration: 0,
                xValueMapper: (_SalesData sales, _) => sales.year,
                yValueMapper: (_SalesData sales, _) => sales.sales - 10,
                name: 'Sales2',
                color: Colors.blue,
              ),
              ColumnSeries<_SalesData, String>(
                dataSource: data,
                animationDuration: 0,
                xValueMapper: (_SalesData sales, _) => sales.year,
                yValueMapper: (_SalesData sales, _) => sales.sales - 15,
                name: 'Sales3',
                color: Colors.green,
              ),
            ],
          ),
        ],
      ),
    );
  }
}

class _SalesData {
  _SalesData(this.year, this.sales);

  final String year;
  final double sales;
}

class LabeledCheckbox extends StatelessWidget {
  const LabeledCheckbox({
    Key? key,
    required this.label,

    // required this.value,
    // required this.onChanged,
    required this.color,
    required this.isShowing,
  }) : super(key: key);

  final String label;

  // final bool value;
  // final Function onChanged;
  final Color? color;
  final RxBool isShowing;
  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.only(right: 8, bottom: 6),
      child: Obx(
        () => Row(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            Container(
              width: 14,
              height: 14,
              decoration: const BoxDecoration(
                shape: BoxShape.circle,
                color: Color(0xFF2E3138),
              ),
              alignment: Alignment.center,
              child: isShowing.value
                  ? (Container(
                      width: 8,
                      height: 8,
                      decoration: BoxDecoration(
                        shape: BoxShape.circle,
                        color: color ?? Colors.white,
                      ),
                    ))
                  : Container(),
            ),
            Flexible(child: Text(label)),
          ],
        ),
      ),
    );
  }
}

Screenshots or Video

Image

Image

Image

Stack Traces

no stack trace

On which target platforms have you observed this bug?

Android

Flutter Doctor output

[√] Flutter (Channel stable, 3.29.3, on Microsoft Windows [版本 10.0.22621.3155],
locale zh-CN) [1,399ms]
• Flutter version 3.29.3 on channel stable at
D:\flutter_windows_3.29.3-stable\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision ea121f8859 (6 weeks ago), 2025-04-11 19:10:07 +0000
• Engine revision cf56914b32
• Dart version 3.7.2
• DevTools version 2.42.3

[√] Windows Version (11 专业版 64-bit, 22H2, 2009) [5.2s]

[√] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
[3.7s]
• Android SDK at D:\Android\SDK
• Platform android-35, build-tools 35.0.0
• ANDROID_SDK_ROOT = D:\Android\SDK
• Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
This is the JDK bundled with the latest Android Studio installation on
this machine.
To manually set the JDK path, use: flutter config --jdk-dir="path/to/jdk".
• Java version OpenJDK Runtime Environment (build 21.0.6+-13355223-b631.42)
• All Android licenses accepted.

[√] Chrome - develop for the web [831ms]
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[!] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.12.3)
[830ms]
• Visual Studio at D:\Microsoft Visual Studio2022
• Visual Studio Community 2022 version 17.12.35527.113
X Visual Studio is missing necessary components. Please re-run the Visual
Studio installer for the "Desktop development with C++" workload, and
include these components:
MSVC v142 - VS 2019 C++ x64/x86 build tools
- If there are multiple build tool versions available, install the
latest
C++ CMake tools for Windows
Windows 10 SDK

[√] Android Studio (version 2024.3) [16ms]
• Android Studio at C:\Program Files\Android\Android Studio
• 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 21.0.6+-13355223-b631.42)

[√] Connected device (5 available) [778ms]
• SM S9010 (mobile) • R5CTA17Q1MB • android-arm64 • Android 14 (API 34)
• sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64 • Android 12 (API 31) (emulator)
• Windows (desktop) • windows • windows-x64 • Microsoft
Windows [版本 10.0.22621.3155]
• Chrome (web) • chrome • web-javascript • Google
Chrome 136.0.7103.93
• Edge (web) • edge • web-javascript • Microsoft
Edge 136.0.3240.50

[√] Network resources [1,854ms]
• All expected network resources are available.

! Doctor found issues in 1 category.

Metadata

Metadata

Assignees

No one assigned

    Labels

    chartsCharts componentfeatureNew featureuncertainUncertain feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions