Visitar URL original
Unexpected behaviour with ColorScheme.fromSeed and Brightness.dark · Issue #127523 · flutter/flutter · GitHub
Skip to content

Unexpected behaviour with ColorScheme.fromSeed and Brightness.dark #127523

Closed

Description

@polilluminato

Is there an existing issue for this?

Steps to reproduce

  • Create a new Flutter project
  • Inside the MaterialApp -> ThemeData change the brightness from Brightness.light to Brightness.dark
  • Launch the app

Expected results

The app launches correctly without issues.

Actual results

The Debug Console shows this error:

════════ Exception caught by widgets library ═══════════════════════════════════
The following assertion was thrown building MyApp(dirty):
'package:flutter/src/material/theme_data.dart': Failed assertion: line 459 pos 12: 'colorScheme?.brightness == null || brightness == null || colorScheme!.brightness == brightness': is not true.
theme_data.dart:459

The relevant error-causing widget was
MyApp
main.dart:4
When the exception was thrown, this was the stack
#2      new ThemeData
theme_data.dart:459
#3      MyApp.build
main.dart:14
#4      StatelessElement.build
framework.dart:5156
#5      ComponentElement.performRebuild
framework.dart:5086
#6      Element.rebuild
framework.dart:4805
#7      BuildOwner.buildScope
framework.dart:2780
#8      WidgetsBinding.drawFrame
binding.dart:903
#9      RendererBinding._handlePersistentFrameCallback
binding.dart:358
#10     SchedulerBinding._invokeFrameCallback
binding.dart:1284
#11     SchedulerBinding.handleDrawFrame
binding.dart:1214
#12     SchedulerBinding.scheduleWarmUpFrame.<anonymous closure>
binding.dart:939
#16     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:189:12)

Code sample

This code works:

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
        brightness: Brightness.light,
      ),
      home: Container(),
    );
  }
}

This code does NOT work:

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
        brightness: Brightness.dark,
      ),
      home: Container(),
    );
  }
}

This code works:

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorSchemeSeed: Colors.deepPurple,
        useMaterial3: true,
        brightness: Brightness.light,
      ),
      home: Container(),
    );
  }
}

This code works:

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorSchemeSeed: Colors.deepPurple,
        useMaterial3: true,
        brightness: Brightness.dark,
      ),
      home: Container(),
    );
  }
}

Issue

  • If I use colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple) It works only with brightness: Brightness.light but not with brightness: Brightness.dark
  • If I use colorSchemeSeed: Colors.deepPurple It works with both brightness: Brightness.light and brightness: Brightness.dark

Flutter Doctor output

[✓] Flutter (Channel stable, 3.10.1, on Fedora Linux 37 (KDE Plasma) 6.2.15-200.fc37.x86_64, locale it_IT.UTF-8)
    • Flutter version 3.10.1 on channel stable at /home/alberto/tools/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision d3d8effc68 (8 giorni fa), 2023-05-16 17:59:05 -0700
    • Engine revision b4fb11214d
    • Dart version 3.0.1
    • DevTools version 2.23.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /home/alberto/Android/Sdk
    • Platform android-33-ext4, build-tools 33.0.2
    • Java binary at: /home/alberto/.local/share/JetBrains/Toolbox/apps/AndroidStudio/ch-0/222.4459.24.2221.9971841/jbr/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • CHROME_EXECUTABLE = /opt/brave.com/brave/brave-browser

[✓] Linux toolchain - develop for Linux desktop
    • clang version 15.0.7 (Fedora 15.0.7-2.fc37)
    • cmake version 3.26.4
    • ninja version 1.10.2
    • pkg-config version 1.8.0

[✓] Android Studio (version 2022.2)
    • Android Studio at /home/alberto/.local/share/JetBrains/Toolbox/apps/AndroidStudio/ch-0/222.4459.24.2221.9971841
    • 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.6+0-17.0.6b802.4-9586694)

[✓] IntelliJ IDEA Community Edition (version 2023.1)
    • IntelliJ at /home/alberto/.local/share/JetBrains/Toolbox/apps/IDEA-C/ch-0/231.8770.65
    • 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

[✓] VS Code (version 1.78.2)
    • VS Code at /usr/share/code
    • Flutter extension version 3.64.0

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • Fedora Linux 37 (KDE Plasma) 6.2.15-200.fc37.x86_64
    • Chrome (web)    • chrome • web-javascript • Brave Browser 113.1.51.118

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

• No issues found!

Activity

  1. added
    in triagePresently being triaged by the triage team
    on May 25, 2023
  2. huycozy commented on May 25, 2023

    @huycozy
    Member

    Thanks for your report. This issue is reproducible on the latest stable and master channels.

    For more information about the last condition from the failed assertion (colorScheme!.brightness == brightness):

    Brightness brightness = Brightness.light,

    It is in conflict with brightness: Brightness.dark from ThemeData.

    flutter doctor -v (stable and master)
    [✓] Flutter (Channel stable, 3.10.2, on macOS 13.0.1 22A400 darwin-x64, locale en-VN)
        • Flutter version 3.10.2 on channel stable at /Users/huynq/Documents/GitHub/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 9cd3d0d9ff (22 hours ago), 2023-05-23 20:57:28 -0700
        • Engine revision 90fa3ae28f
        • Dart version 3.0.2
        • DevTools version 2.23.1
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
        • Android SDK at /Users/huynq/Library/Android/sdk
        • Platform android-33, build-tools 32.0.0
        • ANDROID_HOME = /Users/huynq/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 14.3)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 14E222b
        • CocoaPods version 1.11.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2022.2)
        • 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.6+0-17.0.6b802.4-9586694)
    
    [✓] VS Code (version 1.78.1)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.64.0
    
    [✓] Connected device (3 available)
        • RMX2001 (mobile) • EUYTFEUSQSRGDA6D • android-arm64  • Android 11 (API 30)
        • macOS (desktop)  • macos            • darwin-x64     • macOS 13.0.1 22A400 darwin-x64
        • Chrome (web)     • chrome           • web-javascript • Google Chrome 113.0.5672.126
    
    [✓] Network resources
        • All expected network resources are available.
    
    • No issues found!
    [!] Flutter (Channel master, 3.11.0-13.0.pre.20, on macOS 13.0.1 22A400 darwin-x64, locale en-VN)
        • Flutter version 3.11.0-13.0.pre.20 on channel master at /Users/huynq/Documents/GitHub/flutter_master
        ! Warning: `flutter` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
        ! Warning: `dart` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 5eacfe62bd (22 minutes ago), 2023-05-24 21:47:08 -0400
        • Engine revision 1bed04a437
        • Dart version 3.1.0 (build 3.1.0-142.0.dev)
        • DevTools version 2.23.1
        • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
        • Android SDK at /Users/huynq/Library/Android/sdk
        • Platform android-33, build-tools 32.0.0
        • ANDROID_HOME = /Users/huynq/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 14.3)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 14E222b
        • CocoaPods version 1.11.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2022.2)
        • 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.6+0-17.0.6b802.4-9586694)
    
    [✓] VS Code (version 1.78.1)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.64.0
    
    [✓] Connected device (3 available)
        • RMX2001 (mobile) • EUYTFEUSQSRGDA6D • android-arm64  • Android 11 (API 30)
        • macOS (desktop)  • macos            • darwin-x64     • macOS 13.0.1 22A400 darwin-x64
        • Chrome (web)     • chrome           • web-javascript • Google Chrome 113.0.5672.126
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 1 category.
  3. added
    c: crashStack traces logged to the console
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    in triagePresently being triaged by the triage team
    on May 25, 2023
  4. self-assigned this
    on May 31, 2023
  5. HansMuller commented on May 31, 2023

    @HansMuller
    Contributor

    @huycozy is correct. To correct a dark color scheme (dark theme) you need to override the color scheme's brightness parameter:

    import 'package:flutter/material.dart';
    
    void main() {
      runApp(const MyApp());
    }
    
    class MyApp extends StatelessWidget {
      const MyApp({super.key});
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(
            colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple, brightness: Brightness.dark),
            useMaterial3: true,
          ),
          home: Container(),
        );
      }
    }
  6. added
    ⏳Bot is counting down the days until it unassigns the issue
    on Oct 18, 2023
  7. flutter-triage-bot commented on Oct 18, 2023

    @flutter-triage-bot

    This issue is assigned to @HansMuller but has had no recent status updates. Please consider unassigning this issue if it is not going to be addressed in the near future. This allows people to have a clearer picture of what work is actually planned. Thanks!

  8. added
    P2Important issues not at the top of the work list
    on Oct 23, 2023
  9. removed
    ⏳Bot is counting down the days until it unassigns the issue
    on Oct 23, 2023
  10. moved this from To do to In progress in Nevercodeon Oct 31, 2023
  11. moved this from In progress to PR submitted in Nevercodeon Oct 31, 2023
  12. moved this from PR submitted to Done (PR merged) in Nevercodeon Nov 6, 2023
  13. added
    r: fixedIssue is closed as already fixed in a newer version
    on Nov 6, 2023
  14. github-actions commented on Nov 20, 2023

    @github-actions

    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.

  15. locked as resolved and limited conversation to collaborators on Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listc: crashStack traces logged to the consolefound in release: 3.10Found to occur in 3.10found in release: 3.11Found to occur in 3.11frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesr: fixedIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

Type

No type

Projects

  • Status
    Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions