Skip to content

Document how to set a model field to null #5019

Open
@sampaio96

Description

@sampaio96

Description

The auto-generated model.dart code on Flutter does not allow setting nullable fields to null.

model = model.copyWith(nullableField: null)
Does not work.

We need an alternative like
model = model.removeKey(Model.NULLABLEFIELD)

Categories

  • Analytics
  • API (REST)
  • API (GraphQL)
  • Auth
  • Authenticator
  • DataStore
  • Notifications (Push)
  • Storage

Steps to Reproduce

Take this model:

type Model @model {
  id: ID!
  nullableField: String
}

This is the auto-generated Model.dart, which we use to update the model.

Model copyWith({String? nullableField}) {
    return Model._internal(
      id: id,
      nullableField: nullableField ?? this.nullableField,
    )
}

If you run:

model = model.copyWith(nullableField: null)

Your model will not change the nullableField to null.

Screenshots

No response

Platforms

  • iOS
  • Android
  • Web
  • macOS
  • Windows
  • Linux

Flutter Version

3.22.0

Amplify Flutter Version

1.7.0

Deployment Method

Amplify CLI

Schema

type Model @model {
  id: ID!
  nullableField: String
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationImprovements or fixes to public documentation (docs.amplify.aws, pub.dev, readmes).GraphQL APIIssues related to the API (GraphQL) Categoryfeature-requestA request for a new feature or an enhancement to an existing API or category.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions