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

late keyword is not working when defining a specific type #412

Closed
phamnhuvu-dev opened this issue Apr 7, 2023 · 2 comments
Closed

late keyword is not working when defining a specific type #412

phamnhuvu-dev opened this issue Apr 7, 2023 · 2 comments

Comments

@phamnhuvu-dev
Copy link

I am not sure if it is a bug or not, I could write these codes by hand late Machine _machine; without any problems, so I want to ask about this.

Info:
Version: code_builder: ^4.4.0
Dart SDK version: 2.18.2 (stable) (Tue Sep 27 13:24:11 2022 +0200) on "macos_arm64"

Code:

Field(
  (updates) => updates
    ..name = '_machine'
    ..late = true
    ..type = refer('Machine'),
)

Current behavior:
Generate:

Machine _machine;

Expect behavior
Generate:

late Machine _machine;
@Snehal-Singh174
Copy link
Contributor

The latest version will add late keyword only when create a late field using null-safety. Hence, you have to specify useNullSafetySyntax: true inside DartEmitter

DartEmitter(useNullSafetySyntax: true)

Refer the test of field: https://github.com/dart-lang/code_builder/blob/master/test/specs/field_test.dart

@phamnhuvu-dev
Copy link
Author

@Snehal-Singh174 Thank you, I got it

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

2 participants