Skip to content

CupertinoButton's child text does not apply primaryContrastingColor anymore #161590

@vizakenjack

Description

@vizakenjack

Steps to reproduce

  1. Create a CupertinoApp with default values.
  2. Place a CupertinoButton with a custom background color, for example: CupertinoColors.systemPurple.
  3. Check out the text's color.

Expected results

The text on the button should use primaryContrastingColor, its white by default

Actual results

The text of the CupertinoButton does not apply primaryContrastingColor and instead uses primaryColor.

Why it should be fixed:

  1. This is a breaking change and is not easy to address in a production app after the Flutter 3.27 upgrade.
  2. There is no color: argument in the CupertinoButton.filled constructor, and it only applies primaryColor.
  3. Consequently, there is no straightforward way to create a purple CupertinoButton with white text.

How it can be fixed:

  • Restore the default behavior for CupertinoButton.
  • Alternatively, add a color argument to the CupertinoButton.filled constructor.

Code sample

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

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

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

  @override
  Widget build(BuildContext context) {
    return CupertinoApp(
      home: MyHomePage(title: 'Test'),
      supportedLocales: const [Locale('en')],
      localizationsDelegates: const [
        DefaultMaterialLocalizations.delegate,
        DefaultCupertinoLocalizations.delegate,
        DefaultWidgetsLocalizations.delegate,
      ],
      locale: const Locale('en'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return CupertinoPageScaffold(
      child: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            CupertinoButton(
              color: CupertinoColors.systemPurple,
              child: Text('Click Me'),
              onPressed: () {
                print('Test');
              },
            ),
          ],
        ),
      ),
    );
  }
}

Screenshots or Video

Flutter 3.24 screenshot

Image

Flutter 3.27 screenshot

Image

Logs

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.27.1, on macOS 15.1.1 24B91 darwin-arm64, locale en-RU)
    • Flutter version 3.27.1 on channel stable at /Users/jack/Applications/fvm/versions/3.27.1
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 17025dd882 (4 weeks ago), 2024-12-17 03:23:09 +0900
    • Engine revision cb4b5fff73
    • Dart version 3.6.0
    • DevTools version 2.40.2

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/me/Library/Android/sdk
    • Platform android-34, build-tools 34.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.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16B40
    • CocoaPods version 1.15.0

[✓] 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)

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

[✓] Connected device (4 available)
    • iPhone 13 mini 18.1 (mobile)    • 011A6845-5B18-4765-AEDA-216A8A873621 • ios          • com.apple.CoreSimulator.SimRuntime.iOS-18-1 (simulator)
    • macOS (desktop)                 • macos                                • darwin-arm64 • macOS 15.1.1 24B91 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad                • darwin       • macOS 15.1.1 24B91 darwin-arm64

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listf: cupertinoflutter/packages/flutter/cupertino repositoryfound in release: 3.27Found to occur in 3.27found in release: 3.28Found to occur in 3.28frameworkflutter/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 team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions