Therefore, rather than relying on a live web service or database,
you can “mock” these dependencies. Mocks allow emulating a live
web service or database and return specific results depending
on the situation.

Generally speaking, you can mock dependencies by creating an alternative
implementation of a class. Write these alternative implementations by
hand or make use of the Mockito package as a shortcut.

This recipe demonstrates the basics of mocking with the
Mockito package using the following steps:

Add the package dependencies.

Create a function to test.

Create a test file with a mock http.Client.

Write a test for each condition.

Run the tests.

For more information, see the Mockito package documentation.

1. Add the package dependencies

To use the mockito package, add it to the
pubspec.yaml file along with the flutter_test dependency in the
dev_dependencies section.