user21172488
user21172488

Reputation:

Missing selector such as '.identifier' or '[0]'. TapGestureRecognizer

Code:

final tapRecognizer = TapGestureRecognizer()
    ..onTap!() = () =>
        AppGlobalFunctions().openExternalLink("https://xxxxxx.xxx");

Error log:

Launching lib/main.dart on Redmi Note 7 Pro in debug mode...
Running Gradle task 'assembleDebug'...
lib/modules/auth/phone_auth/phone_auth.dart:15:16: Error: Can't assign to this.
    ..onTap!() = () =>
               ^
Target kernel_snapshot failed: Exception


FAILURE: Build failed with an exception.

* Where:
Script '/Users/udit/Downloads/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 1201

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/Users/udit/Downloads/flutter/bin/flutter'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 6s
Exception: Gradle task assembleDebug failed with exit code 1

How to duplicate:

  1. Create new flutter project

  2. Copy final tapRecognizer = TapGestureRecognizer() ..onTap!() = () => debugPrint("Hello world"); and paste code in _MyHomePageState

  3. import 'package:flutter/gestures.dart' import 'package:flutter/gestures.dart';

  4. run project

Upvotes: 0

Views: 141

Answers (2)

Vivek Singh
Vivek Singh

Reputation: 21

onTap does not need function annotation (), remove () will make the code work

final tapRecognizer = TapGestureRecognizer() ..onTap = () => print("Message");

Upvotes: 1

Ildeberto Vasconcelos
Ildeberto Vasconcelos

Reputation: 1050

i think you want to assigning the OpenExternaLink function to the tapRecognizer

so do it like this:

  final tapRecognizer = TapGestureRecognizer()
      ..onTap = () =>
          AppGlobalFunctions().openExternalLink("https://xxxxxx.xxx");

Upvotes: 1

Related Questions