Skip to content
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

RaisedButton's text is invisible in AlertDialog #30047

Closed
jul1u5 opened this issue Mar 27, 2019 · 3 comments
Closed

RaisedButton's text is invisible in AlertDialog #30047

jul1u5 opened this issue Mar 27, 2019 · 3 comments
Labels
f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Comments

@jul1u5
Copy link

jul1u5 commented Mar 27, 2019

Flutter version: latest stable (v1.2.1)

The issue occurs when trying to use RaisedButton in AlertDialog actions. The background color of the button and the text color are the same, and thus the text is not visible. Of course, it's possible to manually change the textTheme or textColor of the particular button, but that's undesirable, the default shouldn't be unusable.

Might be related to #22789

Steps to Reproduce

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return AlertDialog(
      title: Text('Dialog title'),
      content: Text('Dialog content'),
      actions: <Widget>[
        FlatButton(
          child: Text('FLAT'),
          onPressed: () {},
        ),
        RaisedButton(
          child: Text('RAISED'),
          onPressed: () {},
        )
      ],
    );
  }
}

image

I believe the background color of the button is correct, but the text color should be white.

The issue can also be reproduced with the ButtonTheme.bar constructor, which AlertDialog uses to wrap actions. Even simpler example:

ButtonTheme.bar(
  child: RaisedButton(
    child: Text('RAISED'),
    onPressed: () {},
  ),
);

Perhaps RaisedButton should behave differently with ButtonTextTheme.accent.

@jul1u5
Copy link
Author

jul1u5 commented Mar 27, 2019

I would suggest that the ButtonThemeData.getTextColor method should take into account the type of the button when dealing with ButtonTextTheme.accent.

A naive solution (commented out return colorScheme.secondary):

  Color getTextColor(MaterialButton button) {
    if (!button.enabled)
      return getDisabledTextColor(button);

    if (button.textColor != null)
      return button.textColor;

    switch (getTextTheme(button)) {
      case ButtonTextTheme.normal:
        return getBrightness(button) == Brightness.dark ? Colors.white : Colors.black87;

      case ButtonTextTheme.accent:
        // return colorScheme.secondary;

      case ButtonTextTheme.primary: {
        final Color fillColor = getFillColor(button);
        final bool fillIsDark = fillColor != null
          ? ThemeData.estimateBrightnessForColor(fillColor) == Brightness.dark
          : getBrightness(button) == Brightness.dark;
        if (fillIsDark)
          return Colors.white;
        if (button is FlatButton || button is OutlineButton)
          return colorScheme.primary;
        return Colors.black;
      }
    }

    assert(false);
    return null;
  }

image

EDIT: The text of MaterialButton is not visible with this solution.

@HansMuller HansMuller added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Mar 27, 2019
@TahaTesser
Copy link
Member

Hi @jul1u5
Looks like this is fixed and raised button is grey with visible by default

flutter_02

`flutter doctor -v`
[✓] Flutter (Channel dev, v1.18.0, on Mac OS X 10.15.4 19E266, locale en-GB)
    • Flutter version 1.18.0 at /Users/taha/Code/flutter_dev
    • Framework revision 8f7327f83a (31 hours ago), 2020-04-06 22:11:01 -0400
    • Engine revision 49891e0653
    • Dart version 2.8.0 (build 2.8.0-dev.20.0 1210d27678)
 
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at /Users/taha/Code/sdk
    • Platform android-29, build-tools 29.0.3
    • ANDROID_HOME = /Users/taha/Code/sdk
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      1.8.0_212-release-1586-b4-5784211)
    • All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.4, Build version 11E146
    • CocoaPods version 1.9.1
[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 3.6)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 45.0.1
    • Dart plugin version 192.7761
    • Java version OpenJDK Runtime Environment (build
      1.8.0_212-release-1586-b4-5784211)
[✓] VS Code (version 1.43.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.9.1
[✓] Connected device (4 available)
    • SM M305F   • 32003c30dc19668f • android-arm64  • Android 10 (API 29)
    • macOS      • macOS            • darwin-x64     • Mac OS X 10.15.4 19E266
    • Chrome     • chrome           • web-javascript • Google Chrome
      80.0.3987.149
    • Web Server • web-server       • web-javascript • Flutter Tools
• No issues found!

if you disagree please write in the comments and I will reopen it
Thank you

@lock
Copy link

lock bot commented Apr 25, 2020

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.

@lock lock bot locked and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

No branches or pull requests

3 participants