Skip to content

Commit 3e992e1

Browse files
committed
Remove unnecessary null check and inline params in handler example
Changes: - Removed if (result != null) check - when watching full command, handler only fires when command completes with result - Added comment clarifying this behavior - Inlined CreateTodoParams in execute call for cleaner code The null check was confusing because watching the command (not command.results) only fires on completion with data.
1 parent 5a1a443 commit 3e992e1

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

code_samples/lib/watch_it/register_handler_example.dart

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@ class TodoCreationPage extends WatchingWidget {
1515
registerHandler(
1616
select: (TodoManager m) => m.createTodoCommand,
1717
handler: (context, result, _) {
18-
if (result != null) {
19-
// Show success message
20-
ScaffoldMessenger.of(context).showSnackBar(
21-
SnackBar(content: Text('Created: ${result.title}')),
22-
);
23-
// Navigate back
24-
Navigator.of(context).pop(result);
25-
}
18+
// Handler only fires when command completes with result
19+
// Show success message
20+
ScaffoldMessenger.of(context).showSnackBar(
21+
SnackBar(content: Text('Created: ${result!.title}')),
22+
);
23+
// Navigate back
24+
Navigator.of(context).pop(result);
2625
},
2726
);
2827

@@ -66,11 +65,12 @@ class TodoCreationPage extends WatchingWidget {
6665
onPressed: isCreating
6766
? null
6867
: () {
69-
final params = CreateTodoParams(
70-
title: titleController.text,
71-
description: descController.text,
72-
);
73-
di<TodoManager>().createTodoCommand.execute(params);
68+
di<TodoManager>().createTodoCommand.execute(
69+
CreateTodoParams(
70+
title: titleController.text,
71+
description: descController.text,
72+
),
73+
);
7474
},
7575
child: isCreating
7676
? const SizedBox(

0 commit comments

Comments
 (0)