imaNNeo / fl_chart

FL Chart is a highly customizable Flutter chart library that supports Line Chart, Bar Chart, Pie Chart, Scatter Chart, and Radar Chart.
https://flchart.dev
MIT License
6.87k stars 1.78k forks source link

PieChartData incorrect center color for one PieChartSectionData with opacity color in sections #1716

Open makruhz opened 4 months ago

makruhz commented 4 months ago

Describe the bug The center of the pie chart has an incorrect color when it has one PieChartSectionData in the sections parameter and the PieChartSectionData color has opacity

To Reproduce

import 'package:collection/collection.dart';
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';

void main() => runApp(const FlChartPieCharts());

class FlChartPieCharts extends StatelessWidget {
  const FlChartPieCharts({super.key});

  static const List<double> pieChartData1 = [1];
  static const List<double> pieChartData2 = [0.5, 0.5];

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'FL Chart Pie Charts',
      home: Scaffold(
        body: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            TestPieChart(pieChartData: pieChartData1),
            SizedBox(height: 32),
            TestPieChart(pieChartData: pieChartData2)
          ],
        ),
      ),
    );
  }
}

class TestPieChart extends StatefulWidget {
  const TestPieChart({super.key, required this.pieChartData});

  final List<double> pieChartData;

  @override
  State<TestPieChart> createState() => _TestPieChartState();
}

class _TestPieChartState extends State<TestPieChart> {
  int touchedIndex = -1;

  @override
  Widget build(BuildContext context) {
    return AspectRatio(
      aspectRatio: 2,
      child: PieChart(
        PieChartData(
          centerSpaceColor: Colors.white,
          pieTouchData: PieTouchData(
            touchCallback: (FlTouchEvent event, pieTouchResponse) {
              setState(() {
                if (pieTouchResponse == null || pieTouchResponse.touchedSection == null) {
                  return;
                }
                touchedIndex = pieTouchResponse.touchedSection!.touchedSectionIndex;
              });
            },
          ),
          sections: [
            ...widget.pieChartData.mapIndexed(
              (index, data) => PieChartSectionData(
                value: data,
                radius: 32,
                color: touchedIndex == index ? Colors.green : Colors.green.withOpacity(0.5),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Screenshots simulator_screenshot_63C8B2D6-57D4-4D59-8D17-DC174A4151A5

Versions

RafaRuiz commented 2 months ago

0.65.0 ✅

image

0.66.0 ❌ (and until last one)

image