Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion flutter.compileSdkVersion
compileSdkVersion 34
ndkVersion flutter.ndkVersion

compileOptions {
Expand All @@ -47,8 +47,8 @@ android {
applicationId "com.example.example"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
minSdkVersion 28

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure we need to hardcode here?
@singhtaranjeet any insights?

@singhtaranjeet singhtaranjeet Dec 31, 2023

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it's fine to have it as hardcoded and it totally depends upon the requirements of the project but do we actually need to set it at 28 which is android 9?
Default of flutter 3.16 minSdkVersion is 19.
And Default of previous flutter version was android 16.

IMO we can go with flutter default as of now but in future if project requires then we can make the values hardcoded.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tajjacob any specific reason we changed this?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@apgapg this one for my project. I can change it to default back

targetSdkVersion 34
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Expand Down
6 changes: 3 additions & 3 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.6.10'
ext.kotlin_version = '1.8.21'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath 'com.android.tools.build:gradle:7.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand All @@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
1 change: 1 addition & 0 deletions example/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
android.enableR8=true
2 changes: 1 addition & 1 deletion example/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>9.0</string>
<string>11.0</string>
</dict>
</plist>
13 changes: 8 additions & 5 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -127,7 +127,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down Expand Up @@ -171,10 +171,12 @@
/* Begin PBXShellScriptBuildPhase section */
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}",
);
name = "Thin Binary";
outputPaths = (
Expand All @@ -185,6 +187,7 @@
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down Expand Up @@ -272,7 +275,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down Expand Up @@ -349,7 +352,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -398,7 +401,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 2 additions & 0 deletions example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,7 @@
<false/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
6 changes: 3 additions & 3 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class HomePageState extends State<HomePage> {
ListTile(
title: Text(
'Pie Chart Options'.toUpperCase(),
style: Theme.of(context).textTheme.overline!.copyWith(
style: Theme.of(context).textTheme.labelSmall!.copyWith(
fontSize: 12,
fontWeight: FontWeight.bold,
),
Expand Down Expand Up @@ -269,7 +269,7 @@ class HomePageState extends State<HomePage> {
ListTile(
title: Text(
'Legend Options'.toUpperCase(),
style: Theme.of(context).textTheme.overline!.copyWith(
style: Theme.of(context).textTheme.labelSmall!.copyWith(
fontSize: 12,
fontWeight: FontWeight.bold,
),
Expand Down Expand Up @@ -361,7 +361,7 @@ class HomePageState extends State<HomePage> {
ListTile(
title: Text(
'Chart values Options'.toUpperCase(),
style: Theme.of(context).textTheme.overline!.copyWith(
style: Theme.of(context).textTheme.labelSmall!.copyWith(
fontSize: 12,
fontWeight: FontWeight.bold,
),
Expand Down
26 changes: 20 additions & 6 deletions lib/src/chart_painter.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:math' as math;

import 'package:flutter/material.dart';
import 'package:intl/intl.dart' as intl;
import 'package:pie_chart/pie_chart.dart';

const doublePi = math.pi * 2;
Expand Down Expand Up @@ -29,6 +30,8 @@ class PieChartPainter extends CustomPainter {
final DegreeOptions degreeOptions;
final Color baseChartColor;
final double? totalValue;
final String? prefix;
final String? suffix;

late double _prevAngle;

Expand Down Expand Up @@ -57,6 +60,8 @@ class PieChartPainter extends CustomPainter {
this.degreeOptions = const DegreeOptions(),
required this.baseChartColor,
this.totalValue,
this.prefix,
this.suffix,
}) {
// set total value
if (totalValue == null) {
Expand Down Expand Up @@ -98,7 +103,10 @@ class PieChartPainter extends CustomPainter {
// this is not a precise calculation, should be more generalized later
// e.g. (-90, 91) should start from the left

final left = degreeOptions.initialAngle >= -90 && degreeOptions.totalDegrees <= 180 ? -size.width / 2 : 0.0;
final left =
degreeOptions.initialAngle >= -90 && degreeOptions.totalDegrees <= 180
? -size.width / 2
: 0.0;

const top = 0.0;

Expand Down Expand Up @@ -131,7 +139,8 @@ class PieChartPainter extends CustomPainter {
);
} else {
final isGradientPresent = gradientList?.isNotEmpty ?? false;
final isNonGradientElementPresent = (_subParts.length - (gradientList?.length ?? 0)) > 0;
final isNonGradientElementPresent =
(_subParts.length - (gradientList?.length ?? 0)) > 0;

for (int i = 0; i < _subParts.length; i++) {
if (isGradientPresent) {
Expand All @@ -144,7 +153,8 @@ class PieChartPainter extends CustomPainter {
transform: GradientRotation(normalizedPrevAngle),
endAngle: normalizedEndAngle,
colors: getGradient(gradientList!, i,
isNonGradientElementPresent: isNonGradientElementPresent, emptyColorGradient: emptyColorGradient!),
isNonGradientElementPresent: isNonGradientElementPresent,
emptyColorGradient: emptyColorGradient!),
);
paint.shader = gradient.createShader(boundingSquare);
if (chartType == ChartType.ring) {
Expand All @@ -170,7 +180,8 @@ class PieChartPainter extends CustomPainter {
}

final radius = showChartValuesOutside ? (side / 2) + 16 : side / 3;
final radians = _prevAngle + (((_totalAngle / _total) * _subParts[i]) / 2);
final radians =
_prevAngle + (((_totalAngle / _total) * _subParts[i]) / 2);
final x = (radius) * math.cos(radians);
final y = (radius) * math.sin(radians);

Expand Down Expand Up @@ -209,9 +220,11 @@ class PieChartPainter extends CustomPainter {
double side, {
TextStyle? style,
}) {
final value = intl.NumberFormat("#,##0.00", "en_US");
final span = TextSpan(
style: style ?? chartValueStyle,
text: name,
text:
'${prefix ?? ''} ${value.format(double.parse(name ?? '0'))} ${suffix ?? ''}',
);
TextPainter tp = TextPainter(
text: span,
Expand Down Expand Up @@ -244,5 +257,6 @@ class PieChartPainter extends CustomPainter {
}

@override
bool shouldRepaint(PieChartPainter oldDelegate) => oldDelegate._totalAngle != _totalAngle;
bool shouldRepaint(PieChartPainter oldDelegate) =>
oldDelegate._totalAngle != _totalAngle;
}
4 changes: 4 additions & 0 deletions lib/src/chart_values_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class ChartValuesOptions {
final bool showChartValuesOutside;
final Color? chartValueBackgroundColor;
final TextStyle chartValueStyle;
final String? prefix;
final String? suffix;

const ChartValuesOptions({
this.showChartValueBackground = true,
Expand All @@ -19,5 +21,7 @@ class ChartValuesOptions {
this.chartValueStyle = defaultChartValueStyle,
this.showChartValues = true,
this.showChartValuesOutside = false,
this.prefix,
this.suffix,
});
}
67 changes: 41 additions & 26 deletions lib/src/legend.dart
Original file line number Diff line number Diff line change
@@ -1,49 +1,64 @@
import 'package:flutter/material.dart';

import '../pie_chart.dart';

class Legend extends StatelessWidget {
const Legend({
required this.title,
required this.color,
required this.style,
required this.legendShape,
required this.position,
this.width,
Key? key,
}) : super(key: key);

final String title;
final Color color;
final TextStyle style;
final BoxShape legendShape;
final LegendPosition position;
final double? width;

@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
margin: const EdgeInsets.symmetric(vertical: 2.0),
height: 20.0,
width: 18.0,
decoration: BoxDecoration(
shape: legendShape,
color: color,
double sw = MediaQuery.of(context).size.width;
return SizedBox(
width: (width != null)
? width
: ((position == LegendPosition.right ||
position == LegendPosition.left)
? sw * 0.5
: sw),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
margin: const EdgeInsets.symmetric(vertical: 2.0),
height: 20.0,
width: 18.0,
decoration: BoxDecoration(
shape: legendShape,
color: color,
),
),
const SizedBox(
width: 8.0,
),
Flexible(
fit: FlexFit.loose,
child: Text(
title,
style: style,
softWrap: true,
),
),
),
const SizedBox(
width: 8.0,
),
Flexible(
fit: FlexFit.loose,
child: Text(
title,
style: style,
softWrap: true,
const SizedBox(
width: 8.0,
),
),
const SizedBox(
width: 8.0,
),
],
],
),
);
}
}
4 changes: 3 additions & 1 deletion lib/src/legend_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class LegendOptions {
final TextStyle legendTextStyle;
final BoxShape legendShape;
final LegendPosition legendPosition;
final Map<String,String> legendLabels;
final Map<String, String> legendLabels;
final double? legendWidth;

const LegendOptions({
this.showLegends = true,
Expand All @@ -16,5 +17,6 @@ class LegendOptions {
this.legendShape = BoxShape.circle,
this.legendPosition = LegendPosition.right,
this.legendLabels = const {},
this.legendWidth,
});
}
Loading