title: Mock http.Client in Dart gives exception
body: <p>I have a problem when testing my classes that make http requests.
  I want to Mock the client so that every time the client makes a request, I can answer with a Mocked response.
  At the moment my code looks like this:</p>
  <pre><code>  final fn = MockClientHandler;
    final client = MockClient(fn as Future&lt;Response&gt; Function(Request));
  
    when(client.get(url)).thenAnswer((realInvocation) async =&gt;
      http.Response('{&quot;userId&quot;: 1, &quot;id&quot;: 2, &quot;title&quot;: &quot;mock&quot;}', 200));
  </code></pre>
  <p>However, when I run the test I get the following exception:
  <code>type '_FunctionType' is not a subtype of type '(Request) =&gt; Future&lt;Response&gt;' in type cast test/data_retrieval/sources/fitbit_test.dart 26:32  main </code></p>
  <p>According to Flutter/Dart Mockito should be used like this:</p>
  <pre><code> final client = MockClient();
  
    // Use Mockito to return a successful response when it calls the
    // provided http.Client.
    when(client.get(Uri.parse('https://jsonplaceholder.typicode.com/albums/1')))
        .thenAnswer((_) async =&gt; http.Response('{&quot;userId&quot;: 1, &quot;id&quot;: 2, &quot;title&quot;:&quot;mock&quot;}', 200));
  </code></pre>
  <p>In the example, the client is mocked without parameters, but I guess this has been changed since the documentation of MockClient now also accepts a parameter.
  I have no idea why this exception occurs and nothing can be found on the internet, so I was wondering if someone here knows why this exception is happening.</p>