BirjuVachhani / adaptive_theme

Easiest way to add support for light and dark theme in your flutter app.
https://pub.dev/packages/adaptive_theme
Apache License 2.0
464 stars 37 forks source link

Runtime error #22

Closed detzioni closed 3 years ago

detzioni commented 3 years ago

Trying to run the example application on an Android phone, I am getting the following error:

"package:flutter/src/ material/theme_data.dart': Failed assertion: line 346 pos 12: colorScheme?.brightness == null || brightness I| colorScheme!.brightness = brightness': is not true. See also: https://flutter.dev/docs /testing/errorS == null

To Reproduce Just download the package from github, and run [flutter create .] follow by [flutter run]

Screenshotsimage

Smartphone (please complete the following information):

BirjuVachhani commented 3 years ago

@detzioni I tested it on web and Oneplus Android 11 and everything seems to be working fine. I am on Flutter stable channel. Could you please post stacktrace and output of flutter doctor -v?

detzioni commented 3 years ago

Thank you for your quick response. As requested, here is the output of [flutter doctor -v]

[✓] Flutter (Channel master, 2.4.0-5.0.pre.122, on macOS 11.5 20G71 darwin-x64, locale en-US) • Flutter version 2.4.0-5.0.pre.122 at /Users/up/Development/Flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 5acf7e98f1 (7 days ago), 2021-07-20 19:58:58 -0700 • Engine revision 9b270621e4 • Dart version 2.14.0 (build 2.14.0-338.0.dev)

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0) • Android SDK at /Users/up/Library/Android/sdk • Platform android-31, build-tools 31.0.0 • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264) • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 12.5.1, Build version 12E507 • CocoaPods version 1.10.1

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

[✓] Android Studio (version 4.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 11.0.8+10-b944.6916264)

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

[✓] Connected device (5 available) • SM T377T (mobile) • 520351fc494a5445 • android-arm • Android 7.1.1 (API 25) (emulator) • SM G955U (mobile) • 9889db374653585145 • android-arm64 • Android 9 (API 28) • SM A505F (mobile) • R58M36PRCDL • android-arm64 • Android 11 (API 30) • macOS (desktop) • macos • darwin-x64 • macOS 11.5 20G71 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 92.0.4515.107

• No issues found!

detzioni commented 3 years ago

Changing the channel from master to stable, running the [flutter clean] and [flutter pub get], the [flutter doctor -v] output is:

[✓] Flutter (Channel stable, 2.2.3, on macOS 11.5 20G71 darwin-x64, locale en-US) • Flutter version 2.2.3 at /Users/up/Development/Flutter • Framework revision f4abaa0735 (4 weeks ago), 2021-07-01 12:46:11 -0700 • Engine revision 241c87ad80 • Dart version 2.13.4

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0) • Android SDK at /Users/up/Library/Android/sdk • Platform android-31, build-tools 31.0.0 • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264) • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 12.5.1, Build version 12E507 • CocoaPods version 1.10.1

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

[✓] Android Studio (version 4.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 11.0.8+10-b944.6916264)

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

[✓] Connected device (5 available) • SM T377T (mobile) • 520351fc494a5445 • android-arm • Android 7.1.1 (API 25) (emulator) • SM G955U (mobile) • 9889db374653585145 • android-arm64 • Android 9 (API 28) • SM A505F (mobile) • R58M36PRCDL • android-arm64 • Android 11 (API 30) • macOS (desktop) • macos • darwin-x64 • macOS 11.5 20G71 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 92.0.4515.107

• No issues found!

Now when running the [flutter run] connecting to Android device, I am getting the same error

BirjuVachhani commented 3 years ago

@detzioni This is weird. I thought it could have happened because of the Flutter master branch. Maybe something changed! But that doesn't seem to be the case here.

I'll look into this once I get some time but I do not own a Samsung phone so I need to verify if this is a device specific issue or not. Could you please check following and update me here?

  1. Try running on an emulator if you could and check if it runs or not.
  2. Try checking the same on an iOS simulator.
  3. Try running on web.
  4. Try running on other Android phone if you have any.
  5. Try running on your desktop if possible.

Can you also provide complete stack trace as well?

As this library doesn't anything platform related and doesn't use sensitive classes of the SDK, If it is working on 1 platform, it should work on others as well.

detzioni commented 3 years ago

Yes, I totally agree with you. This is weird. I got the same problem in the application that I am trying to migrate to null-safety, so I decided to just run your example to see what happen.

As you requested I run it on multiple devices and simulators and all of them fail with the same error.

See the outputs below:


Flutter doctor -v


[✓] Flutter (Channel stable, 2.2.3, on macOS 11.5.1 20G80 darwin-x64, locale en-US) • Flutter version 2.2.3 at /Users/up/Development/Flutter • Framework revision f4abaa0735 (4 weeks ago), 2021-07-01 12:46:11 -0700 • Engine revision 241c87ad80 • Dart version 2.13.4

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0) • Android SDK at /Users/up/Library/Android/sdk • Platform android-31, build-tools 31.0.0 • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264) • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 12.5.1, Build version 12E507 • CocoaPods version 1.10.1

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

[✓] Android Studio (version 4.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 11.0.8+10-b944.6916264)

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

[✓] Connected device (6 available) • SM T377T (mobile) • 520351fc494a5445 • android-arm • Android 7.1.1 (API 25) (emulator) • SM G955U (mobile) • 9889db374653585145 • android-arm64 • Android 9 (API 28) • SM A505F (mobile) • R58M36PRCDL • android-arm64 • Android 11 (API 30) • iPhone 12 Pro Max (mobile) • 94DE795C-2673-4016-AC61-25E1C8366806 • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-5 (simulator) • macOS (desktop) • macos • darwin-x64 • macOS 11.5.1 20G80 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 92.0.4515.107

• No issues found!


Running on iOS simulator iPhone 12 Pro Max


══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ The following assertion was thrown building MaterialExample(dirty): 'package:flutter/src/material/theme_data.dart': Failed assertion: line 316 pos 12: 'colorScheme?.brightness == null || brightness == null || colorScheme!.brightness == brightness': is not true.

The relevant error-causing widget was: MaterialExample file:///Users/up/Development/samples/adaptive_theme/example/lib/main.dart:31:13

When the exception was thrown, this was the stack:

2 new ThemeData (package:flutter/src/material/theme_data.dart:316:12)

3 MaterialExample.build (package:example/material_example.dart:22:13)

4 StatelessElement.build (package:flutter/src/widgets/framework.dart:4648:28)

5 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4574:15)

6 Element.rebuild (package:flutter/src/widgets/framework.dart:4267:5)

7 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4553:5)

8 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4548:5)

... Normal element mounting (10 frames)

18 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3611:14)

19 MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6221:36)

20 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6232:32)

... Normal element mounting (17 frames)

37 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3611:14)

38 Element.updateChild (package:flutter/src/widgets/framework.dart:3363:18)

39 RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1189:16)

40 RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:1159:5)

41 RenderObjectToWidgetAdapter.attachToRenderTree. (package:flutter/src/widgets/binding.dart:1104:18)

42 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2535:19)

43 RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:1103:13)

44 WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:937:7)

45 WidgetsBinding.scheduleAttachRootWidget. (package:flutter/src/widgets/binding.dart:917:7)

(elided 13 frames from class _AssertionError, class _RawReceivePortImpl, class _Timer, dart:async, and dart:async-patch)

════════════════════════════════════════════════════════════════════════════════════════════════════ Syncing files to device iPhone 12 Pro Max... 149ms

Flutter run key commands. r Hot reload. 🔥🔥🔥 R Hot restart. h Repeat this help message. d Detach (terminate "flutter run" but leave application running). c Clear the screen q Quit (terminate the application on the device).

💪 Running with sound null safety 💪

An Observatory debugger and profiler on iPhone 12 Pro Max is available at: http://127.0.0.1:50819/WP_5Fj4SokY=/ The Flutter DevTools debugger and profiler on iPhone 12 Pro Max is available at: http://127.0.0.1:9101?uri=http%3A%2F%2F127.0.0.1%3A50819%2FWP_5Fj4SokY%3D%2F


Running on Android simulator Pixel 4 XL


Flutter run key commands. r Hot reload. 🔥🔥🔥 R Hot restart. h Repeat this help message. d Detach (terminate "flutter run" but leave application running). c Clear the screen q Quit (terminate the application on the device).

💪 Running with sound null safety 💪

An Observatory debugger and profiler on sdk gphone x86 arm is available at: http://127.0.0.1:51343/AkeGgg0sDTQ=/ The Flutter DevTools debugger and profiler on sdk gphone x86 arm is available at: http://127.0.0.1:9102?uri=http%3A%2F%2F127.0.0.1%3A51343%2FAkeGgg0sDTQ%3D%2F

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ The following assertion was thrown building MaterialExample(dirty): 'package:flutter/src/material/theme_data.dart': Failed assertion: line 316 pos 12: 'colorScheme?.brightness == null || brightness == null || colorScheme!.brightness == brightness': is not true.

The relevant error-causing widget was: MaterialExample file:///Users/up/Development/samples/adaptive_theme/example/lib/main.dart:31:13

When the exception was thrown, this was the stack:

2 new ThemeData (package:flutter/src/material/theme_data.dart:316:12)

3 MaterialExample.build (package:example/material_example.dart:22:13)

4 StatelessElement.build (package:flutter/src/widgets/framework.dart:4648:28)

5 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4574:15)

6 Element.rebuild (package:flutter/src/widgets/framework.dart:4267:5)

7 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4553:5)

8 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4548:5)

... Normal element mounting (10 frames)

18 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3611:14)

19 MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6221:36)

20 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6232:32)

... Normal element mounting (17 frames)

37 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3611:14)

38 Element.updateChild (package:flutter/src/widgets/framework.dart:3363:18)

39 RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1189:16)

40 RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:1159:5)

41 RenderObjectToWidgetAdapter.attachToRenderTree. (package:flutter/src/widgets/binding.dart:1104:18)

42 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2535:19)

43 RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:1103:13)

44 WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:937:7)

45 WidgetsBinding.scheduleAttachRootWidget. (package:flutter/src/widgets/binding.dart:917:7)

(elided 13 frames from class _AssertionError, class _RawReceivePortImpl, class _Timer, dart:async, and dart:async-patch)

════════════════════════════════════════════════════════════════════════════════════════════════════


Running on Chrome browser


💪 Running with sound null safety 💪

🔥 To hot restart changes while running, press "r" or "R". For a more detailed help message, press "h". To quit, press "q". ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ The following assertion was thrown building MaterialExample(dirty): Assertion failed: file:///Users/up/Development/Flutter/packages/flutter/lib/src/material/theme_data.dart:316:12 colorScheme?.brightness == null || brightness == null || colorScheme!.brightness == brightness is not true

The relevant error-causing widget was: MaterialExample file:///Users/up/Development/samples/adaptive_theme/example/lib/main.dart:31:13

When the exception was thrown, this was the stack: dart-sdk/lib/_internal/js_dev_runtime/private/ddcruntime/errors.dart 236:49 throw dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 29:3 assertFailed packages/flutter/src/material/theme_data.dart 316:106 new packages/example/material_example.dart 22:13 build packages/flutter/src/widgets/framework.dart 4648:28 build packages/flutter/src/widgets/framework.dart 4574:15 performRebuild packages/flutter/src/widgets/framework.dart 4267:5 rebuild packages/flutter/src/widgets/framework.dart 4553:5 [_firstBuild] packages/flutter/src/widgets/framework.dart 4548:5 mount packages/flutter/src/widgets/framework.dart 3611:13 inflateWidget packages/flutter/src/widgets/framework.dart 3363:18 updateChild packages/flutter/src/widgets/framework.dart 6083:14 mount packages/flutter/src/widgets/framework.dart 3611:13 inflateWidget packages/flutter/src/widgets/framework.dart 3363:18 updateChild packages/flutter/src/widgets/framework.dart 4599:16 performRebuild packages/flutter/src/widgets/framework.dart 4267:5 rebuild packages/flutter/src/widgets/framework.dart 4553:5 [_firstBuild] packages/flutter/src/widgets/framework.dart 4548:5 mount packages/flutter/src/widgets/framework.dart 3611:13 inflateWidget packages/flutter/src/widgets/framework.dart 6221:36 inflateWidget packages/flutter/src/widgets/framework.dart 6232:32 mount packages/flutter/src/widgets/framework.dart 3611:13 inflateWidget packages/flutter/src/widgets/framework.dart 3363:18 updateChild packages/flutter/src/widgets/framework.dart 4599:16 performRebuild packages/flutter/src/widgets/framework.dart 4746:11 performRebuild packages/flutter/src/widgets/framework.dart 4267:5 rebuild packages/flutter/src/widgets/framework.dart 4553:5 [_firstBuild] packages/flutter/src/widgets/framework.dart 4737:11 [_firstBuild] packages/flutter/src/widgets/framework.dart 4548:5 mount packages/flutter/src/widgets/framework.dart 3611:13 inflateWidget packages/flutter/src/widgets/framework.dart 3363:18 updateChild packages/flutter/src/widgets/framework.dart 4599:16 performRebuild packages/flutter/src/widgets/framework.dart 4746:11 performRebuild packages/flutter/src/widgets/framework.dart 4267:5 rebuild packages/flutter/src/widgets/framework.dart 4553:5 [_firstBuild] packages/flutter/src/widgets/framework.dart 4737:11 [_firstBuild] packages/flutter/src/widgets/framework.dart 4548:5 mount packages/flutter/src/widgets/framework.dart 3611:13 inflateWidget packages/flutter/src/widgets/framework.dart 3363:18 updateChild packages/flutter/src/widgets/binding.dart 1189:16 [_rebuild] packages/flutter/src/widgets/binding.dart 1159:5 mount packages/flutter/src/widgets/binding.dart 1104:16 packages/flutter/src/widgets/framework.dart 2535:19 buildScope packages/flutter/src/widgets/binding.dart 1103:12 attachToRenderTree packages/flutter/src/widgets/binding.dart 936:24 attachRootWidget packages/flutter/src/widgets/binding.dart 917:7 dart-sdk/lib/_internal/js_dev_runtime/private/isolate_helper.dart 48:19 internalCallback

════════════════════════════════════════════════════════════════════════════════════════════════════


Running on macOS


I am getting the same error I got initially (Initial picture)

detzioni commented 3 years ago

I tried one more thing, which does not make any sense but for some reason solve the problem. I deleted the entire git directory and clone it again... For some reason, everything is working without a problem on the master channel and on the stable channel.

I don't understand why, but not going to argue with flutter.

BirjuVachhani commented 3 years ago

@detzioni That's totally weird. I was confused too because it was working for me but not you! Anyways, seems that it is working for you now. Let me know if you anything!

Thanks.