kj415j45 / system_theme

A flutter plugin to get the current system theme info

Home Page:https://pub.dev/packages/system_theme

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

system_theme

A flutter plugin to get the current system theme information

Supported platforms

Feature Android 10+ iOS Web MacOs 10.4+ Windows 10+ and XBox Linux GTK 3+
Get accent color ✔️ ✔️ ✔️ ✔️ ✔️
Get dark mode ✔️ ✔️ ✔️ ✔️ ✔️ ✔️

Usage

Import it:

import 'package:system_theme/system_theme.dart';

Get system accent color

Use the getter SystemTheme.accentInstance.accent to get the system accent color.

final accentColor = SystemTheme.accentInstance.accent;

To reload the accent colors, use the method load():

await SystemTheme.accentInstance.load();

You can load the colors before running the app, so the colors can't be wrong at runtime:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await SystemTheme.accentInstance.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

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  SystemTheme.fallbackColor = const Color(0xFF865432);
  await SystemTheme.accentInstance.load();

  runApp(MyApp());
}

Check dark mode

Use the getter SystemTheme.isDarkMode to check if the device is in dark mode.

final darkMode = SystemTheme.darkMode;

Contribution

Feel free to open an issue if you find an error or make pull requests.

Acknowlegments

About

A flutter plugin to get the current system theme info

https://pub.dev/packages/system_theme

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:C++ 61.1%Language:CMake 19.0%Language:Dart 8.5%Language:Kotlin 3.3%Language:Swift 3.1%Language:C 2.5%Language:HTML 1.8%Language:Ruby 0.7%Language:Objective-C 0.0%