Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link widget breaks when ensureSemantics is enabled #143164

Open
johnpryan opened this issue Feb 8, 2024 · 3 comments · May be fixed by flutter/packages#6579
Open

Link widget breaks when ensureSemantics is enabled #143164

johnpryan opened this issue Feb 8, 2024 · 3 comments · May be fixed by flutter/packages#6579
Assignees
Labels
a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) P1 High-priority issues at the top of the work list platform-web Web applications specifically team-web Owned by Web platform team triaged-web Triaged by Web platform team

Comments

@johnpryan
Copy link
Contributor

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
@johnpryan johnpryan added the platform-web Web applications specifically label Feb 8, 2024
@johnpryan
Copy link
Contributor Author

johnpryan commented Feb 8, 2024

cc: @mdebbar @yjbanov

@yjbanov yjbanov added a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) P1 High-priority issues at the top of the work list team-web Owned by Web platform team triaged-web Triaged by Web platform team labels Feb 8, 2024
@yjbanov yjbanov added P2 Important issues not at the top of the work list and removed P1 High-priority issues at the top of the work list labels Feb 22, 2024
@emma-roudabush-disney
Copy link

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

@ss1565
Copy link

ss1565 commented Mar 14, 2024

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

@htoor3 htoor3 self-assigned this Apr 17, 2024
@htoor3 htoor3 added P1 High-priority issues at the top of the work list and removed P2 Important issues not at the top of the work list labels Apr 17, 2024
@tvolkert tvolkert assigned yjbanov and unassigned htoor3 Apr 30, 2024
@yjbanov yjbanov assigned mdebbar and unassigned yjbanov May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) P1 High-priority issues at the top of the work list platform-web Web applications specifically team-web Owned by Web platform team triaged-web Triaged by Web platform team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants