feat(ui)!: move last extensions + add extension provider
continuous-integration/drone/pr Build is failing
continuous-integration/drone/pr Build is failing
This commit is contained in:
@@ -14,6 +14,8 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with super program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// A helper class for getting theme elements.
|
||||
abstract class ThemeHelper {
|
||||
/// Gets a nullable theme element from a list of styles.
|
||||
@@ -83,7 +85,11 @@ abstract class ThemeHelper {
|
||||
);
|
||||
|
||||
if (result == null) {
|
||||
throw Exception('No valid style found');
|
||||
throw FlutterError(
|
||||
'No valid style found.\nPlease check your theme configuration.\n'
|
||||
'Searching for: $P in $styles (transform to $T)\n'
|
||||
'If this value can be null, use maybeGetElement instead.',
|
||||
);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ class CardThemeExtensionDefault extends CardThemeExtension {
|
||||
factory CardThemeExtensionDefault.from(ThemeData theme) =>
|
||||
CardThemeExtensionDefault(
|
||||
radius: const BorderRadius.all(Radius.circular(12)),
|
||||
padding: theme.cardTheme.margin,
|
||||
padding: theme.cardTheme.margin ?? const EdgeInsets.all(4),
|
||||
backgroundColors: MultiColor.single(theme.cardTheme.color),
|
||||
borderColors: MultiColor.single(theme.cardTheme.color),
|
||||
minSize: const Size(330, 0),
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:wyatt_ui_components/wyatt_ui_components.dart';
|
||||
|
||||
/// {@template loader_theme_extension_default}
|
||||
/// The default [LoaderThemeExtension].
|
||||
/// {@endtemplate}
|
||||
class LoaderThemeExtensionDefault extends LoaderThemeExtension {
|
||||
/// {@macro loader_theme_extension_default}
|
||||
const LoaderThemeExtensionDefault({
|
||||
required super.colors,
|
||||
required super.stroke,
|
||||
});
|
||||
|
||||
/// Creates a [LoaderThemeExtensionDefault] from a [ThemeData]
|
||||
/// and opinionated defaults.
|
||||
///
|
||||
/// {@macro card_theme_extension_default}
|
||||
factory LoaderThemeExtensionDefault.from(ThemeData theme) =>
|
||||
LoaderThemeExtensionDefault(
|
||||
colors: MultiColor([
|
||||
theme.progressIndicatorTheme.color ?? theme.colorScheme.primary,
|
||||
Colors.transparent,
|
||||
]),
|
||||
stroke: 4,
|
||||
);
|
||||
|
||||
/// Creates a [LoaderThemeExtensionDefault] from a dark [ThemeData]
|
||||
factory LoaderThemeExtensionDefault.dark() =>
|
||||
LoaderThemeExtensionDefault.from(ThemeData.dark());
|
||||
|
||||
/// Creates a [LoaderThemeExtensionDefault] from a light [ThemeData]
|
||||
factory LoaderThemeExtensionDefault.light() =>
|
||||
LoaderThemeExtensionDefault.from(ThemeData.light());
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:wyatt_ui_components/src/domain/theme_extensions/rich_text_builder_theme_extension.dart';
|
||||
|
||||
class RichTextBuilderThemeExtensionDefault
|
||||
extends RichTextBuilderThemeExtension {
|
||||
const RichTextBuilderThemeExtensionDefault({
|
||||
required super.defaultStyle,
|
||||
required super.styles,
|
||||
});
|
||||
|
||||
/// Creates a [RichTextBuilderThemeExtensionDefault] from a [ThemeData]
|
||||
/// and opinionated defaults.
|
||||
///
|
||||
/// {@macro card_theme_extension_default}
|
||||
factory RichTextBuilderThemeExtensionDefault.from(ThemeData theme) =>
|
||||
RichTextBuilderThemeExtensionDefault(
|
||||
defaultStyle: theme.textTheme.bodyMedium,
|
||||
styles: {
|
||||
'blue': theme.textTheme.bodyMedium?.copyWith(
|
||||
color: Colors.blue,
|
||||
) ??
|
||||
const TextStyle(
|
||||
color: Colors.blue,
|
||||
),
|
||||
'red': theme.textTheme.bodyMedium?.copyWith(
|
||||
color: Colors.red,
|
||||
) ??
|
||||
const TextStyle(
|
||||
color: Colors.red,
|
||||
),
|
||||
'green': theme.textTheme.bodyMedium?.copyWith(
|
||||
color: Colors.green,
|
||||
) ??
|
||||
const TextStyle(
|
||||
color: Colors.green,
|
||||
),
|
||||
'bold': theme.textTheme.bodyMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
) ??
|
||||
const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
'italic': theme.textTheme.bodyMedium?.copyWith(
|
||||
fontStyle: FontStyle.italic,
|
||||
) ??
|
||||
const TextStyle(fontStyle: FontStyle.italic),
|
||||
},
|
||||
);
|
||||
|
||||
/// Creates a [RichTextBuilderThemeExtensionDefault] from a dark [ThemeData]
|
||||
factory RichTextBuilderThemeExtensionDefault.dark() =>
|
||||
RichTextBuilderThemeExtensionDefault.from(ThemeData.dark());
|
||||
|
||||
/// Creates a [RichTextBuilderThemeExtensionDefault] from a light [ThemeData]
|
||||
factory RichTextBuilderThemeExtensionDefault.light() =>
|
||||
RichTextBuilderThemeExtensionDefault.from(ThemeData.light());
|
||||
}
|
||||
@@ -16,4 +16,7 @@
|
||||
|
||||
export 'button_theme_extension/button_theme_extension.dart';
|
||||
export 'card_theme_extension_default.dart';
|
||||
export 'loader_theme_extension_default.dart';
|
||||
export 'rich_text_builder_theme_extension_default.dart';
|
||||
export 'text_input_theme_extension_default.dart';
|
||||
export 'top_bar_theme_extension_default.dart';
|
||||
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:wyatt_ui_components/wyatt_ui_components.dart';
|
||||
|
||||
class TopBarThemeExtensionDefault extends TopBarThemeExtension {
|
||||
const TopBarThemeExtensionDefault({
|
||||
required super.iconTheme,
|
||||
required super.backgroundColors,
|
||||
required super.titleStyle,
|
||||
required super.subtitleStyle,
|
||||
required super.selectedIndicatorColors,
|
||||
required super.selectedIndicatorSize,
|
||||
required super.dividerColor,
|
||||
});
|
||||
|
||||
/// Creates a [TopBarThemeExtensionDefault] from a [ThemeData]
|
||||
/// and opinionated defaults.
|
||||
///
|
||||
/// {@macro card_theme_extension_default}
|
||||
factory TopBarThemeExtensionDefault.from(ThemeData theme) =>
|
||||
TopBarThemeExtensionDefault(
|
||||
backgroundColors: MultiColor.single(theme.appBarTheme.backgroundColor),
|
||||
titleStyle:
|
||||
theme.appBarTheme.titleTextStyle ?? theme.textTheme.titleMedium,
|
||||
subtitleStyle: theme.textTheme.bodyMedium,
|
||||
selectedIndicatorColors: MultiColor.single(theme.colorScheme.primary),
|
||||
selectedIndicatorSize: const Size(70, 5),
|
||||
iconTheme: theme.iconTheme,
|
||||
dividerColor: theme.colorScheme.onSurface.withOpacity(0.12),
|
||||
);
|
||||
|
||||
/// Creates a [TopBarThemeExtensionDefault] from a dark [ThemeData]
|
||||
factory TopBarThemeExtensionDefault.dark() =>
|
||||
TopBarThemeExtensionDefault.from(ThemeData.dark());
|
||||
|
||||
/// Creates a [TopBarThemeExtensionDefault] from a light [ThemeData]
|
||||
factory TopBarThemeExtensionDefault.light() =>
|
||||
TopBarThemeExtensionDefault.from(ThemeData.light());
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:wyatt_ui_components/wyatt_ui_components.dart';
|
||||
|
||||
class LoaderThemeExtension extends ThemeExtension<LoaderThemeExtension> {
|
||||
const LoaderThemeExtension({
|
||||
this.colors,
|
||||
this.stroke,
|
||||
});
|
||||
|
||||
/// Gradient colors from start to end.
|
||||
final MultiColor? colors;
|
||||
|
||||
/// Loader stroke width
|
||||
final double? stroke;
|
||||
|
||||
@override
|
||||
ThemeExtension<LoaderThemeExtension> copyWith({
|
||||
MultiColor? colors,
|
||||
double? stroke,
|
||||
}) =>
|
||||
LoaderThemeExtension(
|
||||
colors: colors ?? this.colors,
|
||||
stroke: stroke ?? this.stroke,
|
||||
);
|
||||
|
||||
@override
|
||||
ThemeExtension<LoaderThemeExtension> lerp(
|
||||
covariant ThemeExtension<LoaderThemeExtension>? other,
|
||||
double t,
|
||||
) {
|
||||
if (other is! LoaderThemeExtension) {
|
||||
return this;
|
||||
}
|
||||
return LoaderThemeExtension(
|
||||
colors: MultiColor.lerp(colors, other.colors, t),
|
||||
stroke: lerpDouble(stroke, other.stroke, t),
|
||||
);
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class RichTextBuilderThemeExtension
|
||||
extends ThemeExtension<RichTextBuilderThemeExtension> {
|
||||
const RichTextBuilderThemeExtension({
|
||||
this.defaultStyle,
|
||||
this.styles,
|
||||
});
|
||||
|
||||
/// Default TextStyle used in this rich text component.
|
||||
final TextStyle? defaultStyle;
|
||||
|
||||
/// Used styles in this rich text component.
|
||||
final Map<String, TextStyle>? styles;
|
||||
|
||||
@override
|
||||
ThemeExtension<RichTextBuilderThemeExtension> copyWith({
|
||||
TextStyle? defaultStyle,
|
||||
Map<String, TextStyle>? styles,
|
||||
}) =>
|
||||
RichTextBuilderThemeExtension(
|
||||
defaultStyle: defaultStyle ?? this.defaultStyle,
|
||||
styles: styles ?? this.styles,
|
||||
);
|
||||
|
||||
@override
|
||||
ThemeExtension<RichTextBuilderThemeExtension> lerp(
|
||||
covariant ThemeExtension<RichTextBuilderThemeExtension>? other,
|
||||
double t,
|
||||
) {
|
||||
if (other is! RichTextBuilderThemeExtension) {
|
||||
return this;
|
||||
}
|
||||
return RichTextBuilderThemeExtension(
|
||||
defaultStyle: TextStyle.lerp(defaultStyle, other.defaultStyle, t),
|
||||
styles: styles,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -16,4 +16,7 @@
|
||||
|
||||
export 'button_theme_extension/button_theme_extension.dart';
|
||||
export 'card_theme_extension.dart';
|
||||
export 'loader_theme_extension.dart';
|
||||
export 'rich_text_builder_theme_extension.dart';
|
||||
export 'text_input_theme_extension.dart';
|
||||
export 'top_bar_theme_extension.dart';
|
||||
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:wyatt_ui_components/wyatt_ui_components.dart';
|
||||
|
||||
class TopBarThemeExtension extends ThemeExtension<TopBarThemeExtension> {
|
||||
const TopBarThemeExtension({
|
||||
this.iconTheme,
|
||||
this.backgroundColors,
|
||||
this.titleStyle,
|
||||
this.subtitleStyle,
|
||||
this.selectedIndicatorColors,
|
||||
this.selectedIndicatorSize,
|
||||
this.dividerColor,
|
||||
});
|
||||
|
||||
/// Background colors from start to end of the top bar.
|
||||
final MultiColor? backgroundColors;
|
||||
|
||||
/// Icon theme used in this top bar.
|
||||
final IconThemeData? iconTheme;
|
||||
|
||||
/// Selected indicator colors used in this top bar.
|
||||
final MultiColor? selectedIndicatorColors;
|
||||
|
||||
/// Divider color used in this top bar.
|
||||
final Color? dividerColor;
|
||||
|
||||
/// Title style used in this top bar.
|
||||
final TextStyle? titleStyle;
|
||||
|
||||
/// Subtitle style used in this top bar.
|
||||
final TextStyle? subtitleStyle;
|
||||
|
||||
/// Selected indicator size used in this top bar.
|
||||
final Size? selectedIndicatorSize;
|
||||
|
||||
@override
|
||||
ThemeExtension<TopBarThemeExtension> copyWith({
|
||||
MultiColor? backgroundColors,
|
||||
IconThemeData? iconTheme,
|
||||
MultiColor? selectedIndicatorColors,
|
||||
Color? dividerColor,
|
||||
TextStyle? titleStyle,
|
||||
TextStyle? subtitleStyle,
|
||||
Size? selectedIndicatorSize,
|
||||
}) =>
|
||||
TopBarThemeExtension(
|
||||
iconTheme: iconTheme ?? this.iconTheme,
|
||||
backgroundColors: backgroundColors ?? this.backgroundColors,
|
||||
selectedIndicatorColors:
|
||||
selectedIndicatorColors ?? this.selectedIndicatorColors,
|
||||
dividerColor: dividerColor ?? this.dividerColor,
|
||||
titleStyle: titleStyle ?? this.titleStyle,
|
||||
subtitleStyle: subtitleStyle ?? this.subtitleStyle,
|
||||
selectedIndicatorSize:
|
||||
selectedIndicatorSize ?? this.selectedIndicatorSize,
|
||||
);
|
||||
|
||||
@override
|
||||
ThemeExtension<TopBarThemeExtension> lerp(
|
||||
covariant ThemeExtension<TopBarThemeExtension>? other,
|
||||
double t,
|
||||
) {
|
||||
if (other is! TopBarThemeExtension) {
|
||||
return this;
|
||||
}
|
||||
return TopBarThemeExtension(
|
||||
iconTheme: IconThemeData.lerp(iconTheme, other.iconTheme, t),
|
||||
backgroundColors:
|
||||
MultiColor.lerp(backgroundColors, other.backgroundColors, t),
|
||||
selectedIndicatorColors: MultiColor.lerp(
|
||||
selectedIndicatorColors, other.selectedIndicatorColors, t,),
|
||||
dividerColor: Color.lerp(dividerColor, other.dividerColor, t),
|
||||
titleStyle: TextStyle.lerp(titleStyle, other.titleStyle, t),
|
||||
subtitleStyle: TextStyle.lerp(subtitleStyle, other.subtitleStyle, t),
|
||||
selectedIndicatorSize:
|
||||
Size.lerp(selectedIndicatorSize, other.selectedIndicatorSize, t),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:wyatt_ui_components/src/features/features.dart';
|
||||
import 'package:wyatt_ui_components/wyatt_ui_components.dart';
|
||||
|
||||
/// {@template component_theme}
|
||||
/// A [ComponentTheme] widget that provides a [ComponentThemeData] to its
|
||||
@@ -25,11 +25,22 @@ class ComponentTheme extends StatelessWidget {
|
||||
/// {@macro component_theme}
|
||||
const ComponentTheme({
|
||||
required this.child,
|
||||
required this.componentThemeWidget,
|
||||
required this.data,
|
||||
this.themeExtensionProvider = const DefaultThemeExtensionProvider(),
|
||||
super.key,
|
||||
});
|
||||
|
||||
/// The [ComponentThemeData] of this widget.
|
||||
///
|
||||
/// This contains all components instances of the theme.
|
||||
final ComponentThemeData data;
|
||||
|
||||
/// The [ThemeExtensionProvider] that provides the extensions for the
|
||||
/// current theme.
|
||||
final ThemeExtensionProvider themeExtensionProvider;
|
||||
|
||||
/// The widget below this widget in the tree.
|
||||
final Widget child;
|
||||
final ComponentThemeData componentThemeWidget;
|
||||
|
||||
/// Returns the [ComponentThemeData] of the closest ancestor [ComponentTheme]
|
||||
/// widget. If there is no ancestor [ComponentTheme] widget, it throws an
|
||||
@@ -42,7 +53,7 @@ class ComponentTheme extends StatelessWidget {
|
||||
inheritedThemeComponent != null,
|
||||
'Theme component not find in tree',
|
||||
);
|
||||
return inheritedThemeComponent!.themeWidget.componentThemeWidget;
|
||||
return inheritedThemeComponent!.themeWidget.data;
|
||||
}
|
||||
|
||||
/// Returns the [ComponentThemeData] of the closest ancestor [ComponentTheme]
|
||||
@@ -51,13 +62,17 @@ class ComponentTheme extends StatelessWidget {
|
||||
final _InheritedComponentTheme? inheritedThemeComponent =
|
||||
context.dependOnInheritedWidgetOfExactType<_InheritedComponentTheme>();
|
||||
|
||||
return inheritedThemeComponent?.themeWidget.componentThemeWidget;
|
||||
return inheritedThemeComponent?.themeWidget.data;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => _InheritedComponentTheme(
|
||||
this,
|
||||
child: child,
|
||||
Widget build(BuildContext context) => Theme(
|
||||
// Injections of the default extensions for the current brightness
|
||||
data: themeExtensionProvider.applyExtensionsTo(Theme.of(context)),
|
||||
child: _InheritedComponentTheme(
|
||||
this,
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,3 +16,4 @@
|
||||
|
||||
export 'component_theme.dart';
|
||||
export 'component_theme_data.dart';
|
||||
export 'theme_extension_provider.dart';
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:wyatt_ui_components/wyatt_ui_components.dart';
|
||||
|
||||
/// {@template theme_extension_provider}
|
||||
/// A provider of [ThemeExtension]s to automatically apply to a [Theme].
|
||||
/// {@endtemplate}
|
||||
abstract class ThemeExtensionProvider {
|
||||
/// {@macro theme_extension_provider}
|
||||
const ThemeExtensionProvider();
|
||||
|
||||
/// Returns the [ThemeExtension]s to apply to the current [ThemeData].
|
||||
List<ThemeExtension<dynamic>> getThemeExtensionsFor(ThemeData theme);
|
||||
|
||||
/// Returns a [ThemeData] with the [ThemeExtension]s applied.
|
||||
ThemeData applyExtensionsTo(
|
||||
ThemeData theme,
|
||||
) =>
|
||||
theme.copyWith(
|
||||
extensions: [
|
||||
...theme.extensions.values,
|
||||
...getThemeExtensionsFor(theme),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// {@template default_theme_extension_provider}
|
||||
/// A [ThemeExtensionProvider] that provides the default [ThemeExtension]s
|
||||
/// for the current [ThemeData.brightness].
|
||||
/// {@endtemplate}
|
||||
class DefaultThemeExtensionProvider extends ThemeExtensionProvider {
|
||||
/// {@macro default_theme_extension_provider}
|
||||
const DefaultThemeExtensionProvider();
|
||||
|
||||
/// Default light theme extensions form Wyatt UI Components
|
||||
///
|
||||
/// This needs to be added to the [ThemeData] in order to use the
|
||||
/// Wyatt UI Components widgets.
|
||||
///
|
||||
/// Those extensions are the default ones used in fallback mode
|
||||
/// when no custom theme is provided.
|
||||
///
|
||||
/// See `wyatt_ui_kit` for a custom theme example.
|
||||
static List<ThemeExtension<dynamic>> get defaultLight => [
|
||||
// Cards
|
||||
CardThemeExtensionDefault.light(),
|
||||
// Loader
|
||||
LoaderThemeExtensionDefault.light(),
|
||||
// RichText
|
||||
RichTextBuilderThemeExtensionDefault.light(),
|
||||
// Buttons
|
||||
FileSelectionButtonThemeExtensionDefault.light(),
|
||||
FlatButtonThemeExtensionDefault.light(),
|
||||
SimpleIconButtonThemeExtensionDefault.light(),
|
||||
SymbolButtonThemeExtensionDefault.light(),
|
||||
// TextInput
|
||||
TextInputThemeExtensionDefault.light(),
|
||||
// TopBar
|
||||
TopBarThemeExtensionDefault.light(),
|
||||
];
|
||||
|
||||
/// Default dark theme extensions form Wyatt UI Components
|
||||
///
|
||||
/// This needs to be added to the [ThemeData] in order to use the
|
||||
/// Wyatt UI Components widgets.
|
||||
///
|
||||
/// Those extensions are the default ones used in fallback mode
|
||||
/// when no custom theme is provided.
|
||||
///
|
||||
/// See `wyatt_ui_kit` for a custom theme example.
|
||||
static List<ThemeExtension<dynamic>> get defaultDark => [
|
||||
// Cards
|
||||
CardThemeExtensionDefault.dark(),
|
||||
// Loader
|
||||
LoaderThemeExtensionDefault.dark(),
|
||||
// RichText
|
||||
RichTextBuilderThemeExtensionDefault.dark(),
|
||||
// Buttons
|
||||
FileSelectionButtonThemeExtensionDefault.dark(),
|
||||
FlatButtonThemeExtensionDefault.dark(),
|
||||
SimpleIconButtonThemeExtensionDefault.dark(),
|
||||
SymbolButtonThemeExtensionDefault.dark(),
|
||||
// TextInput
|
||||
TextInputThemeExtensionDefault.dark(),
|
||||
// TopBar
|
||||
TopBarThemeExtensionDefault.dark(),
|
||||
];
|
||||
|
||||
@override
|
||||
List<ThemeExtension<dynamic>> getThemeExtensionsFor(ThemeData theme) =>
|
||||
theme.brightness == Brightness.light ? defaultLight : defaultDark;
|
||||
}
|
||||
Reference in New Issue
Block a user