Skip to content

WidgetTester tap is recognized as longPress by GoogleMap #169501

Open
@mariusturftank

Description

@mariusturftank

Steps to reproduce

  1. Create integration test in google_maps_flutter_android/example
  2. Add onTap callback on the ExampleGoogleMap
  3. Use the WidgetTester instance to call tap i.e. tester.tap(find.byKey(myGoogleMapKey))
  4. See that this tap was not recognized

Expected results

I expect that when I use .tap from WidgetTester on my GoogleMap widget that the onTap callback is called.

Actual results

What I see is that the onLongPress callback is called.

Code sample

Code sample
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:google_maps_flutter_example/example_google_map.dart';
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';

void main() {
  testWidgets('onTap', (WidgetTester tester) async {
    final Key key = GlobalKey();
    final Completer<int> mapIdCompleter = Completer<int>();
    bool hasTapped = false;
    await tester.pumpWidget(Directionality(
      textDirection: TextDirection.ltr,
      child: ExampleGoogleMap(
        key: key,
        onTap: (LatLng position) {
          print('Tapped at: $position');
          hasTapped = true;
        },
        onLongPress: (LatLng position) => print('Long pressed at: $position'),
        initialCameraPosition: const CameraPosition(
          target: LatLng(0, 0),
          zoom: 5,
        ),
        onMapCreated: (ExampleGoogleMapController controller) {
          mapIdCompleter.complete(controller.mapId);
        },
      ),
    ));

    final int mapsId = await mapIdCompleter.future;
    await tester.tap(find.byKey(key));

    expect(mapsId, 0);
    expect(hasTapped, isTrue, reason: 'onTap callback should be called when the map is tapped.');
  });
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.29.0, on Linux Mint 22.1 6.8.0-51-generic, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[!] Android Studio (not installed)
[✓] VS Code (version 1.99.3)
[✓] Connected device (3 available)
[✓] Network resources

! Doctor found issues in 1 category.

This was tested with a Galaxy Tab Active5

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: platform-viewsEmbedding Android/iOS views in Flutter appsa: tests"flutter test", flutter_test, or one of our testsfound in release: 3.32Found to occur in 3.32found in release: 3.33Found to occur in 3.33frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: mapsGoogle Maps pluginpackageflutter/packages repository. See also p: labels.platform-androidAndroid applications specificallyteam-androidOwned by Android platform teamtriaged-androidTriaged by Android platform team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions