title: Flutter widget test of a custom widget fails
body: <p>I am trying to test a custom widget <code>GoogleSignInButton</code>.</p>
  
  <p>Here is the implementation of the widget:</p>
  
  <pre><code>import 'package:flutter/material.dart';
  
  class GoogleSignInButton extends StatelessWidget {
    GoogleSignInButton({this.onPressed});
  
    final Function onPressed;
  
    @override
    Widget build(BuildContext context) {
      Image _buildLogo() {
        return Image.asset(
          "assets/g-logo.png",
          height: 18.0,
          width: 18.0,
        );
      }
  
      Opacity _buildText() {
        return Opacity(
          opacity: 0.54,
          child: Text(
            "Sign in with Google",
            style: TextStyle(
              fontFamily: 'Roboto-Medium',
              color: Colors.black,
            ),
          ),
        );
      }
  
      return MaterialButton(
        height: 40.0,
        onPressed: this.onPressed,
        color: Colors.white,
        child: Row(
          mainAxisSize: MainAxisSize.min,
          children: &lt;Widget&gt;[
            _buildLogo(),
            SizedBox(width: 24.0),
            _buildText(),
          ],
        ),
      );
    }
  }
  </code></pre>
  
  <p>I am trying to test the <code>onPressed</code> function callback by the test that follows.</p>
  
  <pre><code>import 'package:flutter/material.dart';
  import 'package:flutter_test/flutter_test.dart';
  import '../lib/ui/widgets/google_sign_in_button.dart';
  
  void main() {
    testWidgets('my first widget test', (WidgetTester tester) async {
      var pressed = false;
      var widget = GoogleSignInButton(
        onPressed: () =&gt; () {
              pressed = true;
            },
      );
  
      await tester.pumpWidget(
        StatefulBuilder(
          builder: (BuildContext context, StateSetter setState) {
            return MaterialApp(
              home: Material(
                child: Center(
                  child: widget,
                ),
              ),
            );
          },
        ),
      );
  
      await tester.press(find.byWidget(widget));
      expect(pressed, equals(true));
    });
  }
  </code></pre>
  
  <p>Unfortunately, the test fails.</p>
  
  <p>I am executing my widget test on the command line by <strong>flutter test test/widget_test.dart</strong> and here is the result of the test:</p>
  
  <pre><code>══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
  The following TestFailure object was thrown running a test:
    Expected: &lt;true&gt;
    Actual: &lt;false&gt;
  
  When the exception was thrown, this was the stack:
  #4      main.&lt;anonymous closure&gt; (file:///home/hans/Development/flutter/recipes_app/test/widget_test.dart:30:5)
  &lt;asynchronous suspension&gt;
  #5      testWidgets.&lt;anonymous closure&gt;.&lt;anonymous closure&gt; (package:flutter_test/src/widget_tester.dart:72:23)
  #6      TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:566:19)
  &lt;asynchronous suspension&gt;
  #9      TestWidgetsFlutterBinding._runTest (package:flutter_test/src/binding.dart:550:14)
  #10     AutomatedTestWidgetsFlutterBinding.runTest.&lt;anonymous closure&gt; (package:flutter_test/src/binding.dart:893:24)
  #16     AutomatedTestWidgetsFlutterBinding.runTest (package:flutter_test/src/binding.dart:890:15)
  #17     testWidgets.&lt;anonymous closure&gt; (package:flutter_test/src/widget_tester.dart:71:22)
  #18     Declarer.test.&lt;anonymous closure&gt;.&lt;anonymous closure&gt;.&lt;anonymous closure&gt; (package:test_api/src/backend/declarer.dart:168:27)
  &lt;asynchronous suspension&gt;
  #19     Invoker.waitForOutstandingCallbacks.&lt;anonymous closure&gt; (package:test_api/src/backend/invoker.dart:249:15)
  &lt;asynchronous suspension&gt;
  #24     Invoker.waitForOutstandingCallbacks (package:test_api/src/backend/invoker.dart:246:5)
  #25     Declarer.test.&lt;anonymous closure&gt;.&lt;anonymous closure&gt; (package:test_api/src/backend/declarer.dart:166:33)
  #30     Declarer.test.&lt;anonymous closure&gt; (package:test_api/src/backend/declarer.dart:165:13)
  &lt;asynchronous suspension&gt;
  #31     Invoker._onRun.&lt;anonymous closure&gt;.&lt;anonymous closure&gt;.&lt;anonymous closure&gt;.&lt;anonymous closure&gt; (package:test_api/src/backend/invoker.dart:399:25)
  &lt;asynchronous suspension&gt;
  #45     _Timer._runTimers (dart:isolate/runtime/libtimer_impl.dart:382:19)
  #46     _Timer._handleMessage (dart:isolate/runtime/libtimer_impl.dart:416:5)
  #47     _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)
  (elided 28 frames from class _FakeAsync, package dart:async, and package stack_trace)
  
  This was caught by the test expectation on the following line:
    file:///home/hans/Development/flutter/recipes_app/test/widget_test.dart line 30
  
  The test description was:
  my first widget test
  ════════════════════════════════════════════════════════════════════════════════════════════════════
  00:01 +0 -1: my first widget test [E]                                                                                                                                                                             
    Test failed. See exception logs above.
    The test description was: my first widget test
  
  00:02 +0 -1: Some tests failed.
  </code></pre>
  
  <p>Any ideas why the test fails?</p>