-
-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update tutorial in README #20
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some minor changes #21
``` | ||
|
||
To reload the accent colors, use the method `load()`: | ||
|
||
```dart | ||
await SystemTheme.accentInstance.load(); | ||
await SystemTheme.accentColor.load(); | ||
``` | ||
|
||
You can load the colors before running the app, so the colors can't be wrong at runtime: | ||
|
||
```dart | ||
void main() async { | ||
WidgetsFlutterBinding.ensureInitialized(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WidgetsFlutterBinding.ensureInitialized(); |
The SystemAccentColor
already invoke the method ensureInitialized
, meaning it needless to execute it beforehand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why SystemAccentColor
invoke that method since it should be invoked at user-developer's code. For example, firebase/flutterfire never call that in their lib code, but in their example code.
So here may be another issue. This suggestion will not be accepted.
WidgetsFlutterBinding.ensureInitialized(); | ||
|
||
SystemTheme.fallbackColor = const Color(0xFF865432); | ||
await SystemTheme.accentInstance.load(); | ||
await SystemTheme.accentColor.load(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's tested that the code above make NO SENSE as the assignment of fallback color have NO EFFECT on the accent color...
WidgetsFlutterBinding.ensureInitialized(); | |
SystemTheme.fallbackColor = const Color(0xFF865432); | |
await SystemTheme.accentInstance.load(); | |
await SystemTheme.accentColor.load(); | |
var fallbackColor = const Color(0xFF865432); | |
SystemTheme.accentColor = await SystemAccentColor(fallbackColor)..load(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it does affect the accent color but only when platform channel call returns
null
.
Uhhhh...
I didn't try in that way...I tried first load it, change the fallbackColor and load it again.
The fallbackColor setter works only when it's the first to be called in the whole runtime, meaning that the code below is invalid
//void main() {
// Retrieve user-stored color preference
// maybe some io or database conn
// will callback to set systemTheme fallback color later in that part
// Try to load color first
SystemTheme.accentColor.load()
// runApp()
}
And if the accentColor is not loaded(like in iOS), when the user change the color preference, the systemTheme.fallbackColor is changed, but it doesn't affect the systemTheme.accentColor, so developers have to define some separate code for it...
Anyway, present in the package are holes of the old-era, i have chosen to write one myself in my app yesterday...
Co-authored-by: Hoarfroster <hoarfroster@outlook.com>
Sync with latest API.