Sub6Resources / flutter_html

A Flutter widget for rendering static html as Flutter widgets (Will render over 80 different html tags!)
https://pub.dev/packages/flutter_html
MIT License
1.79k stars 860 forks source link

[BUG]onLinkTap works, but onImageTap didn't work, please help! #1143

Closed primeNathanLin closed 2 years ago

primeNathanLin commented 2 years ago
@override
  Widget build(BuildContext context) {
    return Consumer<CompanyInfoProvider>(builder: (BuildContext context,
        CompanyInfoProvider companyInfoProvider, Widget? child) {
      CompanyInfo? companyInfo = companyInfoProvider.companyInfo;
      final options = [
        "新闻中心",
        "武林人物",
        "活动照片",
        "拳社介绍",
        "招生简章",
        "师资介绍",
        "报名缴费",
        "联系我们",
        "拳社通知",
        "付费内容",
      ];
      if (companyInfo != null && isLoaded) {
return Scaffold(
          appBar: AppBar(
            title: Text(options[int.parse(companyInfo.type!)]),
          ),
          body: ListView(
            children: <Widget>[
              Html(
                // data: companyInfo.articleDetail.toString(),
                data:
                    """<a href='https://baidu.com'>123456</a><img alt='Google' src='https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png' />""",
                onImageTap: (url, context, attributes, ____) {
                  print('i am image');
                },
                style: {
                  "span": Style(padding: const EdgeInsets.only(left: 20.0))
                },
                onImageError: (_, __) {
                  print('error');
                },
                onLinkTap: (_, __, ___, ____) {
                  print('i am here');
                },
              ),
            ],
          ),
        );
}

Above is the code, I am not sure why onImageTap not working? Please help! Thanks in advance! Nathan

Describe the bug:

HTML to reproduce the issue:

Html widget configuration:

Expected behavior:

Screenshots:

Device details and Flutter/Dart/flutter_html versions:

Stacktrace/Logcat

Additional info:

A picture of a cute animal (not mandatory but encouraged)

Sub6Resources commented 2 years ago

Which version of the flutter_html widget are you using?

primeNathanLin commented 2 years ago

I was using 2.2.1, the problem has been solved after I changed to version 3.0.0-alpha.5 and reference the sample code. @Sub6Resources Thank you very much for quicky reply!