I'm currently building an application using flutter with webview for mobile. how to detect scroll when it reaches the end of line of a website page in webview?
I'm currently building an application using flutter with webview for mobile. how to detect scroll when it reaches the end of line of a website page in webview?
I had the same problem, so I import syncfusion_flutter_pdfviewer. You can set controller on this viewer and use listener.
It can be done through Javascript with webview, but it is a little bit complicated.
I solved this problem by adding this script on flutter side
WebView(
initialUrl: "http://url.com/tos",
javascriptMode: JavascriptMode.unrestricted,
javascriptChannels: [
JavascriptChannel(
name: 'FLUTTER_CHANNEL',
onMessageReceived: (message) {
if (message.message.toString() ==
"end of scroll") {
setState((){
enableAgreeButton = true;
});
}
})
].toSet(),
gestureNavigationEnabled: true,
debuggingEnabled: true,
)
and this on js side
<script>
window.onscroll = function(ev) {
if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
window.FLUTTER_CHANNEL.postMessage('end of scroll');
}
};
</script>
thanks to nsNeruno and Starscream for the insight