-
-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -24,7 +24,6 @@ | |||||||||||||||
- [Supported platforms](#supported-platforms) | ||||||||||||||||
- [Usage](#usage) | ||||||||||||||||
- [Get system accent color](#get-system-accent-color) | ||||||||||||||||
- [Check dark mode](#check-dark-mode) | ||||||||||||||||
- [Contribution](#contribution) | ||||||||||||||||
- [Acknowlegments](#acknowlegments) | ||||||||||||||||
|
||||||||||||||||
|
@@ -33,7 +32,6 @@ | |||||||||||||||
| Feature | Android 10+ | iOS | Web | MacOs 10.4+ | Windows 10+ and XBox | Linux GTK 3+ | | ||||||||||||||||
| ---------------- | :---------: | :-: | :-: | :---------: | :------------------: | :----------: | | ||||||||||||||||
| Get accent color | ✔️ | | ✔️ | ✔️ | ✔️ | ✔️ | | ||||||||||||||||
| Get dark mode | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | | ||||||||||||||||
|
||||||||||||||||
## Usage | ||||||||||||||||
|
||||||||||||||||
|
@@ -45,38 +43,38 @@ import 'package:system_theme/system_theme.dart'; | |||||||||||||||
|
||||||||||||||||
### Get system accent color | ||||||||||||||||
|
||||||||||||||||
Use the getter `SystemTheme.accentInstance.accent` to get the system accent color. | ||||||||||||||||
Use the getter `SystemTheme.accentColor.accent` to get the system accent color. | ||||||||||||||||
|
||||||||||||||||
```dart | ||||||||||||||||
final accentColor = SystemTheme.accentInstance.accent; | ||||||||||||||||
final accentColor = SystemTheme.accentColor.accent; | ||||||||||||||||
``` | ||||||||||||||||
|
||||||||||||||||
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(); | ||||||||||||||||
await SystemTheme.accentInstance.load(); | ||||||||||||||||
await SystemTheme.accentColor.load(); | ||||||||||||||||
runApp(MyApp()); | ||||||||||||||||
} | ||||||||||||||||
``` | ||||||||||||||||
|
||||||||||||||||
### Configure a fallback accent color | ||||||||||||||||
|
||||||||||||||||
To avoid unexpected effects at runtime, it's good to configure a fallback color. A fallback color is used if the system was not able to provide the color | ||||||||||||||||
To avoid unexpected outcomes at runtime, it's recommended to configure your own fallback color. The fallback color is used if the system is not able to provide the color. | ||||||||||||||||
|
||||||||||||||||
```dart | ||||||||||||||||
void main() async { | ||||||||||||||||
WidgetsFlutterBinding.ensureInitialized(); | ||||||||||||||||
|
||||||||||||||||
SystemTheme.fallbackColor = const Color(0xFF865432); | ||||||||||||||||
await SystemTheme.accentInstance.load(); | ||||||||||||||||
await SystemTheme.accentColor.load(); | ||||||||||||||||
Comment on lines
74
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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...
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more.
Uhhhh... //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... |
||||||||||||||||
|
||||||||||||||||
runApp(MyApp()); | ||||||||||||||||
} | ||||||||||||||||
|
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.
The
SystemAccentColor
already invoke the methodensureInitialized
, 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.