Skip to content

[web] flutter website doesn't resize properly when zoomed in/out and resizing window on desktop  #77084

Closed

Description

@tanharpatel

I have deployed flutter website, its working fine but when I try to zoom the screen it doesn't work as expected.

I come across some cocoon site which is also behaving as my website is.

How the actual site looks like The site after zoom in
image image

Is their any way to resolve it???

Thanks in advance.

Activity

  1. nilsreichardt commented on Mar 2, 2021

    @nilsreichardt
    Contributor

    Which flutter version do you use and can you provide a reproducible code sample?

  2. tanharpatel commented on Mar 3, 2021

    @tanharpatel
    Author

    @nilsreichardt I am using flutter version 1.27 and the minimal reproducible code sample is:

    Code
    import 'package:flutter/material.dart';
    
    void main() {
      runApp(
        MaterialApp(
          debugShowCheckedModeBanner: false,
          home: Scaffold(
            body: Center(
              child: MyWidget(),
            ),
          ),
        ),
     );
    }
    
    class MyWidget extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Material(
          color: const Color(0xFF1a1a1a),
          child: Scaffold(
            backgroundColor: Colors.blue,
            body: Stack(
              children: [
                Positioned(
                  left: MediaQuery.of(context).size.height * 0.2,
                  right: MediaQuery.of(context).size.height * 0.1,
                  top: MediaQuery.of(context).size.height * 0.15,
                  child: Row(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      SizedBox(
                        width: MediaQuery.of(context).size.width * 0.5,
                        child: Text("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum", style: TextStyle(color:Colors.white)),
                      ),
                      SizedBox(width: MediaQuery.of(context).size.width * 0.02),
                      SizedBox(
                        width: MediaQuery.of(context).size.width * 0.2,
                        child: Center(
                          child: Text("Hello\nGood Morning", style: TextStyle(color:Colors.white)),
                      ),
                    ),
                   ],
                  ),
                ),
              ],
            ),
           ),
        );
      }
    }
  3. TahaTesser commented on Mar 3, 2021

    @TahaTesser
    Contributor

    Hi @tanharpatel
    Thanks for filing the issue, I'm unable to reproduce it on macOS or Windows

    code sample
    import 'package:flutter/material.dart';
    
    void main() {
      runApp(
        MaterialApp(
          debugShowCheckedModeBanner: false,
          home: Scaffold(
            body: Center(
              child: MyWidget(),
            ),
          ),
        ),
      );
    }
    
    class MyWidget extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Material(
          color: const Color(0xFF1a1a1a),
          child: Scaffold(
            backgroundColor: Colors.blue,
            body: Stack(
              children: [
                Positioned(
                  left: MediaQuery.of(context).size.height * 0.2,
                  right: MediaQuery.of(context).size.height * 0.1,
                  top: MediaQuery.of(context).size.height * 0.15,
                  child: Row(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      SizedBox(
                        width: MediaQuery.of(context).size.width * 0.5,
                        child: Text(
                            "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum",
                            style: TextStyle(color: Colors.white)),
                      ),
                      SizedBox(width: MediaQuery.of(context).size.width * 0.02),
                      SizedBox(
                        width: MediaQuery.of(context).size.width * 0.2,
                        child: Center(
                          child: Text("Hello\nGood Morning",
                              style: TextStyle(color: Colors.white)),
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        );
      }
    }
    
    flutter doctor -v
    [✓] Flutter (Channel master, 1.27.0-9.0.pre.175, on macOS 11.2.2 20D80 darwin-x64, locale en-GB)
        • Flutter version 1.27.0-9.0.pre.175 at /Users/tahatesser/Code/flutter_master
        • Framework revision 97295dc9a8 (3 hours ago), 2021-03-03 00:19:03 -0500
        • Engine revision cd0e54348b
        • Dart version 2.13.0 (build 2.13.0-93.0.dev)
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
        • Android SDK at /Volumes/Extreme/SDK
        • Platform android-30, build-tools 30.0.3
        • ANDROID_HOME = /Volumes/Extreme/SDK
        • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS
        • Xcode at /Volumes/Extreme/Xcode.app/Contents/Developer
        • Xcode 12.4, Build version 12D4e
        • CocoaPods version 1.10.1
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 4.1)
        • 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 1.8.0_242-release-1644-b3-6915495)
    
    [✓] VS Code (version 1.53.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.20.0
    
    [✓] Connected device (4 available)
        • Taha’s iPad (mobile) • 00008020-000255113EE8402E            • ios            • iOS 14.4
        • iPhone 12 (mobile)   • 948EC106-78EE-4A69-8D31-83C00E6419DE • ios            •
          com.apple.CoreSimulator.SimRuntime.iOS-14-4 (simulator)
        • macOS (desktop)      • macos                                • darwin-x64     • macOS 11.2.2 20D80
          darwin-x64
        • Chrome (web)         • chrome                               • web-javascript • Google Chrome
          88.0.4324.192
    
    • No issues found!

    Can you please provide your flutter doctor -v and which browser you're using? Is it on debug mode or release mode?
    Thank you

  4. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Mar 3, 2021
  5. tanharpatel commented on Mar 3, 2021

    @tanharpatel
    Author

    Hello @TahaTesser
    Thank you for your valuable response.

    I am using Chrome on Windows. And the problem persists in release mode.

    flutter doctor -v
    [√] Flutter (Channel master, 1.27.0-2.0.pre.103, on Microsoft Windows [Version 10.0.18363.1379], locale en-US)
        • Flutter version 1.27.0-2.0.pre.103 at C:\flutter
        • Framework revision f49956598b (2 weeks ago), 2021-02-16 00:56:06 -0500
        • Engine revision 1d537824d6
        • Dart version 2.13.0 (build 2.13.0-30.0.dev)
    
    [√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
        • Android SDK at C:\Users\Tanha Patel\AppData\Local\Android\Sdk
        • Platform android-30, build-tools 29.0.2
        • ANDROID_HOME = C:\Users\Tanha Patel\AppData\Local\Android\Sdk
        • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
        • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
        • All Android licenses accepted.
    
    [√] Chrome - develop for the web
        • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
    
    [√] Android Studio (version 3.6)
        • Android Studio at C:\Program Files\Android\Android Studio
        • Flutter plugin version 45.1.1
        • Dart plugin version 192.7761
        • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
    
    [√] VS Code (version 1.53.2)
        • VS Code at C:\Users\Tanha Patel\AppData\Local\Programs\Microsoft VS Code
        • Flutter extension version 3.20.0
    
    [√] Connected device (2 available)
        • Chrome (web) • chrome • web-javascript • Google Chrome 88.0.4324.190
        • Edge (web)   • edge   • web-javascript • Microsoft Edge 88.0.705.56
    
    • No issues found!
    
  6. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Mar 3, 2021
  7. TahaTesser commented on Mar 3, 2021

    @TahaTesser
    Contributor

    Hi @tanharpatel
    You seem to be on 2 weeks older master, for master channel it's quite old
    I cannot reproduce this issue on the latest master channel.
    Can you please upgrade to the latest master and try again
    flutter channel master
    flutter upgrade --force
    flutter doctor -v
    Thank you

  8. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Mar 3, 2021
  9. tanharpatel commented on Mar 3, 2021

    @tanharpatel
    Author

    Hey @TahaTesser

    I am on latest master channel. But still I am facing issue when I zoom.

    flutter doctor -v
    [√] Flutter (Channel master, 1.27.0-9.0.pre.176, on Microsoft Windows [Version 10.0.18363.1379], locale en-US)
        • Flutter version 1.27.0-9.0.pre.176 at C:\flutter
        • Framework revision dff42b8ee1 (5 hours ago), 2021-03-03 03:14:02 -0500
        • Engine revision cd0e54348b
        • Dart version 2.13.0 (build 2.13.0-93.0.dev)
    
    [√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
        • Android SDK at C:\Users\Tanha Patel\AppData\Local\Android\Sdk
        • Platform android-30, build-tools 29.0.2
        • ANDROID_HOME = C:\Users\Tanha Patel\AppData\Local\Android\Sdk
        • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
        • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
        • All Android licenses accepted.
    
    [√] Chrome - develop for the web
        • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
    
    [√] Android Studio (version 3.6)
        • Android Studio at C:\Program Files\Android\Android Studio
        • Flutter plugin version 45.1.1
        • Dart plugin version 192.7761
        • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
    
    [√] VS Code (version 1.53.2)
        • VS Code at C:\Users\Tanha Patel\AppData\Local\Programs\Microsoft VS Code
        • Flutter extension version 3.20.0
    
    [√] Connected device (2 available)
        • Chrome (web) • chrome • web-javascript • Google Chrome 88.0.4324.190
        • Edge (web)   • edge   • web-javascript • Microsoft Edge 88.0.705.56
    
    • No issues found!

    Thanks!

  10. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Mar 3, 2021
  11. TahaTesser commented on Mar 4, 2021

    @TahaTesser
    Contributor

    Hi @tanharpatel
    There is a precise zoom out to reproduce, if zoomed out quickly it corrects itself, then zoom a bit more, and then issues show up
    Here I managed to zoom out exactly to reproduce. Only reproduces in Canvaskit render

    Preview

    Canvaskit HTML
    ezgif com-gif-maker (1) ezgif com-gif-maker
    code sample
    import 'package:flutter/material.dart';
    
    void main() {
      runApp(
        MaterialApp(
          debugShowCheckedModeBanner: false,
          home: Scaffold(
            body: Center(
              child: MyWidget(),
            ),
          ),
        ),
      );
    }
    
    class MyWidget extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Material(
          color: const Color(0xFF1a1a1a),
          child: Scaffold(
            backgroundColor: Colors.blue,
            body: Stack(
              children: [
                Positioned(
                  left: MediaQuery.of(context).size.height * 0.2,
                  right: MediaQuery.of(context).size.height * 0.1,
                  top: MediaQuery.of(context).size.height * 0.15,
                  child: Row(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      SizedBox(
                        width: MediaQuery.of(context).size.width * 0.5,
                        child: Text(
                            "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum",
                            style: TextStyle(color: Colors.white)),
                      ),
                      SizedBox(width: MediaQuery.of(context).size.width * 0.02),
                      SizedBox(
                        width: MediaQuery.of(context).size.width * 0.2,
                        child: Center(
                          child: Text("Hello\nGood Morning",
                              style: TextStyle(color: Colors.white)),
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        );
      }
    }
    flutter doctor -v
    [✓] Flutter (Channel stable, 2.0.0, on Microsoft Windows [Version 10.0.19042.804], locale en-US)
        • Flutter version 2.0.0 at C:\Users\Taha\Code\flutter_stable
        • Framework revision 60bd88df91 (15 hours ago), 2021-03-03 09:13:17 -0800
        • Engine revision 40441def69
        • Dart version 2.12.0
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
        • Android SDK at C:\Users\Taha\Code\SDK
        • Platform android-30, build-tools 30.0.3
        • ANDROID_HOME = C:\Users\Taha\Code\SDK
        • Java binary at: C:\Users\Taha\Code\android-studio\jre\bin\java
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
        • All Android licenses accepted.
    
    [✓] Chrome - develop for the web
        • Chrome at C:\Users\Taha\AppData\Local\Google\Chrome\Application\chrome.exe
    
    [✓] Visual Studio - develop for Windows (Visual Studio Community 2019 16.8.5)
        • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
        • Visual Studio Community 2019 version 16.8.31005.135
        • Windows 10 SDK version 10.0.18362.0
    
    [✓] Android Studio (version 4.1.0)
        • Android Studio at C:\Users\Taha\Code\android-studio
        • 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 1.8.0_242-release-1644-b01)
    
    [✓] VS Code (version 1.53.2)
        • VS Code at C:\Users\Taha\AppData\Local\Programs\Microsoft VS Code
        • Flutter extension version 3.20.0
    
    [✓] Connected device (4 available)
        • Android SDK built for x86 (mobile) • emulator-5554 • android-x86    • Android 10 (API 29) (emulator)
        • Windows (desktop)                  • windows       • windows-x64    • Microsoft Windows [Version 10.0.19042.804]
        • Chrome (web)                       • chrome        • web-javascript • Google Chrome 88.0.4324.190
        • Edge (web)                         • edge          • web-javascript • Microsoft Edge 88.0.705.81
    
    • No issues found!
    [✓] Flutter (Channel master, 2.1.0-11.0.pre.97, on Microsoft Windows [Version 10.0.19042.804], locale en-US)
        • Flutter version 2.1.0-11.0.pre.97 at C:\Users\Taha\Code\flutter_master
        • Framework revision c14c8d8177 (2 hours ago), 2021-03-03 21:40:34 -0800
        • Engine revision 72bbc5d92c
        • Dart version 2.13.0 (build 2.13.0-93.0.dev)
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
        • Android SDK at C:\Users\Taha\Code\SDK
        • Platform android-30, build-tools 30.0.3
        • ANDROID_HOME = C:\Users\Taha\Code\SDK
        • Java binary at: C:\Users\Taha\Code\android-studio\jre\bin\java
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
        • All Android licenses accepted.
    
    [✓] Chrome - develop for the web
        • Chrome at C:\Users\Taha\AppData\Local\Google\Chrome\Application\chrome.exe
    
    [✓] Visual Studio - develop for Windows (Visual Studio Community 2019 16.8.5)
        • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
        • Visual Studio Community 2019 version 16.8.31005.135
        • Windows 10 SDK version 10.0.18362.0
    
    [✓] Android Studio (version 4.1.0)
        • Android Studio at C:\Users\Taha\Code\android-studio
        • 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 1.8.0_242-release-1644-b01)
    
    [✓] VS Code (version 1.53.2)
        • VS Code at C:\Users\Taha\AppData\Local\Programs\Microsoft VS Code
        • Flutter extension version 3.20.0
    
    [✓] Connected device (4 available)
        • Android SDK built for x86 (mobile) • emulator-5554 • android-x86    • Android 10 (API 29) (emulator)
        • Windows (desktop)                  • windows       • windows-x64    • Microsoft Windows [Version 10.0.19042.804]
        • Chrome (web)                       • chrome        • web-javascript • Google Chrome 88.0.4324.190
        • Edge (web)                         • edge          • web-javascript • Microsoft Edge 88.0.705.81
    
    • No issues found!

    A similar issue was fixed in #75286 and also reported #75790

    Thank you

  12. 46 remaining items

  13. HeinrichJanzing commented on May 23, 2022

    @HeinrichJanzing

    I just tested this on master and it seems the merged fix is only a partial one. In case the surface size is still valid (i.e. no window size change, only device pixel ratio change), there's an early exit happening here in lib\src\engine\canvaskit\surface.dart, Surface.createOrUpdateSurface:

        // Check if the window is the same size as before, and if so, don't allocate
        // a new canvas as the previous canvas is big enough to fit everything.
        final ui.Size? previousSurfaceSize = _currentSurfaceSize;
        if (!_forceNewContext &&
            previousSurfaceSize != null &&
            size.width == previousSurfaceSize.width &&
            size.height == previousSurfaceSize.height) {
          // The existing surface is still reusable.
          if (window.devicePixelRatio != _currentDevicePixelRatio) {
            _updateLogicalHtmlCanvasSize(); // <-- should also call `_translateCanvas()` here!
          }
          return _surface!;
        }

    Interestingly, as @linxuebin1990 noticed, size.width and size.height often suffer from precision issues, making them subtly different, causing this path to not be taken as often as expected. When it is taken, the devicePixelRatio change is detected, the logical size of the canvas is updated to match, but the canvas' translation, intended to compensate for the canvas being oversized, isn't updated. This translation is expressed in logical pixels and thus should also be updated.

    If this doesn't happen, it causes the Flutter UI to appear shifted vertically in the browser's viewport. This can be reproduced in any Flutter web app by using Ctrl+mousewheel to change the zoom level. Sooner or later it pops up. Luckily, changing the zoom level again or resizing the window does trigger the call to _translateCanvas() and fixes things.

    So, there should be a call to _translateCanvas() next to _updateLogicalHtmlCanvasSize().

    I would contribute a patch but it seems to take a while to get my CLA in order.

  14. linhdoan24 commented on May 24, 2022

    @linhdoan24

    i still have this problem when zoom out + zoom in.
    Flutter 3.0.1

  15. fatduckling commented on May 25, 2022

    @fatduckling
    Contributor

    Hi @HeinrichJanzing
    I've created #104573 for the fix and added a pull request (as this issue is closed).
    Thanks

  16. fatduckling commented on May 30, 2022

    @fatduckling
    Contributor

    Hi team,
    I have created a pull request flutter-team-archive/engine#33695 to call _translateCanvas() after _updateLogicalHtmlCanvasSize(). Please check, thanks

  17. PongsiriTK commented on Jun 17, 2022

    @PongsiriTK

    Any updates? I'm also facing this issue on production. Compare to the normal html this issue won't happen.

  18. lucas-goldner commented on Jul 10, 2022

    @lucas-goldner
    Contributor

    Please check @fatduckling PR. Still facing this issue

  19. lextotan commented on Jul 13, 2022

    @lextotan

    first solutions: run on terminal : flutter run -d chrome --web-renderer html
    seconds solutions: if u use android studio , click main.dart(top left run button) Edit configurations. You will see Additional run args: --web-renderer html
    apply > ok > run

  20. andrelrf1 commented on Jul 23, 2022

    @andrelrf1

    first solutions: run on terminal : flutter run -d chrome --web-renderer html seconds solutions: if u use android studio , click main.dart(top left run button) Edit configurations. You will see Additional run args: --web-renderer html apply > ok > run

    That didn't work one hundred percent, because when I zoom in with the touchpad the problem still happens unfortunately.

  21. lextotan commented on Jul 23, 2022

    @lextotan

    Bro, can u try on new flutter project. Channel stable

  22. andrelrf1 commented on Jul 23, 2022

    @andrelrf1

    Bro, can u try on new flutter project. Channel stable

    That's what I did. I'm using the latest stable version of Flutter. So when I zoom with ctrl + mouse scroll or using the browser's zoom option the page works as expected, but when I use the touchpad/trackpad gesture to zoom the problem still happens.

  23. added a commit that references this issue on Aug 5, 2022
    1f8255a
  24. github-actions commented on Aug 19, 2022

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  25. locked as resolved and limited conversation to collaborators on Aug 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work listc: regressionIt was better in the past than it is nowc: renderingUI glitches reported at the engine/skia or impeller rendering levelcustomer: crowdAffects or could affect many people, though not necessarily a specific customer.customer: sameheree: web_canvaskitCanvasKit (a.k.a. Skia-on-WebGL) rendering backend for Webengineflutter/engine related. See also e: labels.found in release: 2.0Found to occur in 2.0found in release: 2.1Found to occur in 2.1has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-webWeb applications specifically

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions