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

Getter 'a' is Not Defined for Class 'Color' in axis_chart_data.dart #1846

Open
jishnugopalan opened this issue Jan 11, 2025 · 23 comments
Open

Comments

@jishnugopalan
Copy link

jishnugopalan commented Jan 11, 2025

When using the fl_chart package version 0.70.1, I encountered an error in axis_chart_data.dart at line 1409. The getter a is not defined for the class Color. This issue occurs when checking the alpha value of strokeColor in the if condition.

Error: The getter 'a' isn't defined for the class 'Color'.
'Color' is from 'dart:ui'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'a'.
if (strokeWidth != 0.0 && strokeColor.a != 0.0) {
^
Steps to Reproduce:

Add fl_chart version 0.70.1 to a Flutter project.
Use a widget from fl_chart that involves axis-based charts (e.g., LineChart or BarChart).
Run the project.

Expected Behavior: The chart should render without errors.

Actual Behavior: A compilation error occurs due to the use of a non-existent getter a on the Color class.

Additional Information:

Flutter version: [Provide your Flutter version]
Dart version: [Provide your Dart version]

Suggested Fix: Replace the a getter with opacity or use value to get the ARGB components. For example:

if (strokeWidth != 0.0 && strokeColor.opacity != 0.0) {

@alcampospalacios
Copy link

Same error over here

@bankrot6
Copy link

+1

@expertmars
Copy link

Same for me...
Do we have any older version for use now without this bug?

@hoangneeee
Copy link

Same for me

@hoangneeee
Copy link

Same for me... Do we have any older version for use now without this bug?

You try old version 0.66.1, I am using it, and this works for me.

@Michkwetzel
Copy link

Also having this Error

@ArizArmeidi
Copy link

same issue, downgraded to 0.69.0 and it works. currently my project is still on Flutter 3.24.4 could that be the cause?

@jishnugopalan
Copy link
Author

I am using pie_chart: ^5.0.0 . Its very easy

@E-Anas
Copy link

E-Anas commented Jan 20, 2025

running flutter upgrade worked for me

@idrinkandiknowthing
Copy link

I’m using fl_chart version 0.69.0, and it seems to be working fine. However, I need to use version 0.70.1 to create a horizontal bar chart. Unfortunately, I’m encountering the same error as you. Can you help me out with this?

@luszczynski
Copy link

+1

1 similar comment
@mhchofficial
Copy link

+1

@Leozin777
Copy link

Leozin777 commented Jan 30, 2025

Same error over here, but and 0.70.2

@bodacious-me
Copy link

same error with the latest version of fl_chart

@bodacious-me
Copy link

same issue, downgraded to 0.69.0 and it works. currently my project is still on Flutter 3.24.4 could that be the cause?

Tried it out works fine Thanks: 0.66.1

@GiulianoRM
Copy link

GiulianoRM commented Jan 31, 2025

+1 Same error over here, but and 0.70.2

Somebody knows if is possible turn arround the BarChart to horizontal direction on another version without this bug?

@imaNNeo , help here please!

@Leonard0912
Copy link

+1 same error

@lancedw
Copy link

lancedw commented Feb 8, 2025

same here

@Fady4Mohamed
Copy link

this happened in new versions . use [0.69.2] version to solve it

@bcheidemann
Copy link

Same issue on Flutter 3.24.5 with fl_chart 0.70.2. Issue is resolved by downgrading to fl_chart 0.69.2.

Looks like this issue was introduced in 1998d92 (feat: Upgrade to Flutter 3.27.0):

diff --git a/lib/src/chart/base/axis_chart/axis_chart_data.dart b/lib/src/chart/base/axis_chart/axis_chart_data.dart
index a71fa600..5f7525d0 100644
--- a/lib/src/chart/base/axis_chart/axis_chart_data.dart
+++ b/lib/src/chart/base/axis_chart/axis_chart_data.dart
@@ -1377,7 +1377,7 @@ class FlDotCirclePainter extends FlDotPainter {
   /// Implementation of the parent class to draw the circle
   @override
   void draw(Canvas canvas, FlSpot spot, Offset offsetInCanvas) {
-    if (strokeWidth != 0.0 && strokeColor.opacity != 0.0) {
+    if (strokeWidth != 0.0 && strokeColor.a != 0.0) {
       canvas.drawCircle(
         offsetInCanvas,
         radius + (strokeWidth / 2),
@@ -1474,7 +1474,7 @@ class FlDotSquarePainter extends FlDotPainter {
   /// Implementation of the parent class to draw the square
   @override
   void draw(Canvas canvas, FlSpot spot, Offset offsetInCanvas) {
-    if (strokeWidth != 0.0 && strokeColor.opacity != 0.0) {
+    if (strokeWidth != 0.0 && strokeColor.a != 0.0) {
       canvas.drawRect(
         Rect.fromCircle(
           center: offsetInCanvas,

I suspect this change was made because the opacity getter is deprecated in recent Flutter versions. However, this breaks compatibility with previous Flutter versions where the a property has not yet been added.

Either the supported Flutter version needs to be bumped (currently it's on flutter: '>=3.16.0'), or the offending changes should be temporarily reverted.

Imo, since Flutter has not yet removed the opacity getter, it would be preferable to use this until it is removed, as this maximises the range of compatible Flutter versions for this package.

I'd happy to contribute the required changes if that would be helpful 👍

@Leozin777
Copy link

Leozin777 commented Feb 10, 2025

Thanks @bcheidemann, on pub.dev the minimum version is 3.2, I think it should be clearer there, 0.70 has dart 3.27 and 0.69 has 3.24

@bcheidemann
Copy link

bcheidemann commented Feb 11, 2025

Thanks @bcheidemann, on pub.dev the minimum version is 3.2, I think it should be clearer there, 0.70 has dart 3.27 and 0.69 has 3.24

Hi @Leozin777, thanks for your comment 🙂 Are you referring to the minimum Dart SDK version listed on pub.dev? I don't believe the Dart SDK version constraint is the issue here. Based on testing and review of the source codes for Flutter and fl_chart, the Flutter version constraint declared in the pubspec.yaml (flutter: '>=3.16.0') is incorrect. I haven't determined what the last supported version of Flutter is, but based on my testing (and review of the source code) at least flutter: '<= 3.24.5' is not supported due to the changes in 1998d92.

@Leozin777
Copy link

Leozin777 commented Feb 11, 2025

oh right, thanks @bcheidemann for your help with this question, I appreciate

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