Code Monkey home page Code Monkey logo

system_theme's Introduction

Hi there πŸ‘‹

I'm Bruno, but you can also call me D'Luka (pronounced di luka);
currently majoring in Computer Science;
I do Flutter and stuff; currently learning React Native and Unity (see Pinned);
pronouns: he/him🌈;
Brazilian πŸ‡§πŸ‡·;
fun fact: I can speak 4 languages (pt, en, es, ko), but I'm bad at all of them.


system_theme's People

Contributors

alexmercerind avatar bdlukaa avatar blindmatrix avatar davidskelly avatar kj415j45 avatar pgiacomo69 avatar ricardoboss avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

system_theme's Issues

Support linux

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.

Fail on iOS with fallbackColor set.

Env:

  • Host
    • MacOS 12.6.2
    • Flutter 3.10.3 (Dart 3.0.3) stable channel
  • Target
    • iPhone 14 (simulator)
    • iOS 16.2

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>

doesn't work on my windows

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!

Depreciation in windows10colors causes build failure

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.

Configurable fallback colour

Would it be possible to configure the fallback accent colour somehow? It would simplify some cross platform code.

Error when using SystemTheme.accentInstance

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

The code that produces the error is the following:
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 doctor -v
[√] 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!

Failed to get accent color on Chrome 117

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>

Bad documentation

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.

Accent color changed listener

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.

Do not throw unhandlable exception in plugin initialization when platform unsupported

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.

Package version should be bump to 3.0.0

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

[critical] `2.3.0` Breaks release build at runtime

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:

static final SystemAccentColor accentColor = SystemAccentColor(fallbackColor)
..load();

Here, try to initialize final variable SystemTheme.accentColor with SystemAccentColor(fallbackColor)..load(). During the load(),
/// Updates the fetched accent colors on Windows.
Future<void> load() async {
WidgetsFlutterBinding.ensureInitialized();
_subscription = SystemTheme.onChange.listen((color) {
accent = color.accent;
light = color.light;
lighter = color.lighter;
lightest = color.lightest;
dark = color.dark;
darker = color.darker;
darkest = color.darkest;
});

SystemTheme.onChange getter was called, and it return Stream.value(accentColor) on platform other than Windows.
static Stream<SystemAccentColor> get onChange {
if (kIsWeb || !Platform.isWindows) return Stream.value(accentColor);
return _eventChannel.receiveBroadcastStream().map((event) {
return SystemAccentColor._fromMap(event);
}).distinct();
}

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.