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

Adaptive_Theme on windows has problem with shared_preferences #38

Closed ThraaxSession closed 2 years ago

ThraaxSession commented 2 years ago

Describe the bug I try to use adaptive_theme first time with windows and ran into following issue:

To Reproduce Steps to reproduce the behavior:

  1. add adaptive_theme to project in version ^3.0.0
  2. run the app with windows as target.

Expected behavior The app starts up without error.

Screenshots

[ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: 'package:shared_preferences/shared_preferences.dart': Failed assertion: line 169 pos 14: 'key.startsWith(_prefix)': is not true.
#0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
#1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
#2      SharedPreferences._getSharedPreferencesMap (package:shared_preferences/shared_preferences.dart:169:14)
<asynchronous suspension>
#3      SharedPreferences.getInstance (package:shared_preferences/shared_preferences.dart:33:13)
<asynchronous suspension>
#4      ThemePreferences.fromPrefs (package:adaptive_theme/src/adaptive_theme_preferences.dart:62:21)
<asynchronous suspension>
#5      AdaptiveTheme.getThemeMode (package:adaptive_theme/src/adaptive_theme.dart:91:13)
<asynchronous suspension>
==> #6      main (package:spaceup_ui/main.dart:18:26) <==
<asynchronous suspension>

That's following line in my code image

I also use shared_prefences_settings. Might this be an issue? On Linux, Android and web there is no issue.

BirjuVachhani commented 2 years ago

@ThraaxSession That's weird. I do not have a windows machine to try this out right now! Try running example app on windows.

ThraaxSession commented 2 years ago

So, the plain example does work on windows. I still assume adaptive_theme does not work well with another dependency. image

BirjuVachhani commented 2 years ago

@ThraaxSession Hmm...I'll check with shared_prefences_settings dependency.

BirjuVachhani commented 2 years ago

@ThraaxSession I tried to use shared_prefences_settings with adaptive_theme's example app but I am running into this! How are you able to use it with adaptive_theme: ^3.0.0?

Running "flutter pub get" in example...                         
Because shared_preferences_settings >=1.2.0 depends on shared_preferences ^0.5.6+3 and every version of adaptive_theme from path depends on shared_preferences ^2.0.1, shared_preferences_settings >=1.2.0 is incompatible with adaptive_theme from path.
So, because example depends on both adaptive_theme from path and shared_preferences_settings ^1.2.0, version solving failed.
pub get failed (1; So, because example depends on both adaptive_theme from path and shared_preferences_settings ^1.2.0, version solving failed.)
ThraaxSession commented 2 years ago

Ok that is weird. I assume I might still have something cached on windows. I'll figure it out at weekend and let you know. 🙄

BirjuVachhani commented 2 years ago

Closing this issue because of inactivity. Feel free to re-open if you're still facing the issue.