Skip to content

TextButton.styleFrom() WidgetStateProperty.all(Colors.transparent) #170208

Closed as not planned
@Lybell

Description

@Lybell

Steps to reproduce

Okay, this is a very interesting development.You're saying that if you revert your login.dart to this older version, the TextButton for "Forgot Password" with this style works without the analyzer error:But when you were trying to use TextButton.styleFrom() (as we were discussing, and as used in the minimal test case), you were getting the error:And crucially, the minimal test project also failed with TextButton.styleFrom().This points to a very specific issue, likely a bug or an unexpected behavior related to TextButton.styleFrom() in your current Flutter version (3.32.2) and Dart (3.8.1) combination on your specific system setup.Here's why this is a plausible explanation:1.TextButton.styleFrom() vs. ButtonStyle():•TextButton.styleFrom(...) is a convenience constructor that creates a ButtonStyle object. It's meant to simplify the creation of common button styles.•ButtonStyle(...) is the direct constructor for the ButtonStyle class.•Internally, TextButton.styleFrom() takes its arguments and maps them to the corresponding properties of a ButtonStyle object.2.The Error Persisting in a New Project: The fact that TextButton.styleFrom() with overlayColor failed even in a brand new, minimal project is the strongest indicator that the problem is not with your project's specific code (like themes, other widgets, etc.) but with how TextButton.styleFrom() itself is being interpreted or processed by the Dart analyzer or the Flutter framework in your environment.3.Why ButtonStyle() Might Work: If ButtonStyle(overlayColor: WidgetStateProperty.all(Colors.transparent)) works, it means the fundamental mechanism of assigning a WidgetStateProperty to ButtonStyle.overlayColor is fine. The problem seems to be one layer of abstraction up, specifically with the TextButton.styleFrom() helper.Possible Explanations for the Discrepancy:•Subtle Bug in TextButton.styleFrom() Implementation (Specific Version): There might be a subtle bug in how TextButton.styleFrom() handles or types the overlayColor parameter (or how it merges with default/theme styles) in Flutter 3.32.2 that doesn't manifest when you construct ButtonStyle directly.•Analyzer Misinterpretation of TextButton.styleFrom() Signature: The Dart analyzer in your environment might be incorrectly interpreting the signature or the return type logic of TextButton.styleFrom() for overlayColor, leading it to expect Color? instead of allowing WidgetStateProperty<Color?>.•Interaction with Default Theming: TextButton.styleFrom() also intelligently merges with the TextButtonThemeData from your current Theme. It's possible that this merging logic has an issue in your version that is bypassed when you use ButtonStyle() directly (as direct ButtonStyle might have slightly different merging behavior or precedence).Recommendations:1.Use ButtonStyle() as a Workaround: Since ButtonStyle(overlayColor: WidgetStateProperty.all(Colors.transparent)) works in your old login page code, this is your immediate and effective workaround. Continue using this direct ButtonStyle approach for the "Forgot Password" TextButton and any other TextButton where you encounter this issue.2.Consider Reporting the Issue (Still): Even though you have a workaround, the fact that TextButton.styleFrom() failed in a minimal test project with a clean flutter doctor is worth reporting to the Flutter team. This could be a genuine, albeit perhaps subtle, bug in that specific version.•Go to: https://github.com/flutter/flutter/issues•Provide:•Your flutter doctor -v output.•The minimal main.dart code that used TextButton.styleFrom() and failed.•The exact error message.•Mention that using ButtonStyle() directly with the same WidgetStateProperty works as expected.•Your OS and Flutter/Dart versions.3.Test Future Flutter Versions: When you eventually upgrade Flutter to a newer stable version, re-test the TextButton.styleFrom() approach in a minimal project. The issue might get resolved in a future release.Why this is a good resolution path for now:•It unblocks you and allows your code to work correctly.•It isolates the problem to a specific Flutter API helper (TextButton.styleFrom()) rather than a widespread issue with your entire environment or project.It's a relief to know that the direct ButtonStyle() works! This strongly refines where the problem lies. The previous diagnostic steps were crucial to arrive at this point and rule out broader environmental issues.

Expected results

Subtle Bug in TextButton.styleFrom() Implementation (Specific Version): There might be a subtle bug in how TextButton.styleFrom() handles or types the overlayColor parameter (or how it merges with default/theme styles) in Flutter 3.32.2 that doesn't manifest when you construct ButtonStyle directly.

// This was causing the error, even in the minimal test
TextButton(
  style: TextButton.styleFrom( // <--- Using the convenience constructor
    overlayColor: WidgetStateProperty.all(Colors.transparent)
  ),
  // ...
)

Actual results

WidgetStateProperty.all(Colors.transparent) gives an error that WidgetStateProperty.all<Color> cannot be assigned to <Color>

Code sample

// This was causing the error, even in the minimal test
TextButton(
  style: TextButton.styleFrom( // <--- Using the convenience constructor
    overlayColor: WidgetStateProperty.all(Colors.transparent)
  ),
  // ...
)

and workaround is

TextButton(
  style: ButtonStyle( // <--- Using ButtonStyle directly
    overlayColor: WidgetStateProperty.all(Colors.transparent)
  ),
  onHover: (val) { // ...

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Launching lib\main.dart on Chrome in debug mode...
Waiting for connection from debug service on Chrome...
lib/main.dart:20:49: Error: The argument type 'WidgetStateProperty<Color?>' can't be assigned to the parameter type 'Color?'.
 - 'WidgetStateProperty' is from 'package:flutter/src/widgets/widget_state.dart' ('/C:/src/flutter/packages/flutter/lib/src/widgets/widget_state.dart').
 - 'Color' is from 'dart:ui'.
              overlayColor: WidgetStateProperty.all<Color?>(Colors.transparent),

Flutter Doctor output

PowerShell 7.5.1
~\StudioProjects\local_work_market
flutter doctor -v
[√] Flutter (Channel stable, 3.32.2, on Microsoft Windows [Version 10.0.26100.4202], locale en-CA) [380ms]
    • Flutter version 3.32.2 on channel stable at C:\src\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 8defaa71a7 (3 days ago), 2025-06-04 11:02:51 -0700
    • Engine revision 1091508939
    • Dart version 3.8.1
    • DevTools version 2.45.1

[√] Windows Version (11 Pro 64-bit, 24H2, 2009) [1,341ms]

[√] Android toolchain - develop for Android devices (Android SDK version 35.0.1) [2.6s]
    • Android SDK at C:\Users\steve\AppData\Local\Android\Sdk
    • Platform android-35, build-tools 35.0.1
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.6+-13368085-b895.109)
    • All Android licenses accepted.

[√] Chrome - develop for the web [126ms]
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Build Tools 2019 16.11.34) [125ms]
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools
    • Visual Studio Build Tools 2019 version 16.11.34601.136
    • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 2024.3.2) [18ms]
    • Android Studio at C:\Program Files\Android\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 21.0.6+-13368085-b895.109)

[√] Connected device (3 available) [167ms]
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.26100.4202]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 137.0.7151.69
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 137.0.3296.68

[√] Network resources [618ms]
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    r: invalidIssue is closed as not valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions