aws-amplify / aws-amplify/amplify-codegen
[codegen models] add 'required' modifier in constructors when a field is non-nullable
- Dominant language
- TypeScript
- Stars
- 59
- Forks
- 64
- PR merge metrics
- No merged PRs in 30d
Description
### Description
The models generated by `amplify codegen models` won't compile because of the following error:
> The parameter 'id' can't have a value of 'null' because of its type, but the implicit default value is 'null'. [(Documentation)](https://dart.dev/tools/diagnostic-messages?utm_source=dartdev&utm_medium=redir&utm_id=diagcode&utm_content=missing_default_value_for_parameter#missing_default_value_for_parameter)
> Try adding either an explicit non-'null' default value or the 'required' modifier.
The generated field definition looks like this:
```dart
final String id;
```
And the generated constructor looks like this:
```
const Someclass._internal({this.id});
```
Since this field is non-nullable, the constructor should be generated like so:
```
const Someclass._internal({required this.id});
```
This causes us some overhead as we have to update the generated files manually each time.
We're on CLI version `12.0.3` and Flutter version `3.10.2`.
### Categories
- [ ] Analytics
- [ ] API (REST)
- [ ] API (GraphQL)
- [ ] Auth
- [ ] Authenticator
- [ ] DataStore
- [ ] Storage
### Steps to Reproduce
Have a model with a non-nullable field.
Run `amplify codegen models`.
Try compiling they project with the latest version of Flutter.
### Screenshots
_No response_
### Platforms
- [ ] iOS
- [ ] Android
- [ ] Web
- [ ] macOS
- [ ] Windows
- [ ] Linux
### Flutter Version
3.10.2
### Amplify Flutter Version
1.1.0
### Deployment Method
Amplify CLI
### Schema
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.