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
Add Dart non-nullable support #1673
Comments
+1 we really need this feature. |
It looks to me like that all that is needed for null safety is to make it work exactly like make all fields required, but to use just 'required' as the filed prefix, instead of '@required'. It should probably be under its own switch so that you keep the old functionality. |
Also the tool should detect if some field may be nullable (eg. If some field has null value in provided json). |
Think about It shouldn't even be an option. Quicktype must generate Imagine a |
This is what freezed null-safely generates:
|
dart code generation packages.. stopped using since 2019. especially with localizations. I just personally hate it. the explanation would be too long. It's based on experience. |
+1 We really need to generate dart non-nullable classes with quicktype! |
Also, when the JSON fields are optional the generated class fields should be nullable with class Sensordata {
...
String? sensor;
List<Datum>? data;
...
Map<String, dynamic> toJson() => {
"sensor": sensor == null ? null : sensor,
"data": data == null
? null
: List<dynamic>.from(data!.map((x) => x.toJson())),
};
}
class Datum {
...
String? value;
DateTime? readingTime1;
...
Map<String, dynamic> toJson() => {
"value": value == null ? null : value,
"reading_time1": readingTime1 == null
? null
: "${readingTime1!.year.toString().padLeft(4, '0')}-${readingTime1!.month.toString().padLeft(2, '0')}-${readingTime1!.day.toString().padLeft(2, '0')}",
};
} |
+1 |
1 similar comment
+1 |
The right one should be like this:#1898 |
|
https://github.com/chunlee-thong/dart-quicktype/tree/dev |
we really need this feature.when will change? |
I was also suprised to find, that quicktype did not adapt their tool for a year now. |
I would also love some null-safety support, however there is a workaround: you can add |
I dont think this is a valid option. In dart, one would usually use generated files as |
Yes, I agree, this is not a solution, just a workaround and this should be fixed, however this project doesn't seem to be maintained anymore and I don't know of any alternative, so it's the only thing we have. Also, I don't know what you mean by "migrate the whole project". Those 2 changes (adding |
And to the toolsets that use your dart code (flutter) and to the projects that want to use your library or any other place that has an import. You essentially migrate your project to a Dart 2.10 project with the There's a reason why pub.dev has a chip-indicator/flag for libraries with sound null safety, you generally dont wanna mix the two. and 95% of dart code currently written will want to support sound null safety. |
Ahh yeah, you're right, it's probably not a good workaround for libraries, only applications. |
Well, comments like these aren't going to help |
Disagree. People should be aware that Quicktype as a whole is practically abandonware at this point. While everyone should be grateful for the free, open-sourced code, it's still polite for the authors to mark a project as unmaintained/archived, so people don't create a dependency on it if they're not expecting obvious issues like these. I was someone who didn't notice, created a dependency on it, and am now spending my time trying to patch it instead of working on my projects. |
As Dart non-nullable is stable now, please add option to generate non-nullable classes with the tool (especially freezed classes)
The text was updated successfully, but these errors were encountered: