パッケージ、リポジトリ、アプリカテゴリを検索

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のビジュアル一貫性を必要とするアプリ
  • デザイナーはプラットフォーム固有のUI忠実度に注目しました
  • 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

ソースリポジトリ

このパッケージを使用しているプロジェクト