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

<a> tag is not working #147

Closed
gabrielhernandez3333 opened this issue Aug 24, 2019 · 9 comments · Fixed by #122
Closed

<a> tag is not working #147

gabrielhernandez3333 opened this issue Aug 24, 2019 · 9 comments · Fixed by #122
Labels
bug Something isn't working
Milestone

Comments

@gabrielhernandez3333
Copy link

gabrielhernandez3333 commented Aug 24, 2019

the tag i am using for testing is the following one:

<a href="https://google.com" class="btn btn-alpha btn-sm" data-original-title="" title="">Esto es una prueba</a>

When I click on the tag in the rendered view it throws the following error:

══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
I/flutter ( 9586): The following NoSuchMethodError was thrown while handling a gesture:
I/flutter ( 9586): The method 'call' was called on null.
I/flutter ( 9586): Receiver: null
I/flutter ( 9586): Tried calling: call()
I/flutter ( 9586): 
I/flutter ( 9586): When the exception was thrown, this was the stack:
I/flutter ( 9586): #0      new LinkTextSpan.<anonymous closure> (package:flutter_html/rich_text_parser.dart:50:24)
I/flutter ( 9586): #1      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
I/flutter ( 9586): #2      TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:365:11)
I/flutter ( 9586): #3      TapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:312:7)
I/flutter ( 9586): #4      GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27)
I/flutter ( 9586): #5      _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:222:20)
I/flutter ( 9586): #6      _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
I/flutter ( 9586): #7      _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
I/flutter ( 9586): #8      _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
I/flutter ( 9586): #9      _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
I/flutter ( 9586): #13     _invoke1 (dart:ui/hooks.dart:250:10)
I/flutter ( 9586): #14     _dispatchPointerDataPacket (dart:ui/hooks.dart:159:5)
I/flutter ( 9586): (elided 3 frames from package dart:async)
I/flutter ( 9586): 
I/flutter ( 9586): Handler: "onTap"
I/flutter ( 9586): Recognizer:
I/flutter ( 9586):   TapGestureRecognizer#84a5d
I/flutter ( 9586): ════════════════════════════════════════════════════════════════════════════════════════════════════
@The-Redhat
Copy link
Contributor

The-Redhat commented Aug 26, 2019

Hey can you please post your Html Widget. Is onLinkTap implemented ?

@gabrielhernandez3333
Copy link
Author

gabrielhernandez3333 commented Aug 26, 2019

Sure!

class NoticiasItemBody extends StatelessWidget {
  Noticia noticia;
  NoticiasItemBody(@required this.noticia);

  @override
  Widget build(BuildContext context) {
    return Center(
        child: ListView(
      children: <Widget>[
        Column(
          children: <Widget>[
            noticia.imagenUrl != ''
                ? Image.network(
                    noticia.imagenUrl,
                  )
                : Container(),
           Html(
              data: noticia.content,
            ),
            noticia.video != ''
                ? YoutubePlayer(
                    context: context,
                    videoId: YoutubePlayer.convertUrlToId(noticia.video),
                    flags: YoutubePlayerFlags(
                      hideControls: false,
                      autoPlay: false,
                    ),
                  )
                : Container(),
          ],
        )
      ],
    ));
  }
}

The content (noticia.content) in HTML widget contains:

<p style="margin-bottom: 20px; font-family: 'Roboto Slab', sans-serif; font-size: 18.9px;">
<a href="https://google.com" class="btn btn-alpha btn-sm" data-original-title="" title="">Esto es una prueba</a>
</p>

@gabrielhernandez3333
Copy link
Author

<p style="margin-bottom: 20px; font-family: 'Roboto Slab', sans-serif; font-size: 18.9px;">
<a href="https://google.com" class="btn btn-alpha btn-sm" data-original-title="" title="">Esto es una prueba</a>
</p>

@The-Redhat
Copy link
Contributor

The-Redhat commented Aug 26, 2019

In order for the onTap of the a tag to work, you must specify onLinkTap. For example

Html(
   data: //data
   onLinkTap: (url) {
       // Do something
   }
)

@wackyapps
Copy link

wackyapps commented Sep 6, 2019

I have same issue that A tag is not working. I have added onLinkTap: (url){
}
Below is my code:

                padding: EdgeInsets.symmetric(horizontal: 15.0),
                defaultTextStyle: TextStyle(
                    fontSize: 18.0, fontFamily: 'JosefinSans', height: 1.2),
                linkStyle: TextStyle(
                    fontSize: 18.0,
                    fontFamily: 'JosefinSans',
                    height: 1.2,
                    color: Colors.blue),
                onLinkTap: (url) {
                  // open url in a webview
                  print("OPEN URL: $url");
                },
                data:
                    "<p>One of the most happening <strong>Ladies Day Event</strong> of Sydney is knocking the door again Join us to celebrate the <strong>Womanhood, Sisterhood, Friendship</strong> on <strong>28<sup>th</sup> July 2019</strong>. A funfilled day.</p> <p> Last few tickets left to grab. Contact Desi Network on 0452664774 Nikita Singh for more information.</p> <blockquote> <p> <strong><a href='https://google.com'>HURRY COUNTDOWN STARTED</a></strong></p> </blockquote>",
              )

When I click on the link text, following exception is thrown:

════════ Exception Caught By gesture ═══════════════════════════════════════════
The following NoSuchMethodError was thrown while handling a gesture:
The method 'call' was called on null.
Receiver: null
Tried calling: call("")
When the exception was thrown, this was the stack
#0      Object.noSuchMethod  (dart:core-patch/object_patch.dart:50:5)
#1      new LinkTextSpan.<anonymous closure>  (package:flutter_html/rich_text_parser.dart:50:24)
#2      GestureRecognizer.invokeCallback 
package:flutter/…/gestures/recognizer.dart:182
#3      TapGestureRecognizer._checkUp 
package:flutter/…/gestures/tap.dart:365
#4      TapGestureRecognizer.acceptGesture 
package:flutter/…/gestures/tap.dart:312
...
Handler: "onTap"
Recognizer: TapGestureRecognizer#e0056
    state: ready
    won arena
    finalPosition: Offset(256.0, 519.1)
    finalLocalPosition: Offset(227.0, 19.3)
    sent tap down
════════════════════════════════════════════════════════════════════════════════

@Sub6Resources Sub6Resources added bug Something isn't working richtext-parser labels Sep 6, 2019
@ginzbergfarns
Copy link

Any news?

@NicolasDionB
Copy link

A fix for that would be of great help since I can't rely on the old parser as it has problems with word wrapping correctly. Using the new richtext parser it works great for rendering but I can't get events!! Please help us on this!!

@Sub6Resources
Copy link
Owner

I am looking into this. Will have a fix out by the end of the year.

@Sub6Resources Sub6Resources added this to the 1.0.0 milestone Dec 12, 2019
@Sub6Resources
Copy link
Owner

This has been fixed in 1.0.0. Watch #122 for updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants