Skip to content

Cupertino widgets don't adapt colors to Theme brightness in MaterialApp #100180

@evandrmb

Description

@evandrmb

Steps to Reproduce

  1. Set up a Flutter app theme like below
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:go_router/go_router.dart';
import 'package:timer/l10n/l10n.dart';
import 'package:timer/timer/timer.dart';

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

  @override
  Widget build(BuildContext context) {
    const primaryColor = Color.fromARGB(255, 97, 0, 92);
    const darkSurfaceColor = Color(0xFF121212);

    return MaterialApp.router(
      theme: ThemeData(
        scaffoldBackgroundColor: darkSurfaceColor,
        appBarTheme: const AppBarTheme(
          color: darkSurfaceColor,
          systemOverlayStyle: SystemUiOverlayStyle.light,
          elevation: 0,
        ),
        cardTheme: CardTheme(
          elevation: 0,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(6),
          ),
        ),
        colorScheme: ColorScheme.fromSwatch(
          brightness: Brightness.dark,
          primaryColorDark: primaryColor,
          accentColor: primaryColor,
        ),
      ),
      localizationsDelegates: const [
        AppLocalizations.delegate,
        GlobalMaterialLocalizations.delegate,
      ],
      supportedLocales: AppLocalizations.supportedLocales,
      routerDelegate: _router.routerDelegate,
      routeInformationParser: _router.routeInformationParser,
    );
  }

  final _router = GoRouter(
    routes: [
      GoRoute(
        path: '/',
        builder: (context, state) => const TimersPage(),
        routes: [
          GoRoute(
            path: 'new',
            builder: (context, state) => const NewTimerPage(),
          ),
        ],
      ),
    ],
  );
}
  1. Create a page like the one below
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:timer/l10n/l10n.dart';

const timePickerKey = Key('CupertinoTimePicker');

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

  @override
  Widget build(BuildContext context) {
    final l10n = context.l10n;

    return Scaffold(
      appBar: AppBar(
        title: Text(l10n.newTimerAppBarTitle),
      ),
      body: Padding(
        padding: const EdgeInsets.symmetric(horizontal: 16),
        child: Column(
          children: [
            CupertinoTimerPicker(
              key: timePickerKey,
              mode: CupertinoTimerPickerMode.hm,
              onTimerDurationChanged: (value) {},
            ),
            const SizedBox(height: 16),
            Card(
              elevation: 0,
              child: Column(
                children: const [
                  ListTile(),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Expected results:
It's expected that the text in CupertinoTimePicker will adapt to the dark theme and display a white label.

Actual results:
But only the numbers turn white.
image

Logs
Analyzing timer...                                                      
No issues found! (ran in 4.2s)
[✓] Flutter (Channel stable, 2.10.3, on macOS 12.1 21C52 darwin-arm, locale pt-BR)
    • Flutter version 2.10.3 at /Users/evandromb/development/.fvm/2.10.3
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 7e9793dee1 (13 days ago), 2022-03-02 11:23:12 -0600
    • Engine revision bd539267b4
    • Dart version 2.16.1
    • DevTools version 2.9.2

[!] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
    • Android SDK at /Users/evandromb/Library/Android/sdk
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more
      details.

[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.2

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

[✓] Android Studio (version 2021.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.11+0-b60-7772763)

[✓] VS Code (version 1.64.2)
    • VS Code at /Users/evandromb/Downloads/Visual Studio Code.app/Contents
    • Flutter extension version 3.37.20220301

[✓] Connected device (2 available)
    • iPhone 13 (mobile) • 711992C7-2CA3-4A2A-BB1F-BE78ED22BEE3 • ios            •
      com.apple.CoreSimulator.SimRuntime.iOS-15-2 (simulator)
    • Chrome (web)       • chrome                               • web-javascript •
      Google Chrome 99.0.4844.74

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

! Doctor found issues in 1 category.

Metadata

Metadata

Assignees

Labels

f: cupertinoflutter/packages/flutter/cupertino repositoryf: material designflutter/packages/flutter/material repository.found in release: 2.10Found to occur in 2.10found in release: 2.13Found to occur in 2.13frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer version

Type

No type

Projects

Status

Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions