Skip to content

OnTap of Listtile in Overlay dosen't work with Flutter web #55449

@skowrons

Description

@skowrons

Code

The following code is after a tutorial from medium:
https://medium.com/saugo360/https-medium-com-saugo360-flutter-using-overlay-to-display-floating-widgets-2e6d0e8decb9

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Padding(
        padding: const EdgeInsets.all(50.0),
        child: Form(
          child: ListView(
            children: <Widget>[
              CountriesField(),
              SizedBox(
                height: 16.0,
              ),
              RaisedButton(
                child: Text('SUBMIT'),
                onPressed: () {
                  // submit the form
                },
              )
            ],
          ),
        ),
      ),
    );
  }
}

class CountriesField extends StatefulWidget {
  @override
  _CountriesFieldState createState() => _CountriesFieldState();
}

class _CountriesFieldState extends State<CountriesField> {
  final FocusNode _focusNode = FocusNode();

  OverlayEntry _overlayEntry;

  @override
  void initState() {
    _focusNode.addListener(() {
      if (_focusNode.hasFocus) {
        this._overlayEntry = this._createOverlayEntry();
        Overlay.of(context).insert(this._overlayEntry);
      } else {
        this._overlayEntry.remove();
      }
    });
  }

  OverlayEntry _createOverlayEntry() {
    RenderBox renderBox = context.findRenderObject();
    var size = renderBox.size;
    var offset = renderBox.localToGlobal(Offset.zero);

    return OverlayEntry(
        builder: (context) => Positioned(
              left: offset.dx,
              top: offset.dy + size.height + 5.0,
              width: size.width,
              child: Material(
                elevation: 4.0,
                child: ListView(
                  padding: EdgeInsets.zero,
                  shrinkWrap: true,
                  children: <Widget>[
                    ListTile(
                      onTap: () {
                        print('Syria');
                      },
                      title: Text('Syria'),
                    ),
                    ListTile(
                      onTap: () {
                        print('Lebanon');
                      },
                      title: Text('Lebanon'),
                    )
                  ],
                ),
              ),
            ));
  }

  @override
  Widget build(BuildContext context) {
    return TextFormField(
      focusNode: this._focusNode,
      decoration: InputDecoration(labelText: 'Country'),
    );
  }
}

Steps to Reproduce

We use Flutter beta channel.

Expected results:
When you tab or click on one Listtile it should execute whatever is within the onTap function. After that the overlay should removed.

Actual results:
When you build the app for Android it works as described. But if you run the same code with Flutter web it dosen't work. When you click the Tile no onTap code is executet. Only the overlay will removed.

Logs
flutter run --verbose -d chrome
[  +15 ms] executing: [C:\Users\maxsk\flutter/] git -c log.showSignature=false log -n 1 --pretty=format:%H
[  +48 ms] Exit code 0 from: git -c log.showSignature=false log -n 1 --pretty=format:%H
[        ] d3ed9ec945f8869f0e136c357d0c2a6be2b60c98
[        ] executing: [C:\Users\maxsk\flutter/] git describe --match *.*.* --first-parent --long --tags
[  +46 ms] Exit code 0 from: git describe --match *.*.* --first-parent --long --tags
[        ] 1.17.0-dev.3.1-0-gd3ed9ec945
[   +8 ms] executing: [C:\Users\maxsk\flutter/] git rev-parse --abbrev-ref --symbolic @{u}
[  +27 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u}
[        ] origin/beta
[        ] executing: [C:\Users\maxsk\flutter/] git ls-remote --get-url origin
[  +22 ms] Exit code 0 from: git ls-remote --get-url origin
[        ] https://github.com/flutter/flutter.git
[  +70 ms] executing: [C:\Users\maxsk\flutter/] git rev-parse --abbrev-ref HEAD
[  +24 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD
[        ] beta
[  +30 ms] Artifact Instance of 'AndroidMavenArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.  
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[   +2 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.       
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.     
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[  +12 ms] executing: C:\Users\maxsk\AppData\Local\Android\sdk\platform-tools\adb.exe devices -l
[  +28 ms] List of devices attached
[   +4 ms] Artifact Instance of 'AndroidMavenArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[   +2 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[ +138 ms] Generating
D:\Projecte\ovtest\android\app\src\main\java\io\flutter\plugins\GeneratedPluginRegistrant.java
[  +72 ms] Launching lib\main.dart on Chrome in debug mode...
[  +52 ms] Updating assets
[ +130 ms] Syncing files to device Chrome...
[  +34 ms] Generating
D:\Projecte\ovtest\android\app\src\main\java\io\flutter\plugins\GeneratedPluginRegistrant.java
[+1638 ms] <- reset
[   +7 ms] C:\Users\maxsk\flutter\bin\cache\dart-sdk\bin\dart.exe
C:\Users\maxsk\flutter\bin\cache\artifacts\engine\windows-x64\frontend_server.dart.snapshot --sdk-root
C:\Users\maxsk\flutter\bin\cache\flutter_web_sdk/ --incremental --target=dartdevc --debugger-module-names        
-Ddart.developer.causal_async_stacks=true --output-dill
C:\Users\maxsk\AppData\Local\Temp\flutter_tool.f0fd35cf-8546-11ea-8ea7-94b86de443e2\app.dill --libraries-spec    
file:///C:/Users/maxsk/flutter/bin/cache/flutter_web_sdk/libraries.json --packages D:\Projecte\ovtest\.packages  
-Ddart.vm.profile=false -Ddart.vm.product=false
--bytecode-options=source-positions,local-var-info,debugger-stops,instance-field-initializers,keep-unreachable-code,avoid-closure-call-instructions --enable-asserts --track-widget-creation --filesystem-root
C:\Users\maxsk\AppData\Local\Temp\flutter_tools.f0fd35d0-8546-11ea-8ea7-94b86de443e2 --filesystem-scheme
org-dartlang-app --initialize-from-dill build\cache.dill --platform
file:///C:/Users/maxsk/flutter/bin/cache/flutter_web_sdk/kernel/flutter_ddc_sdk.dill
[  +12 ms] <- compile org-dartlang-app:///web_entrypoint.dart
[+10948 ms] Syncing files to device Chrome... (completed in 12.635ms, longer than expected)
[   +1 ms] Synced 21.2MB.
[  +13 ms] <- accept
[ +149 ms] [CHROME]:
[   +1 ms] [CHROME]:DevTools listening on
ws://127.0.0.1:57432/devtools/browser/a80f6237-0193-4dc4-a083-99635e46d147
[+3934 ms] Debug service listening on ws://127.0.0.1:57465/239TCRsZFWY=

[ +178 ms] Debug service listening on ws://127.0.0.1:57465/239TCRsZFWY=
[   +2 ms] Warning: Flutter's support for web development is not stable yet and hasn't
[  +12 ms] been thoroughly tested in production environments.
[   +1 ms] For more information see https://flutter.dev/web
[   +2 ms]   To hot restart changes while running, press "r". To hot restart (and refresh the browser), press    
"R".
[   +1 ms] For a more detailed help message, press "h". To quit, press "q".
flutter analyze
Analyzing ovtest...

   info - This method overrides a method annotated as '@mustCallSuper' in 'State', but doesn't invoke the        
          overridden method - lib\main.dart:68:8 - must_call_super

1 issue found. (ran in 1.5s)
flutter doctor -v 
[√] Flutter (Channel beta, v1.17.0, on Microsoft Windows [Version 10.0.18362.720], locale de-DE)
    • Flutter version 1.17.0 at C:\Users\maxsk\flutter
    • Framework revision d3ed9ec945 (2 weeks ago), 2020-04-06 14:07:34 -0700
    • Engine revision c9506cb8e9
    • Dart version 2.8.0 (build 2.8.0-dev.18.0 eea9717938)


[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at C:\Users\maxsk\AppData\Local\Android\sdk
    • Platform android-29, build-tools 28.0.3
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Android Studio (version 3.4)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 35.3.1
    • Dart plugin version 183.6270
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)

[√] VS Code (version 1.44.2)
    • VS Code at C:\Users\maxsk\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.9.1

[√] Connected device (2 available)
    • Chrome     • chrome     • web-javascript • Google Chrome 81.0.4044.122
    • Web Server • web-server • web-javascript • Flutter Tools

• No issues found!

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work listf: gesturesflutter/packages/flutter/gestures repository.found in release: 1.17Found to occur in 1.17found in release: 1.18Occurs in 1.18frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-webWeb applications specifically

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions