Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,15 @@ Future<void> updatePost() async {
}
}
```

<Callout>

`copyWith` cannot assign `null` to a nullable field: a null argument keeps the current value. Use `copyWithModelFieldValues` instead:

Comment thread
cadivus marked this conversation as resolved.
</Callout>

```dart
final newPost = oldPost.copyWithModelFieldValues(
content: ModelFieldValue.value(null),
);
```
18 changes: 18 additions & 0 deletions src/fragments/lib/graphqlapi/flutter/mutate-data.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@ Future<void> updateTodo(Todo originalTodo) async {
}
```

<Callout>

`copyWith` cannot assign `null` to a nullable field: a null argument keeps the current value. Use `copyWithModelFieldValues` instead:

</Callout>

```dart
Future<void> clearTodoDescription(Todo originalTodo) async {
final cleared = originalTodo.copyWithModelFieldValues(
description: ModelFieldValue.value(null),
);

final request = ModelMutations.update(cleared);
final response = await Amplify.API.mutate(request: request).response;
safePrint('Response: $response');
}
```

To delete the `Todo`:

```dart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@ do {
<InlineFilter filters={["flutter"]}>

```dart
final memberWithRemovedTeam = existingMember.copyWith(team: null);
final memberWithRemovedTeam = existingMember.copyWithModelFieldValues(
teamId: ModelFieldValue.value(null),
);
final memberRemoveRequest = ModelMutations.update(memberWithRemovedTeam);
final memberRemoveResponse = await Amplify.API.mutate(request: memberRemoveRequest).response;
```
Expand Down Expand Up @@ -687,7 +689,9 @@ do {
<InlineFilter filters={["flutter"]}>

```dart
final cartWithRemovedCustomer = existingCart.copyWith(customer: null);
final cartWithRemovedCustomer = existingCart.copyWithModelFieldValues(
customerId: ModelFieldValue.value(null),
);
final cartRemoveRequest = ModelMutations.update(cartWithRemovedCustomer);
final cartRemoveResponse = await Amplify.API.mutate(request: cartRemoveRequest).response;
```
Expand Down
18 changes: 18 additions & 0 deletions src/pages/[platform]/build-a-backend/data/mutate-data/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,24 @@ Future<void> updateTodo(Todo originalTodo) async {
}
```

<Callout>

`copyWith` cannot assign `null` to a nullable field: a null argument keeps the current value. Use `copyWithModelFieldValues` instead:

</Callout>

```dart
Future<void> clearTodoDescription(Todo originalTodo) async {
final cleared = originalTodo.copyWithModelFieldValues(
description: ModelFieldValue.value(null),
);

final request = ModelMutations.update(cleared);
final response = await Amplify.API.mutate(request: request).response;
safePrint('Response: $response');
}
```

</InlineFilter>

## Delete an item
Expand Down
18 changes: 18 additions & 0 deletions src/pages/[platform]/frontend/data/mutate-data/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,24 @@ Future<void> updateTodo(Todo originalTodo) async {
}
```

<Callout>

`copyWith` cannot assign `null` to a nullable field: a null argument keeps the current value. Use `copyWithModelFieldValues` instead:

</Callout>

```dart
Future<void> clearTodoDescription(Todo originalTodo) async {
final cleared = originalTodo.copyWithModelFieldValues(
description: ModelFieldValue.value(null),
);

final request = ModelMutations.update(cleared);
final response = await Amplify.API.mutate(request: request).response;
safePrint('Response: $response');
}
```

</InlineFilter>

## Delete an item
Expand Down