[英]How can i set the color of the bars with the values gotten from a provider file when using charts_flutter package
I have been trying to set the colors of the bars in a bar chart with values from a provider file so that i can be able to change the color from other activities.我一直在尝试使用提供程序文件中的值设置条形图中条形的颜色,以便我能够更改其他活动的颜色。 If i directly put the color value like this如果我直接把颜色值像这样
colorFn: (Kpi kpi, _) => charts.ColorUtil.fromDartColor(Color(0xff000000)),
it works.有用。
But trying to do this like this但试图这样做
colorFn: (Kpi kpi, _) => charts.ColorUtil.fromDartColor(Color(context.watch<Providers>().colorAlpha)),
It does not work.这是行不通的。
i get the following error我收到以下错误
I/flutter ( 1999): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter ( 1999): The following NoSuchMethodError was thrown during performLayout():
I/flutter ( 1999): The method '&' was called on null.
I/flutter ( 1999): Receiver: null
I/flutter ( 1999): Tried calling: &(4294967295)
I/flutter ( 1999):
I/flutter ( 1999): The relevant error-causing widget was:
I/flutter ( 1999): ChartContainer<String>
I/flutter ( 1999): file:///C:/flutter/.pub-cache/hosted/pub.dartlang.org/charts_flutter-0.9.0/lib/src/base_chart_state.dart:89:32
I/flutter ( 1999):
I/flutter ( 1999): When the exception was thrown, this was the stack:
I/flutter ( 1999): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
I/flutter ( 1999): #1 new Color (dart:ui/painting.dart:109:42)
I/flutter ( 1999): #2 _AnalyticspageState.build.<anonymous closure> (package:GapHub/screens/analyticspage.dart:86:42)
I/flutter ( 1999): #3 new Series.<anonymous closure> (package:charts_common/src/data/series.dart:143:56)
I/flutter ( 1999): #4 DomainHighlighter._updateColorFunctions.<anonymous closure>.<anonymous closure> (package:charts_common/src/chart/common/behavior/domain_highlighter.dart:53:40)
I/flutter ( 1999): #5 BaseBarRenderer.update.<anonymous closure> (package:charts_common/src/chart/bar/base_bar_renderer.dart:407:31)
I/flutter ( 1999): #6 List.forEach (dart:core-patch/growable_array.dart:302:8)
I/flutter ( 1999): #7 BaseBarRenderer.update (package:charts_common/src/chart/bar/base_bar_renderer.dart:342:23)
I/flutter ( 1999): #8 BaseChart.onPostLayout.<anonymous closure> (package:charts_common/src/chart/common/base_chart.dart:584:37)
I/flutter ( 1999): #9 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:377:8)
I/flutter ( 1999): #10 BaseChart.onPostLayout (package:charts_common/src/chart/common/base_chart.dart:583:10)
I/flutter ( 1999): #11 CartesianChart.onPostLayout (package:charts_common/src/chart/cartesian/cartesian_chart.dart:428:11)
I/flutter ( 1999): #12 BaseChart.layout (package:charts_common/src/chart/common/base_chart.dart:398:7)
I/flutter ( 1999): #13 ChartContainerRenderObject.performLayout (package:charts_flutter/src/chart_container.dart:215:12)
The way im doing this is我这样做的方式是
return charts.Color.fromHex(
code: "#${Colors.primaries[Random().nextInt(Colors.primaries.length)].value}");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.