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

Issue when using super_context_menu with flutter_markdown as a child #389

Open
mjurfest opened this issue Jun 17, 2024 · 6 comments
Open

Comments

@mjurfest
Copy link

I am using flutter_markdown (which is an official package) on a widget that also uses super_context_menu, it happens that using super_context_menu brakes the tappable links defined by flutter_markdown and
It looks like a bug.

Sample code combining the two pacakges:

ContextMenu(
  items: getContextMenuItems(),
  childElement: MarkdownBody(
    data: 'content',
    onTapLink: (text, href, title) {
      // It's never called
    },
  );
);
@mjurfest mjurfest changed the title Issue when using with flutter_markdown Issue when using super_context_menu with flutter_markdown as a child Jun 17, 2024
@knopp
Copy link
Collaborator

knopp commented Jun 17, 2024

Which platform does this happen on?

@mjurfest
Copy link
Author

mjurfest commented Jun 18, 2024

iOS, I didn't test it on Android.

@mjurfest
Copy link
Author

@knopp this issue is preventing me from using the package, if you can please take a look

@knopp
Copy link
Collaborator

knopp commented Jun 20, 2024

This is a bug in FlutterMarkdown. For some reason they destroy the gesture recognizer inside didChangeDependencies, but that method is also called during reparent when the state is preserved. Simple example to reproduce:

class _BaseContextMenu extends StatefulWidget {
  @override
  State<_BaseContextMenu> createState() => _BaseContextMenuState();
}

class _BaseContextMenuState extends State<_BaseContextMenu> {
  bool pointerDown = false;
  final key = GlobalKey();

  @override
  Widget build(BuildContext context) {
    final child = MarkdownBody(
      key: key,
      data: 'What is this [content](https://example.com)',
      onTapLink: (text, _, __) {
        print('Clicked on $text');
      },
    );
    return Listener(
      onPointerDown: (event) {
        setState(() {
          pointerDown = true;
        });
      },
      onPointerUp: (event) {
        setState(() {
          pointerDown = false;
        });
      },
      child: pointerDown
          ? ColoredBox(
              color: Colors.green,
              child: child,
            )
          : child,
    );
  }
}

@knopp
Copy link
Collaborator

knopp commented Jun 20, 2024

Reported the issue here: flutter/flutter#150558

@mjurfest
Copy link
Author

mjurfest commented Jun 20, 2024

Thanks @knopp.
If somebody gets to this issue i changed flutter_markdown for markdown_widget and everything works fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants