2000calories / flutter_easy_rich_text

The EasyRichText widget provides an easy way to use RichText.
https://pub.dev/packages/easy_rich_text
MIT License
79 stars 34 forks source link

[Issue] GestureRecognizer never fired #46

Closed Paroca72 closed 12 months ago

Paroca72 commented 1 year ago

Hello,

Here my code:

class TemplateListTile extends StatelessWidget {
  final TemplateCell cell;
  final String? Function(String text)? onReplace;

  TemplateListTile({
    super.key,
    required this.cell,
    this.onReplace,
  });

  final EasyRichTextPattern correct = EasyRichTextPattern(
    targetString: r"(\*)(.*?)(\*)",
    matchWordBoundaries: false,
    matchBuilder: (context, match) {
      return TextSpan(
        text: match?[0]?.replaceAll("*", ""),
        style: const TextStyle(
          color: ThemesManager.templateTextHighLightColor,
          fontWeight: FontWeight.bold,
        ),
      );
    },
  );

  final EasyRichTextPattern missing = EasyRichTextPattern(
    targetString: r"#\b\w+\b",
    matchWordBoundaries: false,
    style: const TextStyle(
      color: ThemesManager.templateErrorColor,
      fontWeight: FontWeight.bold,
    ),
    recognizer: TapGestureRecognizer()..onTap = () {
      ...
    },
  );

  @override
  Widget build(BuildContext context) => EasyRichText(
        cell.compile(true, onReplace),
        textAlign: cell.alignment,
        defaultStyle: TextStyle(
          color: ThemesManager.templateRowColor,
          fontSize: cell.isIncreased ? null : ThemesManager.labelSizeSmall,
          fontWeight: cell.isBold ? FontWeight.bold : null,
          fontStyle: cell.isItalic ? FontStyle.italic : null,
        ),
        patternList: [
          correct,
          missing,
        ],
      );
}

I'm using the TemplateListTile inside a ListView. Both the patterns are proper drawn. In the "missing" pattern the tap is never called.

Also there is a way to have, on tap, the word that is matched?

Very thanks for your support and fantastic plugin. Sam

2000calories commented 1 year ago

In the "missing" pattern the tap is never called. you mean the style of the "missing" pattern is working but the onTap in recognizer not working?

final EasyRichTextPattern missing = EasyRichTextPattern(
    targetString: r"#\b\w+\b",
    matchWordBoundaries: false,
    style: const TextStyle(
      color: ThemesManager.templateErrorColor,
      fontWeight: FontWeight.bold,
    ),
    recognizer: TapGestureRecognizer()..onTap = () {
      print("tap missing")
    },
  );
2000calories commented 1 year ago

I just tested it. It works fine for me. Please provide fluttter doctor output.

Paroca72 commented 1 year ago

Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, 3.13.4, on Microsoft Windows [Version 10.0.22621.2283], locale en-US) [√] Windows Version (Installed version of Windows is version 10 or higher) [√] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [√] Chrome - develop for the web [!] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.7.3) X Visual Studio is missing necessary components. Please re-run the Visual Studio installer for the "Desktop development with C++" workload, and include these components: MSVC v142 - VS 2019 C++ x64/x86 build tools

! Doctor found issues in 1 category.

Paroca72 commented 1 year ago

If for you its working probably is something inside my code. I'll investigate better.

Thanks for your time

2000calories commented 1 year ago

I use a lower version of flutter. I will check it on 3.13.4.

2000calories commented 1 year ago

the onTap function works on my demo. Maybe there is a conflict between different widgets' TapGestureRecognizer.

Paroca72 commented 12 months ago

Hello.. finally I got some free time to take a look to this issue. It seems the problem was the sortable ListView.

Very thanks for your support.