64 lines
2.3 KiB
Dart
64 lines
2.3 KiB
Dart
|
|
import 'package:flutter/material.dart';
|
|||
|
|
import 'app_colors.dart';
|
|||
|
|
|
|||
|
|
/// ThemeUtils - テーマカラーへの安全なアクセスを提供するユーティリティ
|
|||
|
|
///
|
|||
|
|
/// 使用例:
|
|||
|
|
/// ```dart
|
|||
|
|
/// // Extension経由(推奨):
|
|||
|
|
/// Text('テキスト', style: TextStyle(color: context.colors.textPrimary));
|
|||
|
|
/// Icon(icon, color: context.colors.brandPrimary);
|
|||
|
|
///
|
|||
|
|
/// // 短縮形:
|
|||
|
|
/// color: context.brandPrimary
|
|||
|
|
/// color: context.textSecondary
|
|||
|
|
/// ```
|
|||
|
|
|
|||
|
|
extension ThemeContextExtensions on BuildContext {
|
|||
|
|
/// AppColorsへの安全なアクセス
|
|||
|
|
AppColors get colors => Theme.of(this).extension<AppColors>()!;
|
|||
|
|
|
|||
|
|
// ===== 便利なショートカット =====
|
|||
|
|
|
|||
|
|
// テキストカラー
|
|||
|
|
Color get textPrimary => colors.textPrimary;
|
|||
|
|
Color get textSecondary => colors.textSecondary;
|
|||
|
|
Color get textTertiary => colors.textTertiary;
|
|||
|
|
|
|||
|
|
// ブランドカラー
|
|||
|
|
Color get brandPrimary => colors.brandPrimary;
|
|||
|
|
Color get brandAccent => colors.brandAccent;
|
|||
|
|
Color get brandSurface => colors.brandSurface;
|
|||
|
|
|
|||
|
|
// アイコンカラー
|
|||
|
|
Color get iconDefault => colors.iconDefault;
|
|||
|
|
Color get iconSubtle => colors.iconSubtle;
|
|||
|
|
Color get iconAccent => colors.iconAccent;
|
|||
|
|
|
|||
|
|
// サーフェイスカラー
|
|||
|
|
Color get surfaceElevated => colors.surfaceElevated;
|
|||
|
|
Color get surfaceSubtle => colors.surfaceSubtle;
|
|||
|
|
Color get dividerColor => colors.divider;
|
|||
|
|
|
|||
|
|
// セマンティックカラー
|
|||
|
|
Color get successColor => colors.success;
|
|||
|
|
Color get warningColor => colors.warning;
|
|||
|
|
Color get errorColor => colors.error;
|
|||
|
|
Color get infoColor => colors.info;
|
|||
|
|
|
|||
|
|
// ===== ダークモードチェック(既存コードとの互換性用) =====
|
|||
|
|
/// ダークモードかどうかを判定
|
|||
|
|
/// 注意: 新規コードでは使用しないでください。代わりにAppColorsのセマンティックカラーを使用してください。
|
|||
|
|
@Deprecated('Use context.colors.brandPrimary instead of checking isDark manually')
|
|||
|
|
bool get isDark => Theme.of(this).brightness == Brightness.dark;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// グローバルヘルパー関数(既存コードとの互換性用)
|
|||
|
|
///
|
|||
|
|
/// 注意: 新規コードでは使用しないでください。
|
|||
|
|
/// 代わりに `context.colors.brandPrimary` などのExtensionを使用してください。
|
|||
|
|
@Deprecated('Use context.colors instead')
|
|||
|
|
AppColors appColors(BuildContext context) {
|
|||
|
|
return Theme.of(context).extension<AppColors>()!;
|
|||
|
|
}
|