Skip to content

Migration guide to 3.0

Josip Krnjic edited this page Oct 31, 2022 · 6 revisions

Welcome to migration guide for 3.0

This is a major update for the package, and these are the changes:

ChartState: data and itemOptions are now required named parameters

  • Before:
   ChartState(
     _yourData,
   );
  • Now:
   ChartState(
     data: _yourData,
     itemOptions: BarItemOptions(),
   );

Instead of automatically assigning BarItemOptions, now this important parameter will be required for you to enter. You can enter either BarItemOptions, BubbleItemOptions or WidgetItemOptions.

To make it more consistent we also changed data to also be the required named parameter.


Data: BarValue and BubbleValue deprecated

  • Deprecated: BarValue, BubbleValue: ChartData([[3,4,5,3,5].map((e) => BarValue<void>(e.toDouble())).toList()])
  • Use: ChartItem: ChartData([[3,4,5,3,5].map((e) => ChartItem<void>(e.toDouble())).toList()])

The BarValue and BubbleValue were not used to draw exactly bar or bubble. They were just setting the item min and max height. It was confusing since you could use BubbleChart with BarItem. So now we just force using the ChartItem(max, {min, value}).


Data: multiItemStack renamed and moved to StackStrategy

  • Use stackMultipleValues in DefaultDataStrategy: DefaultDataStrategy(stackMultipleValues: true))

The multiItemStack was property of ItemOptions but now it's moved to strategy. Reason is that behaviour is very connected with the strategy and with this we can prevent cases where specific options don't make sense. We also renamed it to stackMultipleValues.


Options: Complete overhaul

  • Use new builder parameter:
BarItemOptions(
  padding: const EdgeInsets.symmetric(horizontal: 2.0),
  minBarWidth: 4.0,
  barItemBuilder: (data) {
    return BarItem(
      radius: const BorderRadius.vertical(top: Radius.circular(24.0)),
      color: Colors.red.withOpacity(0.4),
    );
 },
)

The options had some configurability with a colorForKey or colorForValue builders, which gave you option to change a color for specific list or for the value of the list. But, what if you wanted to change e.g. gradient, radius or any other propery? They didn't have these forKey or forValue builders. So from now on the main and required parameter is itemBuilder. It receives ItemBuilderData with ChartItem, itemKey and listKey so you can build completely different items.

The biggest "new" here is the introduction of WidgetItemOptions which works with a same builder, but you can return any kind of Widget.


Decorations: Massive deprecations

  • Use new WidgetDecoration

Similar to the WidgetItemOptions, we introduced the WidgetDecoration which allows you to return any kind of Widget for decoration. With this change, we will deprecate some of the more "niche" decoration since they are not completely customizable and they can all be reimplemented as WidgetDecoration: TargetLineDecoration, TargetLineTextDecoration, TargetAreaDecoration, BorderDecoration, SelectedItemDecoration, ValueDecoration.

In the /example project there is now Migration screen with decorations reimplemented as WidgetDecoration.