搜索插件、代码仓与 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 系统用户界面美学
  • 在 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

源码仓库

使用此插件的项目