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

buttonTheme not working #48299

Closed
psygo opened this issue Jan 7, 2020 · 5 comments
Closed

buttonTheme not working #48299

psygo opened this issue Jan 7, 2020 · 5 comments
Labels
a: quality A truly polished experience f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on

Comments

@psygo
Copy link

psygo commented Jan 7, 2020

Use case

This might be related to what's discussed on Issues #19623 and #29050, though they are much longer discussions.

I'm trying to create a Button Material Theme for my app, but at least one attribute of buttonTheme is not acting the way I would expect, namely buttonColor.

Other attributes, like height or shape, take an immediate effect on all of my buttons, however, buttonColor simply doesn't do anything, and I can't even access it as an attribute from within my app's widgets.

In my main.dart:

child: MaterialApp(
  ...
  theme: ThemeData(
    buttonTheme: ButtonThemeData(
      buttonColor: Colors.red,
    ),
  ),
),

In one of my screens, I have a regular FlatButton, which does not get an alterations from tinkering the buttonColor. As a workaround, I have created a colorScheme for my buttonTheme and then I access it within the FlatButton:

FlatButton(
  ...
  color: Theme.of(context).buttonTheme.colorScheme.background,
),

I find it strange that I can't access the buttonTheme's buttonColor property from the button, but can access the colorScheme property.

Why is it that in the ButtonThemeData documentation there are many properties in the constructor which can't be accessed later on as properties? Is this a mistake or maybe some sort of different API to what I'm used to?

Proposal

The obvious proposal would be to have the buttonColor work as the other ThemeData (sub)properties.

However, it seems to make sense to also add a way of accessing the buttonColor as a property, e.g. color: Theme.of(context).buttonTheme.buttonColor.

@HansMuller HansMuller added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Jan 7, 2020
@TahaTesser
Copy link
Member

Could be related #38655

@TahaTesser
Copy link
Member

Issue exist

Code Sample

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Material App',
      theme: ThemeData(
        buttonTheme: ButtonThemeData(
          buttonColor: Colors.red,
        ),
      ),
      home: Scaffold(
        appBar: AppBar(
          title: Text('Material App Bar'),
        ),
        body: Center(
          child: FlatButton(
            color: Theme.of(context).buttonTheme.colorScheme.background,
            onPressed: () {},
            child: Text('Press'),
          ),
        ),
      ),
    );
  }
}

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!

@TahaTesser TahaTesser added a: quality A truly polished experience has reproducible steps The issue has been confirmed reproducible and is ready to work on labels Apr 8, 2020
@HansMuller
Copy link
Contributor

@psygo it's been a while since you opened this issue and I apologize for the lack of activity. If you're still interested in the topic, there's a wide-ranging proposal for updating the button widgets and their themes in #54776. The new proposal addresses the problems with overriding the default button foreground (text) or background colors.

I'm going to close this issue in favor of #54776.

@psygo
Copy link
Author

psygo commented Apr 15, 2020

Nice to know that there's active development on these basic widgets. Issue #54776 sure seems interesting. Good luck to you and the rest of the Flutter team.

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: quality A truly polished experience f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on
Projects
None yet
Development

No branches or pull requests

3 participants