Skip to content

Link widget not working from keyboard on web #97863

@Leffe108

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.

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