Skip to content
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

Merged
merged 3 commits into from
Jul 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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

Expand All @@ -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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
WidgetsFlutterBinding.ensureInitialized();

The SystemAccentColor already invoke the method ensureInitialized, meaning it needless to execute it beforehand.

Copy link
Contributor Author

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.

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
Copy link
Contributor

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...

Suggested change
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();

Copy link
Contributor Author

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.

image

Copy link
Contributor

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.

image

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...


runApp(MyApp());
}
Expand Down