Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
makruhz opened this issue Jul 22, 2024 · 1 comment

Comments

@makruhz
Copy link

makruhz commented Jul 22, 2024

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

  • which version of the Flutter are you using?
    3.22.3
  • which version of the FlChart are you using? fl_chart:
    0.68.0
@RafaRuiz
Copy link

RafaRuiz commented Sep 12, 2024

0.65.0 ✅
image

0.66.0 ❌ (and until last one)
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants