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

appkit_ui_element_colors 封面
套件詳情v1.0.1

appkit_ui_element_colors

一個暴露 AppKit 的「UI 元素顏色」的 Flutter 插件。

macOS
近 30 天下載
4.7萬
喜歡數
0
Pub 分數
140

安裝套件

flutter pub add appkit_ui_element_colors

套件介紹

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

一個適用於 macOS 的 Flutter 插件,提供對 AppKit 內建 UI 元素顏色的存取,讓 Flutter 應用在 macOS 上具有一致的原生外觀。它映射了 Apple 的 AppKit 框架中的系統顏色常數,例如視窗背景、控制項陰影與文字顏色,確保符合 macOS 設計指南。此套件透過提供對平台特定顏色值的直接存取,簡化主題設定,無需手動設定。

適用情境

  • 匹配 macOS 系統 UI 美學
  • 在 macOS 上建立原生外觀的 Flutter 應用
  • 簡化 macOS 的主題實作
  • 確保與系統顏色方案的一致性
  • 使用 macOS 特定樣式開發跨平台應用

主要特色

  • 存取 AppKit 的原生 UI 元素顏色
  • 與 macOS Flutter 應用無縫整合
  • 與系統主題的自動同步
  • 所需設定最少
  • 支援動態顏色更新

適合對象

  • 針對 macOS 的 Flutter 開發人員
  • 需要原生 macOS 視覺一致性應用
  • 設計師專注於平台特定的使用者介面保真度
  • 使用 macOS 特定主題的項目

使用建議

  • 僅限 macOS 平台
  • 取決於底層 AppKit 的可用性
  • 可能需要額外處理深色模式切換
  • 不適用於非 macOS 平台

原始 README

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

appkit_ui_element_colors

A Flutter plugin that exposes AppKit’s “UI Element Colors” to facilitate the retrieval of standard color objects for use with windows, controls, labels, text, selections and other content in your app.

Screenshot of example project

Screenshot 2023-03-19 at 12 36 03

Getting started

Install this package:

flutter pub add appkit_ui_element_colors

Then import it in your Dart code:

import 'package:appkit_ui_element_colors/appkit_ui_element_colors.dart';

Features

Retrieving UI element colors

The following colors are available:

Available UI Element colors
  • labelColor
  • secondaryLabelColor
  • tertiaryLabelColor
  • quaternaryLabelColor
  • textColor
  • placeholderTextColor
  • selectedTextColor
  • textBackgroundColor
  • selectedTextBackgroundColor
  • keyboardFocusIndicatorColor
  • unemphasizedSelectedTextColor
  • unemphasizedSelectedTextBackgroundColor
  • linkColor
  • separatorColor
  • selectedContentBackgroundColor
  • unemphasizedSelectedContentBackgroundColor
  • selectedMenuItemTextColor
  • gridColor
  • headerTextColor
  • alternatingContentBackgroundColors0
  • alternatingContentBackgroundColors1
  • controlAccentColor
  • controlColor
  • controlBackgroundColor
  • controlTextColor
  • disabledControlTextColor
  • currentControlTint
  • selectedControlColor
  • selectedControlTextColor
  • alternateSelectedControlTextColor
  • scrubberTexturedBackground
  • windowBackgroundColor
  • windowFrameTextColor
  • underPageBackgroundColor
  • findHighlightColor
  • highlightColor
  • shadowColor

Each color can be retrieved as a Color object using the AppkitUiElementColors.getColor method:

final darkWindowBackgroundColor = await AppkitUiElementColors.getColor(
  uiElementColor: UiElementColor.windowBackgroundColor,
  appearance: NSAppearanceName.darkAqua,
);

Alternatively, it can also be converted to any available NSColorSpace and retrieved as a map of requested NSColorComponents using AppkitUiElementColors.getColorComponents:

final components = await AppkitUiElementColors.getColorComponents(
  uiElementColor: UiElementColor.selectedControlColor,
  components: {
    NSColorComponent.redComponent,
    NSColorComponent.greenComponent,
    NSColorComponent.blueComponent,
  },
  colorSpace: NSColorSpace.sRGB,
  appearance: NSAppearanceName.aqua,
);

// prints "{blueComponent: 0.7450980544090271, redComponent: 1.0, greenComponent: 0.9333333373069763}"
print(components);
Observing system color changes

Certain events, such as the user changing their preferred accent color, can trigger system color changes. Such changes can be observed using the SystemColorObserver class. The AppkitUiElementColors class provides a global shared instance of SystemColorObserver that can be accessed as follows:

AppkitUiElementColors.systemColorObserver.stream
    .listen((_) => print('System colors changed.'));
Building widgets using UiElementColorBuilder

The UiElementColorBuilder class provides a convenient way to build widgets that depend on UI element colors provided by appkit_ui_element_colors:

UiElementColorBuilder(
  builder: (context, colorContainer) => Container(
    color: colorContainer.windowBackgroundColor,
  ),
);

By default, UiElementColorBuilder uses a SharedUiElementColorContainerInstanceProvider to provide a global shared instance of UiElementColorContainer. SharedUiElementColorContainerInstanceProvider uses an instance of MediaQueryData derived from the current BuildContext and assumes it to be the same across all UiElementBuilders which use it. If your app contains surfaces with different MediaQueryData overrides, use OwnedUiElementColorContainerInstanceProvider instead:

// A dark cupertino theme.
CupertinoTheme(
  data: const CupertinoThemeData(
    brightness: Brightness.dark,
  ),
  // Override the MediaQueryData so that platformBrightness is dark.
  child: MediaQuery(
    data: MediaQuery.of(context).copyWith(
      platformBrightness: Brightness.dark,
    ),
    child: UiElementColorBuilder(
      // Since there may be surfaces within the app that do not override the
      // brightness, use an OwnedUiElementColorContainerInstanceProvider.
      uiElementColorContainerInstanceProvider:
          OwnedUiElementColorContainerInstanceProvider(),
      builder: (context, colorContainer) => Container(
        color: colorContainer.windowBackgroundColor,
      ),
    ),
  ),
);

Incorrect usage of SharedUiElementColorContainerInstanceProvider throws the following assertion error:

“Found conflicting MediaQueryData in SharedUiElementColorContainerInstanceProvider. If you are using UiElementColorBuilder within widget subtrees with differing MediaQueryData (such as different theme brightness or accessibility settings), please use OwnedUiElementColorContainerInstanceProvider instead.”

所屬分類

依賴

依賴清單 2 項

  • equatable^2.0.5
  • plugin_platform_interface^2.0.2

原始碼儲存庫

使用此套件的專案