Skip to content

Commit

Permalink
fix: Added flag to fix theme.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathrunet committed Mar 7, 2023
1 parent b83468b commit 3e31542
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 35 deletions.
16 changes: 8 additions & 8 deletions packages/katana_theme/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ packages:
dependency: transitive
description:
name: built_value
sha256: "169565c8ad06adb760c3645bf71f00bff161b00002cace266cad42c5d22a7725"
sha256: "31b7c748fd4b9adf8d25d72a4c4a59ef119f12876cf414f94f8af5131d5fa2b0"
url: "https://pub.dev"
source: hosted
version: "8.4.3"
version: "8.4.4"
characters:
dependency: transitive
description:
Expand Down Expand Up @@ -181,10 +181,10 @@ packages:
dependency: transitive
description:
name: dart_style
sha256: "7a03456c3490394c8e7665890333e91ae8a49be43542b616e414449ac358acd4"
sha256: "5be16bf1707658e4c03078d4a9b90208ded217fb02c163e207d334082412f2fb"
url: "https://pub.dev"
source: hosted
version: "2.2.4"
version: "2.2.5"
encrypt:
dependency: transitive
description:
Expand Down Expand Up @@ -345,22 +345,22 @@ packages:
path: ".."
relative: true
source: path
version: "1.3.3"
version: "1.4.0"
katana_theme_annotation:
dependency: transitive
description:
name: katana_theme_annotation
sha256: bfa97dd576edbbc2736cb18941bd0fed0a3e8d73318ae947d03dfcca28c19801
sha256: "01073043410a76a19c627a0b6d722cfa7eaad9a09c6147f87f35f92ce5adbe93"
url: "https://pub.dev"
source: hosted
version: "1.3.1"
version: "1.4.0"
katana_theme_builder:
dependency: "direct dev"
description:
path: "../../katana_theme_builder"
relative: true
source: path
version: "1.3.1"
version: "1.4.0"
lints:
dependency: transitive
description:
Expand Down
59 changes: 40 additions & 19 deletions packages/katana_theme/lib/src/app_theme_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ class AppThemeData {
this.platform = TargetPlatform.iOS,
this.centerTitleOnAppBar,
this.brightness = Brightness.light,
this.fixed = false,
}) : _lightColor = brightness == Brightness.light
? ColorThemeData._(
brightness: brightness,
Expand Down Expand Up @@ -249,11 +250,12 @@ class AppThemeData {
onWarning: onWarning,
splashColor: splashColor,
shadow: shadow,
inverseSurface:
inverseSurface ?? surface ?? _surface(_inverse(brightness)),
inverseSurface: inverseSurface ??
surface ??
_surface(_inverse(brightness, fixed)),
onInverseSurface: onInverseSurface ??
onSurface ??
_onBackgroundOrSurface(_inverse(brightness)),
_onBackgroundOrSurface(_inverse(brightness, fixed)),
inversePrimary: inversePrimary ?? primary,
appBarColor: appBarColor,
onAppBarColor: onAppBarColor,
Expand All @@ -278,11 +280,12 @@ class AppThemeData {
warning: inverseWarning ?? warning,
info: inverseInfo ?? info,
success: inverseSuccess ?? success,
surface:
inverseSurface ?? surface ?? _surface(_inverse(brightness)),
surface: inverseSurface ??
surface ??
_surface(_inverse(brightness, fixed)),
background: inverseBackground ??
background ??
_background(_inverse(brightness)),
_background(_inverse(brightness, fixed)),
onPrimary: onInversePrimary ?? onPrimary,
onSecondary: onInverseSecondary ?? onSecondary,
onTertiary: onInverseTertiary ?? onTertiary,
Expand All @@ -295,10 +298,10 @@ class AppThemeData {
onDisabled: onInverseDisabled ?? onDisabled,
onSurface: onInverseSurface ??
onSurface ??
_onBackgroundOrSurface(_inverse(brightness)),
_onBackgroundOrSurface(_inverse(brightness, fixed)),
onBackground: onInverseBackground ??
onBackground ??
_onBackgroundOrSurface(_inverse(brightness)),
_onBackgroundOrSurface(_inverse(brightness, fixed)),
onWeak: onInverseWeak ?? onWeak,
onError: onInverseError ?? onError,
onInfo: onInverseInfo ?? onInfo,
Expand All @@ -318,7 +321,7 @@ class AppThemeData {
onInverseExpandedAppBarColor ?? onExpandedAppBarColor,
scaffoldBackgroundColor: inverseScaffoldBackgroundColor ??
scaffoldBackgroundColor ??
_background(_inverse(brightness)),
_background(_inverse(brightness, fixed)),
),
_darkColor = brightness == Brightness.dark
? ColorThemeData._(
Expand Down Expand Up @@ -355,11 +358,12 @@ class AppThemeData {
onWarning: onWarning,
splashColor: splashColor,
shadow: shadow,
inverseSurface:
inverseSurface ?? surface ?? _surface(_inverse(brightness)),
inverseSurface: inverseSurface ??
surface ??
_surface(_inverse(brightness, fixed)),
onInverseSurface: onInverseSurface ??
onSurface ??
_onBackgroundOrSurface(_inverse(brightness)),
_onBackgroundOrSurface(_inverse(brightness, fixed)),
inversePrimary: inversePrimary ?? primary,
appBarColor: appBarColor,
onAppBarColor: onAppBarColor,
Expand All @@ -384,11 +388,12 @@ class AppThemeData {
warning: inverseWarning ?? warning,
info: inverseInfo ?? info,
success: inverseSuccess ?? success,
surface:
inverseSurface ?? surface ?? _surface(_inverse(brightness)),
surface: inverseSurface ??
surface ??
_surface(_inverse(brightness, fixed)),
background: inverseBackground ??
background ??
_background(_inverse(brightness)),
_background(_inverse(brightness, fixed)),
onPrimary: onInversePrimary ?? onPrimary,
onSecondary: onInverseSecondary ?? onSecondary,
onTertiary: onInverseTertiary ?? onTertiary,
Expand All @@ -401,10 +406,10 @@ class AppThemeData {
onDisabled: onInverseDisabled ?? onDisabled,
onSurface: onInverseSurface ??
onSurface ??
_onBackgroundOrSurface(_inverse(brightness)),
_onBackgroundOrSurface(_inverse(brightness, fixed)),
onBackground: onInverseBackground ??
onBackground ??
_onBackgroundOrSurface(_inverse(brightness)),
_onBackgroundOrSurface(_inverse(brightness, fixed)),
onWeak: onInverseWeak ?? onWeak,
onError: onInverseError ?? onError,
onInfo: onInverseInfo ?? onInfo,
Expand All @@ -424,7 +429,7 @@ class AppThemeData {
onInverseExpandedAppBarColor ?? onExpandedAppBarColor,
scaffoldBackgroundColor: inverseScaffoldBackgroundColor ??
scaffoldBackgroundColor ??
_background(_inverse(brightness)),
_background(_inverse(brightness, fixed)),
),
text = TextThemeData._(
displayLarge: displayLarge,
Expand Down Expand Up @@ -607,6 +612,7 @@ class AppThemeData {
bool useMaterial3 = true,
TargetPlatform platform = TargetPlatform.iOS,
bool? centerTitleOnAppBar,
bool fixed = false,
}) : this(
primary: primary,
secondary: secondary,
Expand Down Expand Up @@ -700,6 +706,7 @@ class AppThemeData {
platform: platform,
centerTitleOnAppBar: centerTitleOnAppBar,
brightness: Brightness.light,
fixed: fixed,
);

/// The dark theme defines the initial color.
Expand Down Expand Up @@ -862,6 +869,7 @@ class AppThemeData {
bool useMaterial3 = true,
TargetPlatform platform = TargetPlatform.iOS,
bool? centerTitleOnAppBar,
bool fixed = false,
}) : this(
primary: primary,
secondary: secondary,
Expand Down Expand Up @@ -955,6 +963,7 @@ class AppThemeData {
platform: platform,
centerTitleOnAppBar: centerTitleOnAppBar,
brightness: Brightness.dark,
fixed: fixed,
);

/// Retrieve the color scheme.
Expand Down Expand Up @@ -1082,6 +1091,15 @@ class AppThemeData {
/// アプリの[Brightness]を定義します。[Brightness.dark]でダークモードに、[Brightness.light]でライトモードになります。
final Brightness brightness;

/// Specifies whether to always use the same theme instead of switching between light and dark modes.
///
/// /// If `true`, the same theme is always used without switching between light and dark modes.
///
/// ライトモードやダークモードの切り替えを行うのではなく、常に同じテーマを使用するかどうかを指定します。
///
/// `true`の場合、ライトモードやダークモードの切り替えを行わず、常に同じテーマを使用します。
final bool fixed;

/// Get [AppThemeData] placed on the widget tree.
///
/// ウィジェットツリー上に配置されている[AppThemeData]を取得します。
Expand Down Expand Up @@ -1426,7 +1444,10 @@ class AppThemeData {
}
}

static Brightness _inverse(Brightness brightness) {
static Brightness _inverse(Brightness brightness, bool fixed) {
if (fixed) {
return brightness;
}
if (brightness == Brightness.light) {
return Brightness.dark;
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/katana_theme/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,10 @@ packages:
dependency: "direct main"
description:
name: katana_theme_annotation
sha256: bfa97dd576edbbc2736cb18941bd0fed0a3e8d73318ae947d03dfcca28c19801
sha256: "01073043410a76a19c627a0b6d722cfa7eaad9a09c6147f87f35f92ce5adbe93"
url: "https://pub.dev"
source: hosted
version: "1.3.1"
version: "1.4.0"
lints:
dependency: transitive
description:
Expand Down
12 changes: 6 additions & 6 deletions packages/katana_theme_builder/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ packages:
dependency: transitive
description:
name: built_value
sha256: "169565c8ad06adb760c3645bf71f00bff161b00002cace266cad42c5d22a7725"
sha256: "31b7c748fd4b9adf8d25d72a4c4a59ef119f12876cf414f94f8af5131d5fa2b0"
url: "https://pub.dev"
source: hosted
version: "8.4.3"
version: "8.4.4"
clock:
dependency: transitive
description:
Expand Down Expand Up @@ -125,10 +125,10 @@ packages:
dependency: "direct main"
description:
name: dart_style
sha256: "7a03456c3490394c8e7665890333e91ae8a49be43542b616e414449ac358acd4"
sha256: "5be16bf1707658e4c03078d4a9b90208ded217fb02c163e207d334082412f2fb"
url: "https://pub.dev"
source: hosted
version: "2.2.4"
version: "2.2.5"
encrypt:
dependency: transitive
description:
Expand Down Expand Up @@ -245,10 +245,10 @@ packages:
dependency: "direct main"
description:
name: katana_theme_annotation
sha256: bfa97dd576edbbc2736cb18941bd0fed0a3e8d73318ae947d03dfcca28c19801
sha256: "01073043410a76a19c627a0b6d722cfa7eaad9a09c6147f87f35f92ce5adbe93"
url: "https://pub.dev"
source: hosted
version: "1.3.1"
version: "1.4.0"
lints:
dependency: transitive
description:
Expand Down

0 comments on commit 3e31542

Please sign in to comment.