Skip to content

Commit

Permalink
feat: deprecate YaruThemeDataExtension in favor of YaruColorSchemeExt…
Browse files Browse the repository at this point in the history
…ension (#349)
  • Loading branch information
jpnurmi committed May 30, 2023
1 parent ec28f98 commit 7aad7ff
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 14 deletions.
17 changes: 17 additions & 0 deletions example/lib/view/colors_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,23 @@ class ColorsView extends StatelessWidget {
_colorContainer('xubuntuBlue', YaruColors.xubuntuBlue),
],
),
const _SpacedDivider(),
Padding(
padding: const EdgeInsets.only(bottom: 20, left: 5),
child: Text(
'Extension Colors',
style: headlineStyle,
),
),
GridView(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
gridDelegate: _gridDelegate,
children: [
_colorContainer('success', theme.colorScheme.success),
_colorContainer('warning', theme.colorScheme.warning),
],
),
],
);
}
Expand Down
7 changes: 1 addition & 6 deletions lib/src/themes/common_themes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/services.dart';
import 'package:yaru/src/colors.dart';
import 'package:yaru/src/text/text_theme.dart';
import 'package:yaru/src/themes/constants.dart';
import 'package:yaru/src/themes/extensions.dart';
import 'package:yaru/src/themes/page_transitions.dart';

const kDividerColorDark = Color.fromARGB(255, 65, 65, 65);
Expand Down Expand Up @@ -485,12 +486,6 @@ DrawerThemeData _createDrawerTheme(ColorScheme colorScheme) {
);
}

extension YaruColorSchemeX on ColorScheme {
bool get isDark => brightness == Brightness.dark;
bool get isLight => brightness == Brightness.light;
bool get isHighContrast => [Colors.black, Colors.white].contains(primary);
}

/// Helper function to create a new Yaru theme
ThemeData createYaruTheme({
required ColorScheme colorScheme,
Expand Down
35 changes: 27 additions & 8 deletions lib/src/themes/extensions.dart
Original file line number Diff line number Diff line change
@@ -1,27 +1,46 @@
import 'package:flutter/material.dart';
import 'package:yaru/src/colors.dart';

/// Yaru-specific theming extensions.
@Deprecated('Use YaruColorSchemeExtension instead.')
extension YaruThemeDataExtension on ThemeData {
@Deprecated('Use ColorScheme.success instead.')
Color get successColor => colorScheme.success;

@Deprecated('Use ColorScheme.warning instead.')
Color get warningColor => colorScheme.warning;
}

/// Yaru-specific color scheme extensions.
extension YaruColorSchemeExtension on ColorScheme {
/// Whether the brightness is dark.
bool get isDark => brightness == Brightness.dark;

/// Whether the brightness is light.
bool get isLight => brightness == Brightness.light;

/// Whether the primary color is either black or white.
bool get isHighContrast =>
const [Colors.black, Colors.white].contains(primary);

/// A color to indicate success e.g. for text input validation.
///
/// ```dart
/// Theme.of(context).successColor
/// Theme.of(context).colorScheme.success
/// ```
///
/// See also:
/// * [ThemeData.colorScheme.error]
Color get successColor => YaruColors.success;
/// * [ColorScheme.error]
Color get success => YaruColors.success;

/// A color to indicate warnings.
///
/// This is the counterpart of [ThemeData.colorScheme.error].
/// This is the counterpart of [ColorScheme.error].
///
/// ```dart
/// Theme.of(context).warningColor
/// Theme.of(context).colorScheme.warning
/// ```
///
/// See also:
/// * [ThemeData.colorScheme.error]
Color get warningColor => YaruColors.warning;
/// * [ColorScheme.error]
Color get warning => YaruColors.warning;
}

0 comments on commit 7aad7ff

Please sign in to comment.