Skip to content

Conversation

@ChiragAgg5k
Copy link
Member

@ChiragAgg5k ChiragAgg5k commented Nov 10, 2025

Summary

This PR 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, matching the behavior of the Python SDK.

Changes

  • Modified templates/dart/base/utils.twig map_parameter macro
  • Modified templates/flutter/base/utils.twig map_parameter macro

Implementation Details

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:15-17 and 26-28) where optional non-nullable parameters are checked with if not None before being added to api_params.

Generated Code Example

Before:

final Map<String, dynamic> apiParams = {
  'requiredParam': requiredParam,
  'optionalParam': optionalParam,  // Always included, even if null
};

After:

final Map<String, dynamic> apiParams = {
  'requiredParam': requiredParam,
  if (optionalParam != null) 'optionalParam': optionalParam,  // Only included when not null
};

Technical Details

  • Uses Dart's collection-if syntax for conditional parameter inclusion
  • Adds null assertion operator (!) for enum values when inside null check
  • Only applies to parameters that are both:
    • Not nullable (not parameter.nullable)
    • Not required (not parameter.required)

Test Plan

  • Generate Dart SDK and verify optional params are conditionally included
  • Generate Flutter SDK and verify optional params are conditionally included
  • Verify required parameters are always included
  • Verify nullable parameters are always included

Summary by CodeRabbit

  • Bug Fixes
    • Improved null handling: non-nullable, non-required parameters are included only when a value is present (enums formatted correctly).
    • Request construction changed: null-valued parameters are no longer globally removed and are now handled at emission time, affecting how query, multipart and form requests include or skip nulls.

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,
};
```
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 10, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds conditional emission in the map_parameter macro (Dart and Flutter templates) so non-nullable, non-required parameters are emitted only when non-null, with special enum value formatting. Removes the early global filter that stripped null entries from params in both Dart and Flutter client_mixin.dart.twig files and instead applies null-skipping at per-key processing: multipart parts skip nulls and null list elements; GET parameter construction builds a filtered params map that excludes nulls and converts numeric and list values appropriately. No public signatures changed.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Heterogeneous changes: small macro branching plus substantive request-parameter handling logic.
  • Files to focus on:
    • templates/dart/base/utils.twig and templates/flutter/base/utils.twig: verify the map_parameter conditional, punctuation, and enum formatting.
    • templates/dart/lib/src/client_mixin.dart.twig and templates/flutter/lib/src/client_mixin.dart.twig: verify new per-key null handling for multipart, list expansions, and GET query construction.
    • Regression risk where retained nulls change request payload shapes or introduce runtime errors.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: fixing how non-nullable optional parameters are handled in Dart/Flutter SDKs by stripping them when null.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-dart-flutter-optional-params

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the Dart and Flutter SDK templates to conditionally include non-nullable optional parameters in API request maps only when they are not null, aligning with Python SDK behavior.

  • Modified parameter mapping logic to use collection-if syntax for non-nullable optional params
  • Removed removeWhere null filtering from client request preparation
  • Added null assertion operator for enum values within null checks

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
templates/dart/base/utils.twig Added conditional inclusion logic for non-nullable optional parameters using collection-if syntax
templates/flutter/base/utils.twig Added conditional inclusion logic for non-nullable optional parameters using collection-if syntax
templates/dart/lib/src/client_mixin.dart.twig Removed removeWhere call that filtered null values from params map
templates/flutter/lib/src/client_mixin.dart.twig Removed removeWhere call that filtered null values from params map

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ChiragAgg5k ChiragAgg5k force-pushed the fix-dart-flutter-optional-params branch from 487b18f to ecfc5fb Compare November 12, 2025 08:51
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ecfc5fb and 3c12f46.

📒 Files selected for processing (2)
  • templates/dart/lib/src/client_mixin.dart.twig (2 hunks)
  • templates/flutter/lib/src/client_mixin.dart.twig (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • templates/flutter/lib/src/client_mixin.dart.twig

@loks0n loks0n merged commit 958947b into master Nov 12, 2025
58 checks passed
@ChiragAgg5k
Copy link
Member Author

appwrite/sdk-for-dart#47

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

Successfully merging this pull request may close these issues.

3 participants