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

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

Open
evaisse opened this issue Sep 4, 2024 · 0 comments

Comments

@evaisse
Copy link

evaisse commented Sep 4, 2024

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.

  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 :

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

Now it's that version :

  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.

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

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...

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

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

Thx,

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

1 participant