flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
166.69k stars 27.61k forks source link

[web] support scaling page content using two-finger pinch gesture #97305

Open jlemanski1 opened 2 years ago

jlemanski1 commented 2 years ago

Steps to Reproduce

  1. Execute flutter run release --web-renderer html -d web-server --web-port 8080 --web-hostname 10.0.0.209 on any Flutter Web project.
  2. Navigate to the hostname and port on any web browser to access the Flutter Web app
  3. Open the developer tools and navigate to the source code.

Expected results: With the HTML tag <meta name="viewport" content="width=device-width, initial-scale=.0, maximum-scale=2.0, user-scalable=yes"> in the index.html, I expect the tag to remain there for accessibility checkers.

Actual results: This meta tag: <meta flt-viewport="" name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> is generated by Flutter, overriding any attempts to set the maximum-scale or user-scalable properties. Even attempts to update this meta tag at runtime are thwarted by Flutter.

This is an issue as it prevents the Flutter web app from passing accessibility checkers even if user scalability is implemented in-app via Flutter. Any help or workarounds would be greatly appreciated as Flutter is only viable for this project as the client relies on passing accessibility checkers and security scans for their institution's cyber-sec insurance, and funding.

maheshj01 commented 2 years ago

Hi @jlemanski1, I checked the index.html from the developer tools but I don't see the <meta tag that you are referring to, Please check the index.html taken from the dev tools. Let me know if I am missing anything.

logs ``` mahesh@Maheshs-MacBook-Air-M1 counter % flutter run --release --web-renderer html -d web-server --web-port 8080 --web-hostname 10.0.0.209 Running "flutter pub get" in counter... 2,027ms Launching lib/main.dart on Web Server in release mode... Failed to bind web development server: SocketException: Failed to create server socket (OS Error: Can't assign requested address, errno = 49), address = 10.0.0.209, port = 8080 mahesh@Maheshs-MacBook-Air-M1 counter % flutter run --release --web-renderer html -d web-server --web-port 8080 --web-hostname 10.0.0.1 Launching lib/main.dart on Web Server in release mode... Failed to bind web development server: SocketException: Failed to create server socket (OS Error: Can't assign requested address, errno = 49), address = 10.0.0.1, port = 8080 mahesh@Maheshs-MacBook-Air-M1 counter % flutter run --release --web-renderer html -d web-server --web-port 8080 Launching lib/main.dart on Web Server in release mode... Compiling lib/main.dart for the Web... 28.1s lib/main.dart is being served at http://localhost:8080 The web-server device requires the Dart Debug Chrome extension for debugging. Consider using the Chrome or Edge devices for an improved development workflow. 🔥 To hot restart changes while running, press "r" or "R". For a more detailed help message, press "h". To quit, press "q". ```
index.html ```html counter ```
flutter doctor -v ``` [✓] Flutter (Channel stable, 2.8.1, on macOS 12.1 21C52 darwin-arm, locale en-GB) • Flutter version 2.8.1 at /Users/mahesh/Documents/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 77d935af4d (3 weeks ago), 2021-12-16 08:37:33 -0800 • Engine revision 890a5fca2e • Dart version 2.15.1 [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0) • Android SDK at /Users/mahesh/Library/Android/sdk • Platform android-31, build-tools 31.0.0 • ANDROID_HOME = /Users/mahesh/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 13.1) • Xcode at /Applications/Xcode.app/Contents/Developer • CocoaPods version 1.10.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 4.2) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264) [✓] IntelliJ IDEA Community Edition (version 2021.2.1) • IntelliJ at /Applications/IntelliJ IDEA CE.app • Flutter plugin version 60.1.4 • Dart plugin version 212.5080.8 [✓] VS Code (version 1.63.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.32.0 [✓] Connected device (4 available) • Redmi K20 Pro (mobile) • 192.168.1.3:5555 • android-arm64 • Android 11 (API 30) • iPhone 13 Pro (mobile) • 0FA2FB93-2A89-4FDB-8293-DF66188F1E54 • ios • com.apple.CoreSimulator.SimRuntime.iOS-15-0 (simulator) • macOS (desktop) • macos • darwin-arm64 • macOS 12.1 21C52 darwin-arm • Chrome (web) • chrome • web-javascript • Google Chrome 96.0.4664.110 • No issues found! ```

Thanks

jlemanski1 commented 2 years ago

Hey @maheshmnj, thanks for the quick response. I just created a new Flutter project to test and running a web server with release mode on, the Chrome developer tools elements tab displays the following index.html:

index.html ```html Flutter Demo ```

When inspecting the page source (raw html, before any JS runs), the index.html is as follows:

raw html ``` test ```

That one meta tag is being read by site accessibility checkers and giving a page zoom restricted alert/warning. Hopefully this helps a little bit. Let me know if there's anything else you need from me, and thank you again!

maheshj01 commented 2 years ago

Thanks for the info @jlemanski1, I can see the same meta tag on stable and the master channel, Leaving this issue open for further insights from the team.

\

index.html ```html ```
flutter doctor -v ``` [✓] Flutter (Channel stable, 2.8.1, on macOS 12.1 21C52 darwin-arm, locale en-GB) • Flutter version 2.8.1 at /Users/mahesh/Documents/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 77d935af4d (3 weeks ago), 2021-12-16 08:37:33 -0800 • Engine revision 890a5fca2e • Dart version 2.15.1 [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0) • Android SDK at /Users/mahesh/Library/Android/sdk • Platform android-31, build-tools 31.0.0 • ANDROID_HOME = /Users/mahesh/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 13.1) • Xcode at /Applications/Xcode.app/Contents/Developer • CocoaPods version 1.10.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 4.2) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264) [✓] IntelliJ IDEA Community Edition (version 2021.2.1) • IntelliJ at /Applications/IntelliJ IDEA CE.app • Flutter plugin version 60.1.4 • Dart plugin version 212.5080.8 [✓] VS Code (version 1.63.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.32.0 [✓] Connected device (4 available) • Redmi K20 Pro (mobile) • 192.168.1.3:5555 • android-arm64 • Android 11 (API 30) • iPhone 13 Pro (mobile) • 0FA2FB93-2A89-4FDB-8293-DF66188F1E54 • ios • com.apple.CoreSimulator.SimRuntime.iOS-15-0 (simulator) • macOS (desktop) • macos • darwin-arm64 • macOS 12.1 21C52 darwin-arm • Chrome (web) • chrome • web-javascript • Google Chrome 96.0.4664.110 • No issues found! ``` ``` [✓] Flutter (Channel master, 2.10.0-1.0.pre.307, on macOS 12.1 21C52 darwin-arm, locale en-GB) • Flutter version 2.10.0-1.0.pre.307 at /Users/mahesh/Documents/flutter_master • Upstream repository https://github.com/flutter/flutter.git • Framework revision b7424c619c (7 hours ago), 2022-01-26 17:25:45 -0800 • Engine revision c248c6e38e • Dart version 2.17.0 (build 2.17.0-63.0.dev) • DevTools version 2.10.0-dev.1 [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0) • Android SDK at /Users/mahesh/Library/Android/sdk • Platform android-31, build-tools 31.0.0 • ANDROID_HOME = /Users/mahesh/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 13.2.1) • Xcode at /Applications/Xcode.app/Contents/Developer • CocoaPods version 1.10.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 4.2) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264) [✓] IntelliJ IDEA Community Edition (version 2021.2.1) • IntelliJ at /Applications/IntelliJ IDEA CE.app • Flutter plugin version 60.1.4 • Dart plugin version 212.5080.8 [✓] VS Code (version 1.63.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.32.0 [✓] Connected device (2 available) • macOS (desktop) • macos • darwin-arm64 • macOS 12.1 21C52 darwin-arm • Chrome (web) • chrome • web-javascript • Google Chrome 97.0.4692.99 [✓] HTTP Host Availability • All required HTTP hosts are available • No issues found! ```

cc: @mdebbar

yjbanov commented 2 years ago

user-scalable=yes would interfere with Flutter's gesture detection. We should instead support scaling content directly in the framework. I recall seeing an issue like that, but I can't find it any more, so let's accept this one as a feature request for scaling page content.

jlemanski1 commented 2 years ago

I've implemented two-finger pinch scaling in the app in question, the bigger issue for me is that the forced user-scalable=no does not allow for any Flutter web app to pass accessibility checkers without manual review of the app. This is notably an issue in enterprise or academic applications where their cyber-security insurance is dependent on these automated checks. Manual reporting is the current workaround but it would be ideal if Flutter web applications could pass these accessibility checkers.

HeinrichJanzing commented 2 years ago

Desktop browsers apparently do not respect the user-scalable=no. IIRC, iOS Safari doesn't respect it either. It cannot be used reliably to prevent the browser's default zooming behavior.

If I use pinch-to-zoom on the flutter gallery app in Chrome or Edge on my laptop, it essentially breaks the app: Before: image

After using a touch pad pinch gesture to zoom in: image

So - I would say this is not just a feature request, but also a rather serious bug to be fixed.

razfazz commented 2 years ago

https://github.com/flutter/flutter/issues/107420

Jonas-Schnee commented 2 years ago

As #107624 was closed in regards of this, I would like to ask here why this is considered a new Feature with Prio P5 as it is a default web/browser functionality that breaks any flutter app?

It seems that the viewport is not taken into account correctly by flutter. Changes on the viewport should not trigger a reflow of the page contents but behave like a magnifying glass.

HeinrichJanzing commented 2 years ago

@yjbanov #107624 was closed as a duplicate of this. It can only be considered a duplicate if we relabel this as a bug (described in that issue) instead of a low prio feature request. The bug is a consequence of a large group of browsers not respecting user-scalable=no and Flutter not handling the browser-enforced zooming correctly. It is common knowledge among web developers that the user-scalable=no directive is not a reliable way to disable the browser's pinch zooming.

So far we've reproduced the problem illustrated by #107624 in Chrome and Firefox on Windows, using both a touch pad and a touch screen.

We believe the issue lies in Flutter relying on window.visualViewport to determine the application width and height (see EngineFlutterWindow.computePhysicalSize). That function only looks at the width and height properties but ignores the scale and offsets (see VisualViewport).

I am not sure why window.visualViewport is used there instead of window.innerWidth and window.innerHeight, which are currently only used as a fallback.

To summarize: Flutter web should either consistently prevent browser pinch zooming or handle it correctly. Currently, it's doing neither.

Edit: fixed typo in referenced issue ID.

khari998 commented 1 year ago

This definitely feels like a bug over a feature. Since I am able to pinch and zoom on any other website, it should be something that we at least have as an option to toggle for web builds of Flutter. I was testing a web application on my monitor and lacking pinch and zoom was incredibly frustrating.

s-hammad-a commented 1 year ago

Is there any progress on this issue? Maybe a temporary fix to this problem?

jlemanski1 commented 1 year ago

Hi @s-hammad-a,

As for Pinch to Zoom functionality there are a few ways of achieving it, I'd recommend starting with this widget.

That being said, as stated above, Flutter Web is currently inconsistent with preventing and/or allowing this behaviour so you will likely still run into issues. There doesn't seem to be any progress on a resolution but @HeinrichJanzing has a detailed comment concerning the probable root cause of the issue.

s-hammad-a commented 1 year ago

@jlemanski1 Thanks for the response.

I tried your recommended InteractiveViewer widget but I am facing a problem where 2 finger scroll gestures also change the zoom. Is there anyway to disable it so it only zooms for pinch gesture? I can't find any through it's properties.

khari998 commented 1 year ago

@s-hammad-a @jlemanski1 hopefully there is a way to. No pinch to zoom has really been a drag for web projects. And now more companies are starting to try out Flutter for their production web applications. It seems small in the grand scope of things but it is one of those issues that make me hesitant to recommend Flutter for web even though its my favorite framework

jpdup commented 1 year ago

This has become a showstopper for our company adoption. Strangely Cmd+- MacOS or Ctrl-+ on Windows Font Scale works fine for zooming.

s-hammad-a commented 1 year ago

Hello hard working developers. Just wanted to know if someone started working on this issue or any update about it?

gabrielmattern commented 1 year ago

This 'bug' or missing feature is a blocker for our company adoption as well.

parito-ltd commented 1 year ago

We have been evaluating flutter for a project exactly 1 year ago but decided against because of this issue. One year later, we are evaluating flutter again for a different project and the issue has seen no progress at all to a solution. This is not a feature, this is an important bug that completely breaks flutter-based apps on web, and therefore is a giant blocker for any web-based flutter project, the team should consider rising its priority.

tom-bailey-om commented 1 year ago

Completely agree with the other comments - we are using Flutter for a production website for the older demographic who are likely to want to zoom. We assumed this functionality would be available, so it's a huge surprise and concern that not only does it not work but that it isn't even considered a bug!

khari998 commented 1 year ago

Glad to see I'm not the only one this is incredibly important to. Hopefully the Flutter team will realize the importance of this as well

0ttik commented 1 year ago

This is 100% a bug because it blocks the expected default web site behaviour and has no workarounds.

25thammar commented 12 months ago

Hi any progress on this issue?