imaNNeo / imaNNeo/fl_chart

Upgrade question : moving optional named parameters into non optional with defaults values make migration difficult

Open
#1,745 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Dart
Stars
7.6k
Forks
2k
Avg merge
9d 1h
Merged PRs (30d)
2

Description

Hello,

I'm upgrading fl_chart form `0.55` to `0.69`, I have a question regarding the port of optional named parameters into non optional with defaults values classes.

```dart
const FlChartStuff({
// v0.55
double? argInV55, // with default value to 22 applied later in the constructor signature
// v0.66
double argInV66 = 22,
});
```

This does maybe not look like a big change but it does present a lot of new constrains...

For example in `SideTitles`, before the signature was [this one](https://github.com/imaNNeo/fl_chart/blob/0.55.0/lib/src/chart/base/axis_chart/axis_chart_data.dart#L169) :

```dart
const SideTitles({
// ...
double? reservedSize, // with default value to 22
// ...
});
```

Now it's [that version](https://github.com/imaNNeo/fl_chart/blob/0.66.0/lib/src/chart/base/axis_chart/axis_chart_data.dart#L162) :

```dart
const SideTitles({
// ...
double reservedSize = 22,
// ...
});
```

Before, the signature allowed us to pass null params and then it was very handy to create a new instance from wrapped configuration in widgets, e.g.

```dart
SideTitles(
// ...
reservedSize: widget.chartConfig?.size
// ...
)
```

but now I only see 2 solutions to achieve the same behavior, but both seems ugly

The first one imply to call different constructor regarding the input value

```dart
final size = widget.chartConfig?.size;

if (size != null) {
return SideTitles(
// ... other params
reservedSize: size
// ...
);
} else {
return SideTitles(
// ... other params
);
}
```

And the other one implied to pass the default lib value in my code...

```dart
SideTitles(
// ...
reservedSize: widget.chartConfig?.size ?? 22
// ...
)
```

How will you deal with that kind of situation with the new version ?

Thx,

Contributor guide

Open the contributing guide

Research direction

Compare the SideTitles signatures in lib/src/chart/base/axis_chart/axis_chart_data.dart at versions 0.55.0 and 0.66.0, focusing on reservedSize and nullable configuration values. Determine the supported migration approach for wrapped widget configuration, then document that guidance and its consequences for existing callers.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, flutter
Domain
mobile
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.