Commit 5a34b58
committed
fix: strip non-nullable optional params in Dart/Flutter SDKs
This change updates the Dart and Flutter SDK templates to conditionally
include non-nullable optional parameters in the request params map only
when they are not null.
Previously, all parameters were always included in the params map,
which could lead to unnecessary null values being sent in API requests.
This implementation matches the Python SDK behavior (templates/python/base/params.twig)
where optional non-nullable parameters are checked with "if not None" before
being added to api_params.
Changes:
- Modified templates/dart/base/utils.twig map_parameter macro
- Modified templates/flutter/base/utils.twig map_parameter macro
- Uses Dart's collection-if syntax for conditional parameter inclusion
- Adds null assertion operator (!) for enum values when inside null check
Example generated code:
```dart
final Map<String, dynamic> apiParams = {
'requiredParam': requiredParam,
if (optionalParam != null) 'optionalParam': optionalParam,
};
```1 parent 1a7a3b8 commit 5a34b58
2 files changed
+8
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
3 | 6 | | |
| 7 | + | |
4 | 8 | | |
5 | 9 | | |
6 | 10 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
3 | 6 | | |
| 7 | + | |
4 | 8 | | |
5 | 9 | | |
6 | 10 | | |
| |||
0 commit comments