Skip to content

BUG: Elevated / Text / Outline Buttons - minimumSize not respected properly when visual density is not standard #123528

@AlexDochioiu

Description

@AlexDochioiu

Steps to Reproduce

  1. Execute flutter run on the code sample

Expected results: All buttons and red container should have same height

Actual results: Buttons with VisualDensity compact and comfortable have a smaller height compared to the explicitly specified minimum height.

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

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(primarySwatch: Colors.blue),
      home: const StlessHomePage(),
    );
  }
}

class StlessHomePage extends StatelessWidget {
  const StlessHomePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    const minHeight = 80.0;
    final buttonStyle = ElevatedButton.styleFrom(
      minimumSize: const Size(100, minHeight),
    );
    final standardButtonStyle = buttonStyle.copyWith(visualDensity: VisualDensity.standard);
    final comfortableButtonStyle = buttonStyle.copyWith(visualDensity: VisualDensity.comfortable);
    final compactButtonStyle = buttonStyle.copyWith(visualDensity: VisualDensity.compact);
    return Scaffold(
      appBar: AppBar(title: const Text('HomePage')),
      body: Center(
        child: Row(
          children: [
            const Spacer(),
            Container(width: 20, height: minHeight, color: Colors.red),
            ElevatedButton(style: standardButtonStyle, onPressed: () {}, child: const Text("Standard")),
            ElevatedButton(style: comfortableButtonStyle, onPressed: () {}, child: const Text("Comfortable")),
            ElevatedButton(style: compactButtonStyle, onPressed: () {}, child: const Text("Compact")),
            const Spacer(),
          ],
        ),
      ),
    );
  }
}
Logs
➜  bug_reporting_project flutter doctor -v
[✓] Flutter (Channel stable, 3.7.8, on macOS 13.2.1 22D68 darwin-arm64, locale en-GB)
    • Flutter version 3.7.8 on channel stable at /Users/alexandrudochioiu/.asdf/installs/flutter/3.7.8-stable
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 90c64ed42b (6 days ago), 2023-03-21 11:27:08 -0500
    • Engine revision 9aa7816315
    • Dart version 2.19.5
    • DevTools version 2.20.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /Users/alexandrudochioiu/Library/Android/sdk
    • Platform android-33, build-tools 33.0.1
    • ANDROID_HOME = /Users/alexandrudochioiu/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14C18
    • CocoaPods version 1.12.0

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

[✓] Android Studio (version 2022.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 11.0.15+0-b2043.56-8887301)

[✓] IntelliJ IDEA Community Edition (version 2022.3.2)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • 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

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

[✓] Connected device (3 available)
    • 2201116TG (mobile) • LN7DPFJ7MNZXPFFA • android-arm64  • Android 12 (API 31)
    • macOS (desktop)    • macos            • darwin-arm64   • macOS 13.2.1 22D68 darwin-arm64
    • Chrome (web)       • chrome           • web-javascript • Google Chrome 111.0.5563.110

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listd: api docsIssues with https://api.flutter.dev/f: material designflutter/packages/flutter/material repository.found in release: 3.7Found to occur in 3.7found in release: 3.9Found to occur in 3.9frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages teamworkaround availableThere is a workaround available to overcome the issue

Type

No type

Projects

Status

Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions