패키지, 저장소 및 앱 카테고리 검색

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용 플러터 플러그인으로 AppKit의 내장 UI 요소 색상에 접근할 수 있게 해주며, 플러터 앱이 macOS에서 일관된 네이티브 외관을 갖도록 합니다. Apple의 AppKit 프레임워크에서 시스템 색상 상수(예: 창 배경, 컨트롤 톤, 텍스트 색상 등)를 매핑하여 macOS 디자인 가이드라인과 일치하도록 보장합니다. 이 패키지는 수동 구성 없이 플랫폼 전용 색상 값을 직접 접근할 수 있도록 하여 테마 설정을 간소화합니다.

사용 사례

  • 맥OS 시스템 UI 미학과 일치
  • macOS에서 네이티브 스타일의 Flutter 앱 만들기
  • macOS용 테마 구현 간소화
  • 시스템 색 구성표와의 일관성 보장
  • macOS 전용 스타일을 사용한 크로스플랫폼 앱 개발

주요 기능

  • AppKit의 네이티브 UI 요소 색상에 대한 액세스
  • macOS Flutter 앱과의 원활한 통합
  • 시스템 테마와의 자동 동기화
  • 최소한의 설정 필요
  • 동적 색상 업데이트를 지원

적합한 대상

  • macOS를 대상으로 하는 플러터 개발자
  • 네이티브 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

소스 저장소

이 패키지를 사용하는 프로젝트