Skip to content

[web:a11y] Link widget breaks when ensureSemantics is enabled #143164

Closed
flutter/packages
#6711

Description

@johnpryan

Enabling semantics using SemanticsBinding.instance.ensureSemantics() causes the Link widget to break.

Steps to reproduce

  1. Create a new Flutter project and copy the contents below
  2. Run the app in Chrome and observe that the link doesn't work
  3. Comment out SemanticsBinding.instance.ensureSemantics(), re-run and observe that the link now works.
Code snippet

main.dart:

import 'package:flutter/material.dart';
import 'package:flutter/semantics.dart';
import 'package:go_router/go_router.dart';
import 'package:url_launcher/link.dart';
import 'package:flutter_web_plugins/url_strategy.dart';


void main() {
  usePathUrlStrategy();
  runApp(const MyApp());
  SemanticsBinding.instance.ensureSemantics();
}

final GoRouter _router = GoRouter(
  routes: <RouteBase>[
    GoRoute(
      path: '/',
      builder: (BuildContext context, GoRouterState state) {
        return const HomeScreen();
      },
      routes: <RouteBase>[
        GoRoute(
          path: 'details-screen',
          builder: (BuildContext context, GoRouterState state) {
            return const DetailsScreen();
          },
        ),
      ],
    ),
  ],
);

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      routerConfig: _router,
    );
  }
}

class HomeScreen extends StatelessWidget {
  const HomeScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Home Screen')),
      body: Center(
        child: Link(
          builder: (context, followLink) {
            return ElevatedButton(
              onPressed: followLink,
              child: const Text('Go to the Details screen'),
            );
          },
          uri: Uri.parse('/details-screen'),
        ),
      ),
    );
  }
}

class DetailsScreen extends StatelessWidget {
  const DetailsScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Details Screen')),
      body: Center(
        child: ElevatedButton(
          onPressed: () => context.go('/'),
          child: const Text('Go back to the Home screen'),
        ),
      ),
    );
  }
}

pubspec.yaml

name: link_widget_bug
description: "A new Flutter project."
publish_to: 'none'
version: 0.1.0

environment:
  sdk: '>=3.4.0-82.0.dev <4.0.0'

dependencies:
  flutter:
    sdk: flutter
  flutter_web_plugins:
    sdk: flutter
  go_router: any
  url_launcher: any

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^3.0.0

flutter:
  uses-material-design: true

Activity

  1. johnpryan commented on Feb 8, 2024

    @johnpryan
    ContributorAuthor
  2. added
    a: accessibilityAccessibility, e.g. VoiceOver or TalkBack. (aka a11y)
    P1High-priority issues at the top of the work list
    team-webOwned by Web platform team
    triaged-webTriaged by Web platform team
    on Feb 8, 2024
  3. added
    P2Important issues not at the top of the work list
    and removed
    P1High-priority issues at the top of the work list
    on Feb 22, 2024
  4. emma-roudabush-disney commented on Mar 4, 2024

    @emma-roudabush-disney

    I am also seeing this issue--we lose all link preview and context menu options

  5. ss1565 commented on Mar 14, 2024

    @ss1565

    I am also seeing this issue. When is this going to be fixed?

  6. self-assigned this
    on Apr 17, 2024
  7. 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 17, 2024
  8. assigned and unassigned on Apr 30, 2024
  9. assigned and unassigned on May 9, 2024
  10. pedromassango commented on Aug 19, 2024

    @pedromassango
    Member

    This is still happing

  11. changed the title [-]Link widget breaks when ensureSemantics is enabled[/-] [+][web:a11y] Link widget breaks when ensureSemantics is enabled[/+] on Oct 7, 2024
  12. github-actions commented on Jan 24, 2025

    @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.

  13. locked as resolved and limited conversation to collaborators on Jan 24, 2025
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 lista: accessibilityAccessibility, e.g. VoiceOver or TalkBack. (aka a11y)customer: castawayplatform-webWeb applications specificallyteam-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