Skip to content

Conversation

iamngoni
Copy link

@iamngoni iamngoni commented Oct 4, 2025

What does this PR do?

fix: 🐛 Handle null values for integer properties in Dart models

Fixes #1150 - Type 'Null' is not a subtype of type 'int' by adding explicit type casting for integer properties to properly handle null values for optional & required fields.

Test Plan

[x] Ran both Dart & Flutter tests (both passed)

Related PRs and Issues

#1150

Have you read the Contributing Guidelines on issues?

Yes

Summary by CodeRabbit

  • New Features

    • None.
  • Bug Fixes

    • Corrects model deserialization for integer fields to properly cast values and respect nullability, reducing unexpected type coercion and errors.
  • Improvements

    • Preserves existing behavior for numeric (double) and string fields while ensuring more predictable handling of integers.
    • No changes to array or enum deserialization behavior, maintaining compatibility.

Copy link
Contributor

coderabbitai bot commented Oct 4, 2025

Walkthrough

Updates templates/dart/lib/src/models/model.dart.twig to explicitly handle integer properties in fromMap: when property.type equals "integer", values are cast to int (or int? for optional). Existing logic for other non-array types remains: numbers use toDouble() with nullability as needed, and strings use toString() with nullability. Array, enum handling, and overall fromMap structure are unchanged.

Possibly related PRs

Suggested reviewers

  • ChiragAgg5k

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title directly references the core change of handling null values for integer properties in Dart models, clearly summarizing the main purpose of the PR in a concise, single sentence.
Linked Issues Check ✅ Passed The PR adds explicit casting of integer properties to int or int? based on nullability, which directly addresses the linked issue’s TypeError by allowing null values without throwing an error as described in issue #1150.
Out of Scope Changes Check ✅ Passed All modifications are confined to the fromMap constructor’s handling of integer properties and no unrelated files or features were altered beyond the scope of fixing null handling.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c30701f and 1828d46.

📒 Files selected for processing (1)
  • templates/dart/lib/src/models/model.dart.twig (1 hunks)
🔇 Additional comments (1)
templates/dart/lib/src/models/model.dart.twig (1)

46-60: LGTM! Fix correctly addresses the null handling issue for integer properties.

The explicit type casting for integer properties properly handles null values:

The restructured logic preserves existing behavior for non-integer types (numbers use toDouble(), strings use toString()). The strict casting approach is correct—if the backend sends incorrect types (e.g., double 123.0 or string "123" for integer fields), the cast will fail, which helps catch data integrity issues early rather than allowing silent type mismatches.


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.

@ChiragAgg5k
Copy link
Member

@iamngoni this issue as well seems to be related to $sequence, can you please verify its an actual issue now? we have reports that the issue has been fixed already since it was a server side change

@iamngoni
Copy link
Author

iamngoni commented Oct 5, 2025

Hi @ChiragAgg5k,

You're right that this is related to $sequence. However, I believe this PR is still valuable as a defensive measure because:

  1. The server-side fix only helps users on latest Appwrite instances
  2. Users on older self-hosted versions still experience this issue
  3. This SDK-side fix would handle null values gracefully for all integer properties

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.

🐛 Bug Report: Appwrite Flutter SDK TypeError: null: type 'Null' is not a subtype of type 'int' in 17.1.0
2 participants