Skip to content

Link widget not working from keyboard on web #97863

Closed
flutter/packages
#6505

Description

@Leffe108

Steps to Reproduce

  1. flutter create bug_link
  2. flutter pub add url_launcher (as of writing this, it adds version 6.0.18 of url_launcher)
  3. replace main.dart with sample code
  4. flutter run -d chrome
  5. Use TAB key to navigate and then SPACE or ENTER to trigger the buttons

You notice that the first button that is not built using Link widget will open https://flutter.dev in a new tab. But the second button does nothing when you use the SPACE or ENTER key on your keyboard.

Expected results:
I expect that both buttons works the same when navigating the app on keyboard.

Actual results:
The button that uses Link widget does not work to "tap" using keyboard.

Sample code - main.dart
import 'package:flutter/material.dart';
import 'package:url_launcher/link.dart';
import 'package:url_launcher/url_launcher.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  static const url = 'https://flutter.dev';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Link'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            ElevatedButton(
              onPressed: () {
                launch(url);
              },
              child: const Text('Button without Link'),
            ),
            Container(height: 20),
            Link(
              uri: Uri.parse(url),
              target: LinkTarget.blank,
              builder: (context, followLink) => ElevatedButton(
                child: const Text('Button with Link'),
                onPressed: followLink!,
              ),
            ),
          ],
        ),
      ),
    );
  }
}
Logs
flutter analyze
Analyzing bug_link...
No issues found! (ran in 3.8s)
flutter doctor -v
[✓] Flutter (Channel stable, 2.10.0, on Microsoft Windows [Version 10.0.19044.1466], locale sv-SE)
    • Flutter version 2.10.0 at C:\Users\Leif\Programmering\Libraries\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5f105a6ca7 (4 days ago), 2022-02-01 14:15:42 -0800
    • Engine revision 776efd2034
    • Dart version 2.16.0
    • DevTools version 2.9.2

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

[✓] VS Code, 32-bit edition (version 1.61.2)
    • VS Code at C:\Program Files (x86)\Microsoft VS Code
    • Flutter extension version 3.29.0

[✓] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.19044.1466]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 97.0.4692.99
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 97.0.1072.69

[✓] HTTP Host Availability
    • All required HTTP hosts are available

bild

bug_link.mp4

Framework code

I did lookup the implementation of the Link widget and see that the followLink() method only registers a binding that is then used when onClick event of the A tag is getting called. So there is probably missing event handlers for keyboard triggering of the link.

Activity

  1. darshankawar commented on Feb 7, 2022

    @darshankawar
    Member

    @Leffe108
    Verified this on latest stable and master and confirmed that this behavior occurs only on web, as on desktop (tried on macOS), the link open properly after tapping from keyboard as expected, but, on web (using both renderers), tab focussed on Button with link button and then hit return from keyboard, but doesn't perform any action.

    stable, master flutter doctor -v
    
    [✓] Flutter (Channel stable, 2.10.0, on Mac OS X 10.15.4 19E2269 darwin-x64,
        locale en-GB)
        • Flutter version 2.10.0 at /Users/dhs/documents/fluttersdk/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 5f105a6ca7 (2 days ago), 2022-02-01 14:15:42 -0800
        • Engine revision 776efd2034
        • Dart version 2.16.0
        • DevTools version 2.9.2
    
    [!] Xcode - develop for iOS and macOS (Xcode 12.3)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        ! Flutter recommends a minimum Xcode version of 13.
          Download the latest version or update via the Mac App Store.
        • CocoaPods version 1.11.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] VS Code (version 1.62.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.21.0
    
    [✓] Connected device (2 available)
        • macOS (desktop) • macos  • darwin-x64     • Mac OS X 10.15.4 19E2269
          darwin-x64
        • Chrome (web)    • chrome • web-javascript • Google Chrome 97.0.4692.99
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    ! Doctor found issues in 1 category.
    
    [✓] Flutter (Channel master, 2.11.0-0.0.pre.452, on Mac OS X 10.15.4 19E2269
        darwin-x64, locale en-GB)
        • Flutter version 2.11.0-0.0.pre.452 at
          /Users/dhs/documents/fluttersdk/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision ba01ec8faa (27 hours ago), 2022-02-05 22:05:18 -0500
        • Engine revision 0712096899
        • Dart version 2.17.0 (build 2.17.0-85.0.dev)
        • DevTools version 2.10.0
    
    [!] Xcode - develop for iOS and macOS (Xcode 12.3)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        ! Flutter recommends a minimum Xcode version of 13.
          Download the latest version or update via the Mac App Store.
        • CocoaPods version 1.11.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] VS Code (version 1.62.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.21.0
    
    [✓] Connected device (3 available)
        • Darshan's iphone (mobile) • 21150b119064aecc249dfcfe05e259197461ce23 • ios
          • iOS 14.4.1 18D61
        • macOS (desktop)           • macos                                    •
          darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
        • Chrome (web)              • chrome                                   •
          web-javascript • Google Chrome 97.0.4692.99
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    ! Doctor found issues in 1 category.
    
    
  2. added
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    p: url_launcherPlugin to launch external applications
    platform-webWeb applications specifically
    and removed
    in triagePresently being triaged by the triage team
    on Feb 7, 2022
  3. added
    P2Important issues not at the top of the work list
    on Feb 10, 2022
  4. self-assigned this
    on Feb 10, 2022
  5. ditman commented on Jun 4, 2022

    @ditman
    Member

    I can repro this in the latest Flutter from master (we pushed a fix that improved accessibility of platform views, but it didn't do the trick for this one). I'll follow up with @mdebbar for next steps! Thanks for the report!

  6. removed their assignment
    on Oct 19, 2022
  7. 12 remaining items

  8. self-assigned this
    on Apr 4, 2024
  9. added
    P1High-priority issues at the top of the work list
    and removed
    P2Important issues not at the top of the work list
    on Apr 4, 2024
  10. added
    r: fixedIssue is closed as already fixed in a newer version
    on Apr 16, 2024
  11. github-actions commented on Apr 30, 2024

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  12. locked as resolved and limited conversation to collaborators on Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work listfound in release: 3.10Found to occur in 3.10found in release: 3.11Found to occur in 3.11has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: url_launcherPlugin to launch external applicationspackageflutter/packages repository. See also p: labels.platform-webWeb applications specificallyr: fixedIssue is closed as already fixed in a newer versionteam-webOwned by Web platform teamtriaged-webTriaged by Web platform team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions