-
Notifications
You must be signed in to change notification settings - Fork 15
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
added onTap feature for chartJS #1690
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter/gestures.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:url_launcher/url_launcher_string.dart'; | ||
// Import for Android features. | ||
|
@@ -138,7 +140,19 @@ class JsWidgetState extends State<JsWidget> { | |
fit: StackFit.expand, | ||
children: [ | ||
!_isLoaded ? widget.loader : const SizedBox.shrink(), | ||
WebViewWidget(controller: controller), | ||
WebViewWidget( | ||
controller: controller, | ||
gestureRecognizers: <Factory<OneSequenceGestureRecognizer>>{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. configure the gestureRecognizers only if a listener has been specified. You don't want to capture clicks if there is no listener |
||
Factory<OneSequenceGestureRecognizer>( | ||
() => TapGestureRecognizer() | ||
..onTapDown = (TapDownDetails details) { | ||
if (widget.listener != null) { | ||
widget.listener!('onTap'); // Notify on tap | ||
} | ||
}, | ||
), | ||
}, | ||
), | ||
], | ||
), | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,7 +100,7 @@ class JsWidgetState extends State<JsWidget> { | |
void initState() { | ||
if (widget.listener != null) { | ||
addListener(widget.id, widget.listener!); | ||
init(globalListener); | ||
_setupFlutterWebCommunication(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the init method sets up the interop. How will it work without calling that method? |
||
} | ||
if (widget.preCreateScript != null) { | ||
eval(widget.preCreateScript!()); | ||
|
@@ -114,6 +114,14 @@ class JsWidgetState extends State<JsWidget> { | |
}); | ||
super.initState(); | ||
} | ||
// Setup Flutter web communication for JS interactions | ||
void _setupFlutterWebCommunication() { | ||
html.window.addEventListener('callFlutter', (event) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. who dispatches the callFlutter event? why not use the interop? |
||
final customEvent = event as html.CustomEvent; | ||
final msg = customEvent.detail; | ||
globalListener(widget.id, msg); | ||
}); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we are sending the event anyway, why not send data as well? It is important in general to send the data along with the event even if not needed for this use case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, I have updated the available data in it.