What are the steps to prevent scrolling in a Flutter web app that is embedded?

This is my first question on this platform, so I hope for some gentle feedback.

I am currently working on a basic flutter web application that I want to embed in an existing webpage. The app is hosted on firebase, and I have used an iFrame on the parent page to display the flutter app. You can see an image of the setup below.

Check out the webpage here

The issue I am facing is that whenever the pointer hovers over the iframe, the flutter app seems to capture all scroll/wheel events, even if there is no scrollable content within the app. I have tried various solutions such as using JavaScript scripts, adjusting iframe attributes, and modifying CSS styles, but nothing has worked so far. Additionally, I am unable to use jQuery on the parent page.

Below is the code snippet I have attempted on the parent webpage. Unfortunately, the console log events do not seem to be triggered (at least when using Chrome Dev Tools), so I have yet to try passing the wheel event to the parent element.


    <style>
        #app {
            height: 280px;
            width: 90%;
            background-color: white;
            margin: 0 auto;
            border: none;
            overflow-y: hidden;
        }
    </style>

    <iframe id="app" src="https://fireball-apps-testimonials.firebaseapp.com/" scroll="no" scrolling="no"></iframe>

    <script type="text/javascript">
        var app = document.getElementById("app");

        function myFunction(event) {
            console.log('event triggered');
            
            if (event) {
                if (event.wheelData < 0) {
                    console.log('scrolling up');
                } else if (event.wheelData > 0) {
                    console.log('scrolling down');
                }
            } else {
                console.log('event is null');
            }
        }

        app.addEventListener("wheel", myFunction);
    </script>

Answer №1

I have experimented with various techniques to prevent scroll actions using CSS and JavaScript on the parent webpage. The issue arises when Flutter captures all scroll events, even if there are no scrollable widgets present. As of now, I have managed to identify the relevant code to disable scroll actions:

  1. Compile your project using flutter build web
  2. Access build/web/main.dart.js
  3. Locate and remove
    s.addEventListener.apply(s,["wheel",q,r])

Note: Modifying build files is not recommended practice, but this workaround has proven effective in disabling scroll actions within the iframe. Deleting the Event Listener will restrict scrolling within the iframe, and this solution is specifically applicable to desktop platforms.

Refer to https://github.com/flutter/flutter/issues/78216 for additional details.

Answer №2

If you remove the line

s.addEventListener.apply(s,["wheel",q,r])
from the file main.dart.js, you will be able to scroll using the mouse wheel. However, this solution does not work for touch screens that do not have a scroll wheel. I discovered that changing the line touch-action: none in the body's CSS within the iframe prevents touch scrolling. The fix is to change it to touch-action: initial. Keep in mind that this may affect all scrolling inside the iframe. If you need horizontal scrolling inside the iframe while still being able to scroll vertically on the entire page, set it to touch-action: pan-y.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Learn the process of adding a key and value into an array using Angular

I need to filter data based on the number of rows and columns provided by the user. After reading an excel file, I extract the data in the controller: https://i.sstatic.net/vPpxL.png These are the column headers retrieved after the user entered 5 as the ...

When I try to import script files into my ASP.NET page, Intellisense displays the methods accurately. However, when I attempt to call one of them, an

I added a function to an existing .js file (I tried two different files) in order to make the method accessible in multiple locations without having to repeat the code. I also created a simple function just to confirm that my function wasn't causing a ...

What sets Java classes apart from JavaScript classes?

After working with C# and Java, I decided to dive into learning javascript/node.js. However, I am facing some challenges trying to understand what is wrong with this code. Here is the snippet from my main.js file: const MyClass = require("./MyClass"); le ...

Is there a way to arrange an HTML list in this specific manner using CSS or JavaScript?

I need to arrange a list of items in columns with 5 rows each, as shown in the attached image. This list is generated dynamically using an SQL query with a loop on the li tag. I am looking for a solution to order the list in this way using javascript or ...

Zero results returned for the angularjs script

I am working on enhancing my skills in angularjs, but I am facing an issue where only the categories are being displayed and the products are not showing up. There are no error messages, so I am having trouble pinpointing where the problem lies. Here is t ...

Handling 401 Status Codes with Access and Refresh Tokens in a React and Node Application

Dealing with a 401 status request from my server when the access token is expired is proving to be a challenge. I have implemented accessTokenVerify on the server side: require('dotenv').config(); const jwt = require("jsonwebtoken") ...

Include a suffix after the user's input in a Material UI TextField

I need to implement a TextField element that displays the entered value followed by an Input Adornment. Can I have the percentage sign (%) appear after the entered value instead of at the end of the input? Currently, the percentage sign (%) appears at the ...

Error: The lambda response was not defined. Please review your function code. The response returned with a status of 500 in 583 milliseconds

https://i.sstatic.net/GUHr9.png I'm experimenting with Netlify and its Lambda function feature to execute a Node.js function. Following the guide at https://css-tricks.com/using-netlify-forms-and-netlify-functions-to-build-an-email-sign-up-widget/. ...

Purge the cache of CSS and JavaScript in your browser

Is there a way to clear JavaScript and CSS cache in ASP MVC without having to clear browser history? ...

Sending back an array within the onOpen function

I am currently in the process of developing a chat application. At this stage, users are able to send messages to each other and I have successfully stored these messages in my database. Now, my objective is to display the stored messages from the database ...

When trying to access data within objects using JSON iteration, it may lead to encountering an issue of reading a

Attempting to retrieve specific data from a JSON file obtained from a website has proven challenging. While iterating through the collection of objects, undefined values are constantly encountered. Unfortunately, if the JSON is poorly structured, modificat ...

Discovering a collection of class elements with particular text in Selenium IDE

My objective is to verify that the correct title, summary, and link are displayed in search results. In the scenario below, I aim to ensure that one of the listings includes the title "Title for Beta," a summary with the content "Summary for Beta," and a ...

Retrieving the value of a selected radio button in Asp.net using Javascript

I have searched for a solution to my issue multiple times, but none of the solutions I have found seem to work for me. I am currently working with IE. <asp:RadioButtonList ID="rbtnView" runat="server" OnSelectedIndexChanged="rbtnView_SelectedIndexChan ...

Confusion with using Javascript callbacks or arrow functions to sort a NeDB database in a Get response

I am facing an issue with sorting the results from my NeDB database in my express server. Currently, when I retrieve the whole database, the order of results does not match the database file. I want to sort the results based on one of the timestamps in the ...

When using Angular 8 with RxJs, triggering API calls on click events will automatically detach if the API server is offline

I have an Angular 8 application with a form containing a save button that triggers a call to a Spring Boot microservice using RxJs. I decided to test what would happen if the Rest API server were down. When the Rest API is running, clicking the button wor ...

Issue with a hidden div, problem with scrolling, a div overlapping other divs

I'm feeling a bit lost here, trying to figure out what went wrong. It seems like a simple mistake, but I can't pinpoint it. Currently, I'm just testing everything out for a mobile website template. Hopefully, that information helps. For any ...

Obtaining data upon clicking a button within a Bootstrap modal

Implementing Google Map API to calculate the distance between departure and destination locations has been successful so far. However, I am encountering an issue with displaying the distance value in a Bootstrap modal after clicking on the Get the Distance ...

JavaScript regex substitution not functioning as expected

My JavaScript code contains a string var str = '<at id="11:12345678">@robot</at> ping'; I am trying to remove a specific part of this string <at id="11:12345678">@ To achieve this, I am using the following code snippet: var ...

Modifying the font style and color of text within the table header - Material Table version 0.19.4

Recently, I began using React and Material UI but have encountered an issue with modifying the color and font of text in the table header. Despite attempting to override it, the default style remains unchanged. It has been mentioned that utilizing "heade ...

Identifying the Occurrence of a Partial Insertion in Rails through JavaScript/jQuery

Is there a way to determine if a partial is currently visible using JavaScript? Let's simplify this with some pseudo-code to explain my question - In this scenario, in my controller: def index if (request.xhr?)//coming from pagination ajax requ ...