Skip to content

Padding inside FilledButton have a different behavior on web when on Mobile Browser vs Desktop Browser #155768

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

Open
c-lucera-pvotal opened this issue Sep 26, 2024 · 9 comments
Labels
c: parity Works on one platform but not another d: api docs Issues with https://api.flutter.dev/ f: material design flutter/packages/flutter/material repository. found in release: 3.24 Found to occur in 3.24 found in release: 3.27 Found to occur in 3.27 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on P2 Important issues not at the top of the work list platform-web Web applications specifically team-design Owned by Design Languages team triaged-design Triaged by Design Languages team

Comments

@c-lucera-pvotal
Copy link

Steps to reproduce

  1. Run the following code with flutter run -d chrome
import 'package:flutter/material.dart';

void main() {
  runApp(
    MaterialApp(
      home: Scaffold(
        body: Center(
          child: SizedBox(
            height: 40,
            child: FilledButton(
              style: FilledButton.styleFrom(
                padding: const EdgeInsets.all(16),
              ),
              onPressed: () {},
              child: const Text("test"),
            ),
          ),
        ),
      ),
    ),
  );
}
  1. open a chrome window on the resulting url
  2. open a browser window on the resulting url with a iPhone simulator or an Android Emulator

Expected results

The two test button looks the same

Actual results

The two button looks really different.
The button text is visible on a chrome browser on macOS.
The button text is not visible on a chrome browser on iPhone/Android.

The mobile version is probably the correct one, with the text being cropped by the height constraint + big padding, but the debug was difficult be cause on desktop it looked good.
image

Code sample

Code sample
import 'package:flutter/material.dart';

void main() {
  runApp(
    MaterialApp(
      home: Scaffold(
        body: Center(
          child: SizedBox(
            height: 40,
            child: FilledButton(
              style: FilledButton.styleFrom(
                padding: const EdgeInsets.all(16),
              ),
              onPressed: () {},
              child: const Text("test"),
            ),
          ),
        ),
      ),
    ),
  );
}

Screenshots or Video

Screenshots / Video demonstration image

Logs

Logs

No interesting logs in the console

Performing hot restart...
Waiting for connection from debug service on Chrome...
Restarted application in 45ms.

Flutter Doctor output

Doctor output
[!] Flutter (Channel [user-branch], 3.22.0, on macOS 14.6.1 23G93 darwin-arm64,
    locale en-IT)
    ! Flutter version 3.22.0 on channel [user-branch] at
      /opt/homebrew/Caskroom/flutter/3.19.4/flutter
      Currently on an unknown channel. Run `flutter channel` to switch to an
      official channel.
      If that doesn't fix the issue, reinstall Flutter by following instructions
      at https://flutter.dev/docs/get-started/install.
    ! Upstream repository unknown source is not a standard remote.
      Set environment variable "FLUTTER_GIT_URL" to unknown source to dismiss
      this error.
    • Framework revision 5dcb86f68f (5 months ago), 2024-05-09 07:39:20 -0500
    • Engine revision f6344b75dc
    • Dart version 3.4.0
    • DevTools version 2.34.3
    • Pub download mirror
      https://pvotaltech.jfrog.io/artifactory/api/pub/pvotal-pub/
    • If those were intentional, you can disregard the above warnings; however
      it is recommended to use "git" directly to perform update checks and
      upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/clucera/Library/Android/sdk
    • Platform android-34, build-tools 33.0.0
    • Java binary at: /Applications/Android
      Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      17.0.7+0-17.0.7b1000.6-10550314)
    • All Android licenses accepted.

[!] Xcode - develop for iOS and macOS (Xcode 16.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16A242d
    ! iOS 18.0 Simulator not installed; this may be necessary for iOS and macOS
      development.
      To download and install the platform, open Xcode, select Xcode > Settings
      > Platforms,
      and click the GET button for the required platform.

      For more information, please visit:
        https://developer.apple.com/documentation/xcode/installing-additional-si
        mulator-runtimes
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.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
      17.0.7+0-17.0.7b1000.6-10550314)

[✓] IntelliJ IDEA Ultimate Edition (version 2023.1.6)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin version 78.2.1
    • Dart plugin version 231.9414.10

[✓] VS Code (version 1.88.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.90.0

[✓] Connected device (4 available)
    • iPhone 15 Pro Max (mobile)      • 7419A062-CAA2-4A3E-B7C1-4273A165C394 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-17-5 (simulator)
    • macOS (desktop)                 • macos                                • darwin-arm64   • macOS 14.6.1 23G93 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad                • darwin         • macOS 14.6.1 23G93 darwin-arm64
    • Chrome (web)                    • chrome                               • web-javascript • Google Chrome 129.0.6668.60

[✓] Network resources
    • All expected network resources are available.
@darshankawar darshankawar added the in triage Presently being triaged by the triage team label Sep 27, 2024
@darshankawar
Copy link
Member

Thanks for the report @c-lucera-pvotal
Can you take a look at #85729 to see if it resembles your case or not ?
See #85729 (comment) to check if it helps to resolve your issue or not.

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Sep 27, 2024
@c-lucera-pvotal
Copy link
Author

Hey @darshankawar
I don't think it is the same issue, that was more about the size of the button affected by the minimum tap target, and if you see their issue, they "solves" it by adding a sized box, like I did here in my solution that already wraps the button in a Sizedox to force the size, the issue here is more about the rendering on desktop that is not up to the expectations (it looks good, but it shouldn't) because the vertical padding should make the button text overflow (it happens correctly on mobile browser)

if you check the code, I have a button sized 40 in height, then I have a padding all of 16, this leaves only 8 (40, minus 16 top and 16 bottom) for the text, that should't be rendered, but it does, effectively masking any potential issue.

here another sample with a 40 sized button with a vertical padding of 20 (sums to 40) for some reason the text instead of being invisible, it is just moved a little to the bottom
image

SizedBox(
  height: 40,
  child: FilledButton(
    style: FilledButton.styleFrom(
      padding: const EdgeInsets.symmetric(vertical: 20),
    ),
    onPressed: () {},
    child: const Text("test"),
  ),
),

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Oct 7, 2024
@c-lucera-pvotal
Copy link
Author

The effect is even more visible by exagerating, in this case a 200 height button, with 100 vertical padding, and a ColoredBox wrapping the text, it shouldn't be visible at all, but in desktop chrome window it is renderer anyway

import 'package:flutter/material.dart';

void main() {
  runApp(
    MaterialApp(
      home: Scaffold(
        body: Center(
          child: SizedBox(
            height: 200,
            child: FilledButton(
              style: FilledButton.styleFrom(
                padding: const EdgeInsets.symmetric(vertical: 100),
              ),
              onPressed: () {},
              child: const ColoredBox(
                color: Colors.red,
                child: const Text("test"),
              ),
            ),
          ),
        ),
      ),
    ),
  );
}
image

@darshankawar
Copy link
Member

Thanks for the update. I see that the reported behavior also occurs on mobile and mobile browsers as compared to web and desktop wherein it renders properly.

https://github.com/flutter/flutter/blob/a6f3a1b8b4b9553e88ae51cb939ed7842a12edba/packages/flutter/lib/src/material/filled_button.dart#L460C29-L460C53 it shows ButtonStyle.padding is reduced from 24 to 16.

In your case,

padding: const EdgeInsets.all(16)

If this is reduced to less than 16, then it does render the text properly

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Oct 8, 2024
@c-lucera-pvotal
Copy link
Author

The thing here is that the reported behavior is not correctly rendered on desktop, it renders correctly on mobile, due to the excessive padding the text should be not visible, but testing on desktop gives a false negative because the text is visible even when it shouldn't
And yes, noticing now that it is not just desktop browser / mobile browser, but even on mobile platform it shows correctly, so probably is just desktop browser that render wrong?

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Oct 8, 2024
@darshankawar
Copy link
Member

Thanks for the update and your patience while we try to figure this out. Please see this issue and likely related to visual density difference between mobile, desktop and web platforms. See https://api.flutter.dev/flutter/material/VisualDensity-class.html to get more details and to know if it helps in your case as why it could be occuring.

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Oct 9, 2024
@c-lucera-pvotal
Copy link
Author

I don't think it is related, that will change the size of the button, and it is somewhat expected,

what is happening here, is that in desktop for some reason, the text appears even if it shouldn't,

I explain it better

we have a 200 sized height container, then we apply 100 padding top and 100 padding bottom, the space for the inner text becomes 0.

This should cause an overflow error, or at least render the content not visible, but in desktop for some reason this doesn't happens, leading to false negatives (looking the UI looks correct while it shouldn't) I can check later if fiddling with the VisualDensity in theme is related to this however.

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Oct 21, 2024
@darshankawar
Copy link
Member

Thanks for the update. Seeing the same behavior as reported with latest versions. Keeping this open for team's tracking.

Stable : 3.24.3
Master : 3.27.0-1.0.pre.120

@darshankawar darshankawar added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. has reproducible steps The issue has been confirmed reproducible and is ready to work on c: parity Works on one platform but not another team-design Owned by Design Languages team found in release: 3.24 Found to occur in 3.24 found in release: 3.27 Found to occur in 3.27 platform-web Web applications specifically and removed in triage Presently being triaged by the triage team labels Oct 22, 2024
@Piinks Piinks added triaged-design Triaged by Design Languages team P2 Important issues not at the top of the work list labels Oct 23, 2024
@Piinks Piinks added this to Nevercode Oct 23, 2024
@github-project-automation github-project-automation bot moved this to To do in Nevercode Oct 23, 2024
@Piinks Piinks added the d: api docs Issues with https://api.flutter.dev/ label Oct 23, 2024
@Piinks
Copy link
Contributor

Piinks commented Oct 23, 2024

May be related to #123528

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: parity Works on one platform but not another d: api docs Issues with https://api.flutter.dev/ f: material design flutter/packages/flutter/material repository. found in release: 3.24 Found to occur in 3.24 found in release: 3.27 Found to occur in 3.27 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on P2 Important issues not at the top of the work list platform-web Web applications specifically team-design Owned by Design Languages team triaged-design Triaged by Design Languages team
Projects
Status: To do
Development

No branches or pull requests

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy