Repository: flutter
Issue: Scrolling and Tap not working in flutter driver
Labels: a: tests,tool,t: flutter driver,P2,team-tool,triaged-tool

## Steps to Reproduce

I have been using `driver.scroll(...)` and `driver.tap(...)` elsewhere, but have been unable to automate this particular game since tap and scroll time outs even though an unique key is being assigned to each of the element.
```dart

  Widget _buildItem(int index, String text, Status status, ShakeCell shaker) {
    return new MyButton(
        key: new ValueKey<int>(index),
        text: text,
        status: status,
        shaker: shaker,
        onPress: () {
          print("Pressed Index: ${index}");
          print("Pressed Text: ${text}");
          print("Pressed Statuses before checking: ${_statuses}");

          int numOfVisible = _statuses.fold(0,(prev, element) => element == Status.Visible ? prev + 1 : prev);

          if (_pressedTileIndex == index || _statuses[index] == Status.Visible || numOfVisible >= 2 || cnt > 2) 
            return;

          cnt++;

          setState(() {
            _statuses[index] = Status.Visible;
          });

          print("Pressed Statuses1: ${_statuses}");

          if (cnt == 2) {
            if (_pressedTile == text) {
              new Future.delayed(const Duration(milliseconds: 250), () {
                setState(() {
                  _letters[_pressedTileIndex] = null;
                  _letters[index] = null;
                  _statuses[_pressedTileIndex] = Status.Disappear;
                  _statuses[index] = Status.Disappear;
                  _pressedTileIndex = -1;
                  _pressedTile = null;
                  cnt = 0;
                });
              });

              _matched++;
              widget.onScore(2);
              widget.onProgress((_progressCnt) / (_allLetters.length / 2));
              _progressCnt++;

              print("Rajesh-Matched${_matched}");
              if (_matched == 8) {
                _matched = 0;
                new Future.delayed(const Duration(milliseconds: 250), () {
                  print("Rajesh Game-End");
                  widget.onEnd();
                });
              }
              print("Pressed Statuses2: ${_statuses}");
              print("Matched");
            } 
            else {
              new Future.delayed(const Duration(milliseconds: 50), () {
                setState(() {
                  _shaker[_pressedTileIndex] = ShakeCell.Wrong;
                  _shaker[index] = ShakeCell.Wrong;
                });
              }); 

              new Future.delayed(const Duration(milliseconds: 500), () {
                setState(() {
                  _shaker[_pressedTileIndex] = ShakeCell.Right;
                  _shaker[index] = ShakeCell.Right;
                });
              });

              new Future.delayed(const Duration(milliseconds: 800), () {
                setState(() {
                  _statuses[_pressedTileIndex] = Status.Hidden;
                  _statuses[index] = Status.Hidden;
                  _pressedTileIndex = -1;
                  _pressedTile = null;
                  cnt = 0;
                });
                print("Pressed Statuses3: ${_statuses}");
              });

              print("Unmatched");
            }
            print("Pressed Statuses4: ${_statuses}");
            return;
          }
          _pressedTileIndex = index;
          _pressedTile = text;
        });
  }

  @override
  Widget build(BuildContext context) {
    print("MyTableState.build");
    MediaQueryData media = MediaQuery.of(context);
    print(media);
    if (_isLoading) {
      return new SizedBox(
        width: 20.0,
        height: 20.0,
        child: new CircularProgressIndicator(),
      );
    }
    int j = 0;
    return new ResponsiveGridView(
      rows: _size,
      cols: _size,
      children: _letters
          .map((e) => _buildItem(j, e, _statuses[j], _shaker[j++]))
          .toList(growable: false),
    );
  }
}

class MyButton extends StatefulWidget {
  MyButton({Key key, this.text, this.status, this.shaker, this.onPress})
      : super(key: key);

  final String text;
  Status status;
  ShakeCell shaker;
  final VoidCallback onPress;

  @override
  _MyButtonState createState() => new _MyButtonState();
}

class _MyButtonState extends State<MyButton> with TickerProviderStateMixin {
  AnimationController controller, shakeController;
  Animation<double> animation, shakeAnimation;
  AnimationController flipController;
  String _displayText;

  initState() {
    super.initState();
    print("_MyButtonState.initState: ${widget.text}");
    _displayText = widget.text;
    controller = new AnimationController(duration: new Duration(milliseconds: 250), vsync: this);
    shakeController = new AnimationController(duration: new Duration(milliseconds: 40), vsync: this);
    flipController = new AnimationController(duration: new Duration(milliseconds: 250), vsync: this);
    animation = new CurvedAnimation(parent: controller, curve: Curves.easeIn)
      ..addStatusListener((state) {
        print("$state:${animation.value}");
        if (state == AnimationStatus.dismissed) {
          print('dismissed');
          if (widget.text != null) {
            setState(() => _displayText = widget.text);
            controller.forward();
          }
        }
      });
    controller.forward().then((f){flipController.reverse();});

    shakeAnimation = new Tween(begin: -6.0, end: 6.0).animate(shakeController);
    _myAnim();
  }

  void _myAnim() {
    shakeAnimation.addStatusListener((status) {
      if (status == AnimationStatus.completed) {
        shakeController.reverse();
      } else if (status == AnimationStatus.dismissed) {
        shakeController.forward();
      }
    });
    shakeController.forward();
  }

   @override
  void dispose() {
    shakeController.dispose();
    controller.dispose();
    super.dispose();
  }

  @override
  void didUpdateWidget(MyButton oldWidget) {
    print("Rajesh");
    super.didUpdateWidget(oldWidget);
    if (oldWidget.text == null && widget.text != null) {
        flipController.reverse();
       print("Rajesh1");
      _displayText = widget.text;
      controller.forward();
    } else if (oldWidget.text != widget.text) {
       print("Rajesh2");
      controller.reverse();
    } else {
       print("Rajesh3");
      if (oldWidget.status != widget.status) {
         print("Rajesh4");
        if (widget.status == Status.Visible) {
           print("Rajesh5");
          flipController.forward();
        } else {
           print("Rajesh6");
          flipController.reverse();
        }
      }
    }
    print("_MyButtonState.didUpdateWidget: ${widget.text} ${oldWidget.text}");
  }
 
  @override
  Widget build(BuildContext context) {

    print("_MyButtonState.build");
    return new Shake(
        animation:
            widget.shaker == ShakeCell.Wrong ? shakeAnimation : animation,
        child: new FlipAnimator(
            controller: flipController,
            front: new ScaleTransition(
                scale: animation,
                child: new RaisedButton(
                    onPressed: () => widget.onPress(),
                    padding: const EdgeInsets.all(8.0),
                    color: Colors.teal,
                    shape: new RoundedRectangleBorder(
                        borderRadius:
                            const BorderRadius.all(const Radius.circular(4.0))),
                    child: new Text(_displayText,
                        style: new TextStyle(
                            color: Colors.white, fontSize: 24.0)))),
            back: new RaisedButton(
                onPressed: () => widget.onPress(),
                padding: const EdgeInsets.all(8.0),
                color: Colors.teal,
                shape: new RoundedRectangleBorder(
                    borderRadius:
                        const BorderRadius.all(const Radius.circular(8.0))),
                child: new Text(' ',
                    style:
                        new TextStyle(color: Colors.teal, fontSize: 24.0)))));
  }
}

```
I am not sure if the problem lies with the Shake class or using the responsive grid because its been working fine in other games.

This is the flutter driver script that I am using for automating the test:

```
import 'dart:async';
import 'package:flutter_driver/flutter_driver.dart';
import 'package:test/test.dart';

const Duration kWaitBetweenActions = const Duration(milliseconds: 1000);

void main() {
  group('login', () {
    FlutterDriver driver;
    setUpAll(() async {
      driver = await FlutterDriver.connect();
    });

    tearDownAll(() async {
    if (driver != null)
      await driver.close();
     });

    test('task', () async {
      final SerializableFinder user = find.byValueKey('user-Chimple');
      await driver.tap(user);
      final SerializableFinder game = find.text('Game');
      await driver.tap(game);

      final SerializableFinder memory = find.byValueKey('memory');
      await driver.tap(memory);

      final SerializableFinder upc = find.text('Upper Case Letters');
      await driver.tap(upc);

      final SerializableFinder mode = find.byValueKey('single');
      await driver.tap(mode);
      
      final SerializableFinder index = find.byValueKey(0);
      await driver.tap(index);
    });
  });
}
```

## Logs
```

00:12 +0 -1: login task [E]
  DriverError: Error in Flutter application: Timeout while executing tap: TimeoutException after 0:00:05.000000: Future not completed
  #0      FlutterDriverExtension.call (package:flutter_driver/src/extension/extension.dart:168:31)
  <asynchronous suspension>
  #1      BindingBase.registerServiceExtension.<anonymous closure> (package:flutter/src/foundation/binding.dart:370:32)
  <asynchronous suspension>
  #2      _runExtension (dart:developer/runtime/libdeveloper.dart:85:23)
  #3      Widget.canUpdate (package:flutter/src/widgets/framework.dart:432:15)
  #4      Element.update (package:flutter/src/widgets/framework.dart:2745:19)
  #5      RenderObjectElement.update (package:flutter/src/widgets/framework.dart:4268:11)
  #6      SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4642:11)
  #7      Element.updateChild (package:flutter/src/widgets/framework.dart:2682:15)
  #8      SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4644:14)
  #9      Element.updateChild (package:flutter/src/widgets/framework.dart:2682:15)
  #10     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3636:16)
  #11     Element.rebuild (package:flutter/src/widgets/framework.dart:3478:5)
  #12     StatefulElement.update (package:flutter/src/widgets/framework.dart:3782:5)
  #13     Element.updateChild (package:flutter/src/widgets/framework.dart:2682:15)
  #14     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3636:16)
  #15     Element.rebuild (package:flutter/src/widgets/framework.dart:3478:5)
  #16     StatelessElement.update (package:flutter/src/widgets/framework.dart:3685:5)
  #17     Element.updateChild (package:flutter/src/widgets/framework.dart:2682:15)
  #18     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4644:14)
  #19     Element.updateChild (package:flutter/src/widgets/framework.dart:2682:15)
  #20     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4644:14)
  #21     Element.updateChild (package:flutter/src/widgets/framework.dart:2682:15)
  #22     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3636:16)
  #23     Element.rebuild (package:flutter/src/widgets/framework.dart:3478:5)
  #24     StatelessElement.update (package:flutter/src/widgets/framework.dart:3685:5)
  #25     Element.updateChild (package:flutter/src/widgets/framework.dart:2682:15)
  #26     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4644:14)
  #27     Element.updateChild (package:flutter/src/widgets/framework.dart:2682:15)
  #28     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3636:16)
  #29     Element.rebuild (package:flutter/src/widgets/framework.dart:3478:5)
  #30     StatefulElement.update (package:flutter/src/widgets/framework.dart:3782:5)
  #31     Element.updateChild (package:flutter/src/widgets/framework.dart:2682:15)
  #32     RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:4362:32)
  #33     MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4752:17)
  #34     Element.updateChild (package:flutter/src/widgets/framework.dart:2682:15)
  #35     _TheatreElement.update (package:flutter/src/widgets/overlay.dart:507:16)
  #36     Element.updateChild (package:flutter/src/widgets/framework.dart:2682:15)
  #37     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3636:16)
  #38     Element.rebuild (package:flutter/src/widgets/framework.dart:3478:5)
  #39     StatefulElement.update (package:flutter/src/widgets/framework.dart:3782:5)
  #40     Element.updateChild (package:flutter/src/widgets/framework.dart:2682:15)
  #41     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3636:16)
  #42     Element.rebuild (package:flutter/src/widgets/framework.dart:3478:5)
  #43     ProxyElement.update (package:flutter/src/widgets/framework.dart:3892:5)
  #44     Element.updateChild (package:flutter/src/widgets/framework.dart:2682:15)
  #45     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4644:14)
  #46     Element.updateChild (package:flutter/src/widgets/framework.dart:2682:15)
  #47     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3636:16)
  #48     Element.rebuild (package:flutter/src/widgets/framework.dart:3478:5)
  #49     StatefulElement.update (package:flutter/src/widgets/framework.dart:3782:5)
  #50     Element.updateChild (package:flutter/src/widgets/framework.dart:2682:15)
  #51     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4644:14)
  #52     Element.updateChild (package:flutter/src/widgets/framework.dart:2682:15)
  #53     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4644:14)
  #54     Element.updateChild (package:flutter/src/widgets/framework.dart:2682:15)
  #55     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3636:16)
  #56     Element.rebuild (package:flutter/src/widgets/framework.dart:3478:5)
  #57     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2225:33)
  #58     __DriverBinding&BindingBase&ServicesBinding&SchedulerBinding&GestureBinding&PaintingBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:621:20)
  #59     __DriverBinding&BindingBase&ServicesBinding&SchedulerBinding&GestureBinding&PaintingBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:208:5)
  #60     __DriverBinding&BindingBase&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
  #61     __DriverBinding&BindingBase&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9)
  #62     __DriverBinding&BindingBase&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:842:5)
  #63     _invoke (dart:ui/hooks.dart:120:13)
  #64     _drawFrame (dart:ui/hooks.dart:109:3)

  Original error: null
  Original stack trace:
  null

  package:flutter_driver/src/driver/driver.dart 342:7           FlutterDriver._sendCommand
  ===== asynchronous gap ===========================
  dart:async/future_impl.dart 22                                _Completer.completeError
  package:flutter_driver/src/driver/driver.dart                 FlutterDriver._sendCommand
  ===== asynchronous gap ===========================
  dart:async/zone.dart 1055                                     _CustomZone.registerUnaryCallback
  dart:async-patch/dart:async/async_patch.dart 77               _asyncThenWrapperHelper
  package:flutter_driver/src/driver/driver.dart 319:68          FlutterDriver._sendCommand
  package:flutter_driver/src/driver/driver.dart 368:11          FlutterDriver.tap
  ===== asynchronous gap ===========================
  dart:async/zone.dart 1047                                     _CustomZone.registerCallback
  dart:async/zone.dart 964                                      _CustomZone.bindCallbackGuarded
  dart:async/schedule_microtask.dart 147                        scheduleMicrotask
  dart:async/future.dart 198                                    new Future.microtask
  package:flutter_driver/src/driver/driver.dart 367:73          FlutterDriver.tap
  test_driver\mem_test.dart 36:20                               main.<fn>.<fn>
  ===== asynchronous gap ===========================
  dart:async/zone.dart 1055                                     _CustomZone.registerUnaryCallback
  dart:async-patch/dart:async/async_patch.dart 77               _asyncThenWrapperHelper
  test_driver\mem_test.dart 19:27                               main.<fn>.<fn>
  package:test/src/backend/declarer.dart 161:27                 Declarer.test.<fn>.<fn>.<fn>
  ===== asynchronous gap ===========================
  dart:async/zone.dart 1055                                     _CustomZone.registerUnaryCallback
  dart:async-patch/dart:async/async_patch.dart 77               _asyncThenWrapperHelper
  package:test/src/backend/declarer.dart 159:70                 Declarer.test.<fn>.<fn>.<fn>
  package:test/src/backend/invoker.dart 249:15                  Invoker.waitForOutstandingCallbacks.<fn>
  ===== asynchronous gap ===========================
  dart:async/zone.dart 1047                                     _CustomZone.registerCallback
  dart:async/zone.dart 964                                      _CustomZone.bindCallbackGuarded
  dart:async/schedule_microtask.dart 147                        scheduleMicrotask
  dart:async/future.dart 198                                    new Future.microtask
  package:test/src/backend/invoker.dart 246:23                  Invoker.waitForOutstandingCallbacks.<fn>
  dart:async/zone.dart 1126                                     _rootRun
  dart:async/zone.dart 1023                                     _CustomZone.run
  dart:async/zone.dart 1501                                     runZoned
  package:test/src/backend/invoker.dart 246:5                   Invoker.waitForOutstandingCallbacks
  package:test/src/backend/declarer.dart 159:33                 Declarer.test.<fn>.<fn>
  dart:async/zone.dart 1126                                     _rootRun
  dart:async/zone.dart 1023                                     _CustomZone.run
  dart:async/zone.dart 1501                                     runZoned
  package:test/src/backend/declarer.dart 158:13                 Declarer.test.<fn>
  ===== asynchronous gap ===========================
  dart:async/zone.dart 1047                                     _CustomZone.registerCallback
  dart:async/zone.dart 964                                      _CustomZone.bindCallbackGuarded
  dart:async/schedule_microtask.dart 147                        scheduleMicrotask
  dart:async/future.dart 198                                    new Future.microtask
  package:test/src/backend/declarer.dart 143:66                 Declarer.test.<fn>
  package:test/src/backend/invoker.dart 403:25                  Invoker._onRun.<fn>.<fn>.<fn>.<fn>
  ===== asynchronous gap ===========================
  dart:async/zone.dart 1047                                     _CustomZone.registerCallback
  dart:async/zone.dart 964                                      _CustomZone.bindCallbackGuarded
  dart:async/schedule_microtask.dart 147                        scheduleMicrotask
  dart:async/future.dart 198                                    new Future.microtask
  package:test/src/backend/invoker.dart 402:31                  Invoker._onRun.<fn>.<fn>.<fn>.<fn>
  dart:async/future.dart 174                                    new Future.<fn>
  package:stack_trace/src/stack_zone_specification.dart 209:15  StackZoneSpecification._run
  package:stack_trace/src/stack_zone_specification.dart 119:48  StackZoneSpecification._registerCallback.<fn>
  dart:async/zone.dart 1122                                     _rootRun
  dart:async/zone.dart 1023                                     _CustomZone.run
  dart:async/zone.dart 925                                      _CustomZone.runGuarded
  dart:async/zone.dart 965                                      _CustomZone.bindCallbackGuarded.<fn>
  package:stack_trace/src/stack_zone_specification.dart 209:15  StackZoneSpecification._run
  package:stack_trace/src/stack_zone_specification.dart 119:48  StackZoneSpecification._registerCallback.<fn>
  dart:async/zone.dart 1126                                     _rootRun
  dart:async/zone.dart 1023                                     _CustomZone.run
  dart:async/zone.dart 949                                      _CustomZone.bindCallback.<fn>
  dart:async-patch/dart:async/timer_patch.dart 21               Timer._createTimer.<fn>
  dart:isolate-patch/dart:isolate/timer_impl.dart 382           _Timer._runTimers
  dart:isolate-patch/dart:isolate/timer_impl.dart 416           _Timer._handleMessage
  dart:isolate-patch/dart:isolate/isolate_patch.dart 165        _RawReceivePortImpl._handleMessage
  ===== asynchronous gap ===========================
  dart:async/zone.dart 1047                                     _CustomZone.registerCallback
  dart:async/zone.dart 964                                      _CustomZone.bindCallbackGuarded
  dart:async/timer.dart 52                                      new Timer
  dart:async/timer.dart 87                                      Timer.run
  dart:async/future.dart 172                                    new Future
  package:test/src/backend/invoker.dart 402:15                  Invoker._onRun.<fn>.<fn>.<fn>
  ===== asynchronous gap ===========================
  dart:async/zone.dart 1047                                     _CustomZone.registerCallback
  dart:async/zone.dart 964                                      _CustomZone.bindCallbackGuarded
  dart:async/schedule_microtask.dart 147                        scheduleMicrotask
  dart:async/future.dart 198                                    new Future.microtask
  package:test/src/backend/invoker.dart 389:27                  Invoker._onRun.<fn>.<fn>.<fn>
  dart:async/zone.dart 1126                                     _rootRun
  dart:async/zone.dart 1023                                     _CustomZone.run
  dart:async/zone.dart 1501                                     runZoned
  package:test/src/backend/invoker.dart 389:9                   Invoker._onRun.<fn>.<fn>
  package:test/src/backend/invoker.dart 443:15                  Invoker._guardIfGuarded
  package:test/src/backend/invoker.dart 388:7                   Invoker._onRun.<fn>
  package:stack_trace/src/chain.dart 101:24                     Chain.capture.<fn>
  dart:async/zone.dart 1126                                     _rootRun
  dart:async/zone.dart 1023                                     _CustomZone.run
  dart:async/zone.dart 1501                                     runZoned
  package:stack_trace/src/chain.dart 99:12                      Chain.capture
  package:test/src/backend/invoker.dart 387:11                  Invoker._onRun
  package:test/src/backend/live_test_controller.dart 188:11     LiveTestController._run
  package:test/src/backend/live_test_controller.dart 40:31      _LiveTest.run
  dart:async/future.dart 200                                    new Future.microtask.<fn>
  dart:async/zone.dart 1122                                     _rootRun
  dart:async/zone.dart 1023                                     _CustomZone.run
  dart:async/zone.dart 925                                      _CustomZone.runGuarded
  dart:async/zone.dart 965                                      _CustomZone.bindCallbackGuarded.<fn>
  dart:async/zone.dart 1126                                     _rootRun
  dart:async/zone.dart 1023                                     _CustomZone.run
  dart:async/zone.dart 925                                      _CustomZone.runGuarded
  dart:async/zone.dart 965                                      _CustomZone.bindCallbackGuarded.<fn>
  dart:async/schedule_microtask.dart 41                         _microtaskLoop
  dart:async/schedule_microtask.dart 50                         _startMicrotaskLoop
  dart:isolate-patch/dart:isolate/timer_impl.dart 391           _Timer._runTimers
  dart:isolate-patch/dart:isolate/timer_impl.dart 416           _Timer._handleMessage
  dart:isolate-patch/dart:isolate/isolate_patch.dart 165        _RawReceivePortImpl._handleMessage

00:12 +0 -1: login (tearDownAll)
00:12 +0 -1: Some tests failed.

Unhandled exception:
Dummy exception to set exit code.
#0      _rootHandleUncaughtError.<anonymous closure> (dart:async/zone.dart:1114)
#1      _microtaskLoop (dart:async/schedule_microtask.dart:41)
#2      _startMicrotaskLoop (dart:async/schedule_microtask.dart:50)
#3      _Timer._runTimers (dart:isolate-patch/dart:isolate/timer_impl.dart:391)
#4      _Timer._handleMessage (dart:isolate-patch/dart:isolate/timer_impl.dart:416)
#5      _RawReceivePortImpl._handleMessage (dart:isolate-patch/dart:isolate/isolate_patch.dart:165)
Stopping application instance.
I/FlutterActivityDelegate( 4749): onResume setting current activity to this
Driver tests failed: 255

```