bdlukaa / system_theme Goto Github PK
View Code? Open in Web Editor NEWA Flutter plugin to get the color theme from the device
Home Page: https://pub.dev/packages/system_theme
A Flutter plugin to get the color theme from the device
Home Page: https://pub.dev/packages/system_theme
project ':system_theme' -> org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.50
Hi, great project!
Is it possible to provide a callback that gets invoked whenever the accent color on the given system changes?
Currently, I (or the user) have to restart the app for it to pick up the new accent color.
Add iOS support
With #11, macOS support was added.
https://developer.apple.com/documentation/swiftui/color/accentcolor, which also supports primary
and secondary
colors
#24 Remove the getter SystemTheme.isDarkMode
, which should be considered as a break change. A major version should be publish for this change instead of a minor version.
Hey, thanks for the great package! π
Seems that for the new version of Flutter the compileSdkVersion
needs to be updated to at least 31, as seen here: flutter/flutter#153281 (comment)
Would it be possible to configure the fallback accent colour somehow? It would simplify some cross platform code.
I've implemented a listener with a builder that reacts to theme switching in Windows:
https://github.com/pgiacomo69/system_theme/tree/sysReactive
It still need some adjustments, but it works, also in fluent_ui example, with some changes.
Env:
Code:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
SystemTheme.fallbackColor = const Color(0xFF1f1e33);
await SystemTheme.accentColor.load();
runApp(MyApp());
}
Error stack:
[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method SystemTheme.accentColor on channel system_theme)
#0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:308:7)
<asynchronous suspension>
#1 SystemAccentColor.load (package:system_theme/system_theme.dart:88:20)
<asynchronous suspension>
[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method SystemTheme.accentColor on channel system_theme)
#0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:308:7)
<asynchronous suspension>
#1 SystemAccentColor.load (package:system_theme/system_theme.dart:88:20)
<asynchronous suspension>
#2 main (package:playground/main.dart:8:3)
<asynchronous suspension>
As much as i know, iOS doesn't have system accent,
so how does it work?
Run command "flutter build windows"; My system is window10 19042.685;
fatal error C1083: ζ ζ³ζεΌε
ζ¬ζδ»Ά: βSystemTheme/Windows10Colors-master/Windows10Colors/Windows10Colors.cppβ: No such file or directory [**\build\windows\plugins\system_theme\system_theme_plugin.vcxproj]
2.3.0
Introduce changes in #7 , which provides ability for app for Windows to react with system accent color changes.
It should be an awesome updates, but, a mistake was made there. As per #28 mentioned, while trying to stream the accent color, cause LateInitializationError
.
Beyond that, it actually break release build of other platform (At least Web
and Android
are breaking). For debug build, it works fine with console error, but all things works. However, in a release build,
this error can break the whole initialization phase and result a blank app without anything. It also makes web build hang up and finally being marked as no respond.
If I understand correctly:
system_theme/lib/system_theme.dart
Lines 59 to 60 in 126cd20
SystemTheme.accentColor
with SystemAccentColor(fallbackColor)..load()
. During the load()
,system_theme/lib/system_theme.dart
Lines 137 to 149 in 126cd20
SystemTheme.onChange
getter was called, and it return Stream.value(accentColor)
on platform other than Windows.system_theme/lib/system_theme.dart
Lines 74 to 80 in 126cd20
accentColor
should be evaluate immediately, and it actually means SystemTheme.accentColor
, which is still initializing. Then cause LateInitializationError
.
Here's my current investigation report. I'm not sure why it will make web build no respond as it should be failed or crash at start time, there may be other deeper issue.
There is a plugin that is trying to get the theme's accent color and other colors for linux:
https://github.com/gtk-flutter/gtk_theme_fl
It can be used as a base to support linux for this plugin. Also as gtk doesn't support dark theme directly, we can use theme_text_color
to know if the theme is dark or light.
At the moment, an unhandlable exception is thrown in case some implementation is not available on a particular platform - because this exception is thrown during the plugin initialization.
This exception should be handled during the plugin initialization and the corresponding getters should return null instead.
This exception makes is pretty hard to get this plugin working in integration tests.
as the title says
it only returns the fallback color
flutter doctor -v
[β] Flutter (Channel beta, 3.12.0, on Microsoft Windows [Version 10.0.22621.1848], locale en-US)
β’ Flutter version 3.12.0 on channel beta at C:\Users\abdua\dev\flutter
β’ Upstream repository https://github.com/flutter/flutter.git
β’ Framework revision 8fcb74dbc1 (3 weeks ago), 2023-06-08 13:37:31 -0600
β’ Engine revision b84ad1ad30
β’ Dart version 3.1.0 (build 3.1.0-163.1.beta)
β’ DevTools version 2.24.0
[β] Windows Version (Installed version of Windows is version 10 or higher)
[β] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
β’ Android SDK at C:\Users\abdua\dev\android_sdk
β’ Platform android-34, build-tools 34.0.0
β’ ANDROID_HOME = C:\Users\abdua\dev\android_sdk
β’ Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
β’ Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9586694)
β’ All Android licenses accepted.
[β] Chrome - develop for the web
β’ Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[β] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.6.3)
β’ Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
β’ Visual Studio Community 2022 version 17.6.33801.468
β’ Windows 10 SDK version 10.0.22000.0
[β] Android Studio (version 2022.2)
β’ Android Studio at C:\Program Files\Android\Android Studio
β’ 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 17.0.6+0-b2043.56-9586694)
[β] VS Code (version 1.79.2)
β’ VS Code at C:\Users\abdua\AppData\Local\Programs\Microsoft VS Code
β’ Flutter extension version 3.67.20230601
[β] Connected device (3 available)
β’ Windows (desktop) β’ windows β’ windows-x64 β’ Microsoft Windows [Version 10.0.22621.1848]
β’ Chrome (web) β’ chrome β’ web-javascript β’ Google Chrome 114.0.5735.134
β’ Edge (web) β’ edge β’ web-javascript β’ Microsoft Edge 114.0.1823.58
[β] Network resources
β’ All expected network resources are available.
β’ No issues found!
I get the following error when calling SystemTheme.accentInstance.load()
or SystemTheme.accentInstance.accent.toAccentColor()
:
MissingPluginException (MissingPluginException(No implementation found for method SystemTheme.adaptiveAccentColor on channel system_theme))
class SystemThemeObserver {
static bool _lastValue = false;
static bool _started = false;
static AccentColor accentColor = Colors.blue;
static Future adaptSystemTheme({bool force = false}) async {
if (!Settings.useSystemTheme) return;
var darkMode = await SystemTheme.darkMode;
if (Settings.adaptAccent) await SystemTheme.accentInstance.load();
var accent = SystemTheme.accentInstance.accent.toAccentColor();
if (force || (darkMode != _lastValue || accent != accentColor && Settings.adaptAccent)) {
_lastValue = darkMode;
accentColor = accent;
NcThemes.setTheme(darkMode ? darkTheme : lightTheme, force: true);
}
}
static void start() {
if (_started) return;
_started = true;
adaptSystemTheme(force: true);
Timer.periodic(Duration(seconds: 1), (timer) => adaptSystemTheme());
}
}
Please help me as I do not know how to fix this. Thanks in advance!
[β] Flutter (Channel stable, 2.10.2, on Microsoft Windows [Version 10.0.19043.1288], locale de-DE)
β’ Flutter version 2.10.2 at D:\Program Files\flutter
β’ Upstream repository https://github.com/flutter/flutter.git
β’ Framework revision 097d3313d8 (5 days ago), 2022-02-18 19:33:08 -0600
β’ Engine revision a83ed0e5e3
β’ Dart version 2.16.1
β’ DevTools version 2.9.2
[β] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
β’ Android SDK at E:\Users\User\.android\sdk
β’ Platform android-31, build-tools 31.0.0
β’ ANDROID_SDK_ROOT = E:\Users\User\.android\sdk
β’ Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
β’ Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
β’ All Android licenses accepted.
[β] Chrome - develop for the web
β’ Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[β] Visual Studio - develop for Windows (Visual Studio Community 2019 16.11.8)
β’ Visual Studio at D:\Program Files (x86)\Microsoft Visual Studio\2019\Community
β’ Visual Studio Community 2019 version 16.11.32002.261
β’ Windows 10 SDK version 10.0.19041.0
[β] Android Studio (version 2020.3)
β’ Android Studio at C:\Program Files\Android\Android Studio
β’ 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.10+0-b96-7249189)
[β] VS Code (version 1.65.0-insider)
β’ VS Code at C:\Users\User\AppData\Local\Programs\Microsoft VS Code Insiders
β’ Flutter extension version 3.34.0
[β] Connected device (3 available)
β’ Windows (desktop) β’ windows β’ windows-x64 β’ Microsoft Windows [Version 10.0.19043.1288]
β’ Chrome (web) β’ chrome β’ web-javascript β’ Google Chrome 98.0.4758.102
β’ Edge (web) β’ edge β’ web-javascript β’ Microsoft Edge 98.0.1108.56
[β] HTTP Host Availability
β’ All required HTTP hosts are available
β’ No issues found!
Env:
Chrome 117.0.5938.62
Doctor summary (to see all details, run flutter doctor -v):
[β] Flutter (Channel stable, 3.13.4, on macOS 12.6.2 21G320 darwin-x64, locale zh-Hans-CN)
[β] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[β] Xcode - develop for iOS and macOS (Xcode 14.2)
[β] Chrome - develop for the web
[β] Android Studio (version 2021.3)
[β] VS Code (version 1.78.2)
[β] VS Code (version 1.83.0-insider)
[β] Proxy Configuration
[β] Connected device (2 available)
[β] Network resources
β’ No issues found!
Error:
Error: PlatformException(error, FormatException: rgba(128, null, null)
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 294:49 throw_
packages/flutter/src/services/message_codecs.dart 652:7 decodeEnvelope
packages/flutter/src/services/platform_channel.dart 310:18 _invokeMethod
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50 <fn>
dart-sdk/lib/async/zone.dart 1661:54 runUnary
dart-sdk/lib/async/future_impl.dart 156:18 handleValue
dart-sdk/lib/async/future_impl.dart 840:44 handleValueCallback
dart-sdk/lib/async/future_impl.dart 869:13 _propagateToListeners
dart-sdk/lib/async/future_impl.dart 641:5 [_completeWithValue]
dart-sdk/lib/async/future_impl.dart 715:7 callback
dart-sdk/lib/async/schedule_microtask.dart 40:11 _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5 _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 181:15 <fn>
In line 66 of windows/system_theme_plugin.cpp, windows10colors::GetDarkModeEnabled(darkMode);
raises a warning, causing the build to fail.
For some reason the dev of the dependency decided to replace it with GetAppDarkModeEnabled
with identical functionality. Works fine when replaced.
You have a badly-documented readme containing beaucoup outdated information.
E.g. SystemTheme.accentInstance
had been removed from #1b210a9 while it's still the preferred method of reloading/loading the accent.
Please fix them all.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.