搜尋套件、儲存庫與 APP 分類

套件詳情v3.3.0

system_theme

一個用於檢索和監聽系統強調色彩的 Flutter 外掛程式。支援 Android、iOS、Web、Windows、macOS 和 Linux。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
8260
喜歡數
123
Pub 分數
160

安裝套件

flutter pub add system_theme

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

system_theme 套件讓 Flutter 應用程式能夠在多個平台(包括 Android、iOS、Web、macOS、Windows 和 Linux)上存取並回應系統的強調色彩。它提供了一種簡單的方法來取得目前系統的強調色彩並監聽變更,提升應用程式介面與裝置層級主題的一致性。非常適合希望符合原生系統美學而無需手動管理主題的應用。

適用情境

  • 匹配應用程式使用者介面中的系統強調色
  • 基於系統偏好建立動態主題
  • 使用原生外觀和感覺構建跨平台應用
  • 系統主題變更時自動更新顏色
  • 透過系統定義的色彩方案增強可訪問性

主要特色

  • 即時監聽系統強調色變更
  • 跨平台支援所有主要作業系統
  • 用於檢索目前強調色的簡單API
  • 系統主題變更時自動更新
  • 輕量且易於整合

適合對象

  • 針對原生使用者介面的開發人員
  • 需要動態主題適配的應用程式
  • 專注於可及性與使用者體驗的專案
  • 跨平台 Flutter 應用
  • 希望實現無縫系統整合的設計人員

使用建議

  • 僅限強調色彩;不管理完整主題模式
  • 行為在不同平台之間可能略有差異
  • 在某些作業系統上需要特定平台的權限
  • 不適合超出強調色之外的複雜主題管理
  • 取決於系統級別的顏色可用性

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

system_theme

A flutter plugin to retrieve the current system theme information

Supported platforms
Platform Accent Color Listen to Color Changes Minimum Version
Android ✔️ Android 10+
iOS ✔️ iOS 14+
Windows ✔️ ✔️ Windows 10+
macOS ✔️ ✔️ Mojave 10.14+
Linux ✔️ GTK 3+
Web ✔️ All modern browsers

Usage

Import it:

import 'package:system_theme/system_theme.dart';
Get system accent color

Use the getter SystemTheme.accentColor.accent to get the accent color.

final accentColor = SystemTheme.accentColor.accent;

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

await SystemTheme.accentColor.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.accentColor.load();
  runApp(MyApp());
}
Configure a fallback accent 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.

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

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

  runApp(MyApp());
}
Listen to changes on the system accent color

To simply listen to changes on the system accent color, use the SystemTheme.onChange stream:

SystemTheme.onChange.listen((event) {
  debugPrint('Accent color changed to ${event.accentColor}');
});

Alteratively, you can the SystemThemeBuilder widget to listen to changes on the system accent color:

SystemThemeBuilder(
  builder: (context, color) {
    return ColoredBox(
      color: color.accent, // Automatically updates when system theme changes
      child: const Center(
        child: Text('System Accent Color'),
      ),
    );
  },
);
Notes

On iOS 14 and later, this is the application's SwiftUI accent color (for example, the accent configured in the app's asset catalog), or the platform's app-level default when none is configured. Unlike Windows and macOS, iOS does not expose an equivalent global user-selected system accent color. If the app accent is unavailable or cannot be converted, the existing fallback or last loaded palette is retained. iOS does not automatically report accent changes; call load() to refresh it.

Contribution

See native testing for platform test commands and manual verification steps.

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

Acknowlegments

所屬分類

依賴

依賴清單 1 項

  • system_theme_web^0.0.5

原始碼儲存庫

使用此套件的專案