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

migrate Optional<T> -> "T?" #679

Closed
fzyzcjy opened this issue Mar 6, 2021 · 4 comments
Closed

migrate Optional<T> -> "T?" #679

fzyzcjy opened this issue Mar 6, 2021 · 4 comments

Comments

@fzyzcjy
Copy link

fzyzcjy commented Mar 6, 2021

Hi thanks for the lib! Since now null safety is stable, we want to migrate all Optional<T> to T?. Can this be done with some tools? Thanks

@cbracken
Copy link
Member

cbracken commented Mar 6, 2021

Unfortunately we don't have any tools to automatically migrate Optional<T>s to T?. It could be done by using the analyzer package.

There are a few bits to be careful of. Specifically:

  1. The transform and transformNullable methods.
  2. Dealing with the fact that Optional<T> implements Iterable<T>. This allows Optionals to be elided when used in an iterable context such that, for example [Optional<int>.of(1), Optional<int>.absent(), Optional<int>.of(2)].expand((i) => i) results in [1, 2]. See: Make Optional implement Iterable #289

If you or anyone else were keen to implement such a thing in a tested way, I think we'd be glad to point people to it in the docs for Optional, or add it as a tool under a bin directory.

@SShayashi
Copy link

Are there any new updates?
The latest Flutter 3.10 adopts Dart3 and only allows null safety code to be executed.
Many developers will be looking for a migration tool.

@fzyzcjy
Copy link
Author

fzyzcjy commented May 23, 2023

I personally migrated it (2 years ago) using hacky regular expressions...

@cbracken
Copy link
Member

No updates. None of the authors currently have time to write such a tool, but as I say, we'd gladly point people to a tool if someone else were to write one. I'm going to close this issue as this isn't on the roadmap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants