Skip to content

Commit

Permalink
Update pie_chart_sample1.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
imaNNeo committed Jul 22, 2021
1 parent 426c31d commit 682aa89
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
27 changes: 23 additions & 4 deletions example/lib/pie_chart/samples/pie_chart_sample1.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
import 'package:flutter/gestures.dart';
import 'indicator.dart';
import 'package:example/utils/color_extensions.dart';

class PieChartSample1 extends StatefulWidget {
@override
Expand Down Expand Up @@ -97,46 +98,64 @@ class PieChartSample1State extends State {
(i) {
final isTouched = i == touchedIndex;
final opacity = isTouched ? 1.0 : 0.6;

final color0 = const Color(0xff0293ee);
final color1 = const Color(0xfff8b250);
final color2 = const Color(0xff845bef);
final color3 = const Color(0xff13d38e);

switch (i) {
case 0:
return PieChartSectionData(
color: const Color(0xff0293ee).withOpacity(opacity),
color: color0.withOpacity(opacity),
value: 25,
title: '',
radius: 80,
titleStyle: TextStyle(
fontSize: 18, fontWeight: FontWeight.bold, color: const Color(0xff044d7c)),
titlePositionPercentageOffset: 0.55,
borderSide: isTouched
? BorderSide(color: color0.darken(40), width: 6)
: BorderSide(color: color0.withOpacity(0)),
);
case 1:
return PieChartSectionData(
color: const Color(0xfff8b250).withOpacity(opacity),
color: color1.withOpacity(opacity),
value: 25,
title: '',
radius: 65,
titleStyle: TextStyle(
fontSize: 18, fontWeight: FontWeight.bold, color: const Color(0xff90672d)),
titlePositionPercentageOffset: 0.55,
borderSide: isTouched
? BorderSide(color: color1.darken(40), width: 6)
: BorderSide(color: color2.withOpacity(0)),
);
case 2:
return PieChartSectionData(
color: const Color(0xff845bef).withOpacity(opacity),
color: color2.withOpacity(opacity),
value: 25,
title: '',
radius: 60,
titleStyle: TextStyle(
fontSize: 18, fontWeight: FontWeight.bold, color: const Color(0xff4c3788)),
titlePositionPercentageOffset: 0.6,
borderSide: isTouched
? BorderSide(color: color2.darken(40), width: 6)
: BorderSide(color: color2.withOpacity(0)),
);
case 3:
return PieChartSectionData(
color: const Color(0xff13d38e).withOpacity(opacity),
color: color3.withOpacity(opacity),
value: 25,
title: '',
radius: 70,
titleStyle: TextStyle(
fontSize: 18, fontWeight: FontWeight.bold, color: const Color(0xff0c7f55)),
titlePositionPercentageOffset: 0.55,
borderSide: isTouched
? BorderSide(color: color3.darken(40), width: 6)
: BorderSide(color: color2.withOpacity(0)),
);
default:
throw Error();
Expand Down
11 changes: 11 additions & 0 deletions example/lib/utils/color_extensions.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:flutter/material.dart';

extension ColorExtension on Color {
/// Convert the color to a darken color based on the [percent]
Color darken([int percent = 40]) {
assert(1 <= percent && percent <= 100);
final value = 1 - percent / 100;
return Color.fromARGB(
alpha, (red * value).round(), (green * value).round(), (blue * value).round());
}
}
Binary file modified repo_files/images/pie_chart/pie_chart_sample_1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 682aa89

Please sign in to comment.