From f08881a63f036f7649d57483536a9571f538700d Mon Sep 17 00:00:00 2001 From: Bean Labs Date: Mon, 8 Jun 2026 13:05:02 -0400 Subject: [PATCH] docs: clarify widget test service injection --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 7fb88aa..6471094 100644 --- a/README.md +++ b/README.md @@ -3215,6 +3215,18 @@ class TodoList extends StatefulWidget { } ``` +In `_TodoListState`, use the injected service when loading the todos. +This lets widget tests pass a mock `TodoService` instead of making the widget +create its own real service. + +```dart +@override +void initState() { + super.initState(); + futureTodosList = widget.todoService.getTodos(); +} +``` + Now, we need to change the `MyApp` class to pass a `TodoService` instance to `TodoList`. It should look like this, now.