Compare commits
No commits in common. "4c08a692d2013a0732e0bacbe70c88db78eb2d98" and "1af9b0b1f1426f1815eff2b2228ab9e74a06873f" have entirely different histories.
4c08a692d2
...
1af9b0b1f1
@ -15,7 +15,6 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:wyatt_ui_components/src/domain/entities/theme_style.dart';
|
||||
|
||||
/// {@template theme_resolver}
|
||||
/// In charge of theme negotiation and merge.
|
||||
@ -31,7 +30,7 @@ import 'package:wyatt_ui_components/src/domain/entities/theme_style.dart';
|
||||
/// - If the value is mandatory: a hardcoded value in "wyatt_ui_kit" is chosen.
|
||||
/// - If not, the style is simply not applied.
|
||||
/// {@endtemplate}
|
||||
abstract class ThemeResolver<S extends ThemeStyle<S>, T, E> {
|
||||
abstract class ThemeResolver<S, T, E> {
|
||||
/// {@macro theme_resolver}
|
||||
const ThemeResolver();
|
||||
|
||||
@ -82,13 +81,8 @@ abstract class ThemeResolver<S extends ThemeStyle<S>, T, E> {
|
||||
/// Choose most suitable style for a given context.
|
||||
S negotiate(BuildContext context, {E? extra}) {
|
||||
S style = computeDefaultValue(context, extra: extra);
|
||||
final S? extensionStyle =
|
||||
computeExtensionValue(context, style, extra: extra);
|
||||
|
||||
style = style.mergeWith(extensionStyle);
|
||||
|
||||
final S? customStyle = computeCustomValue(context, style, extra: extra);
|
||||
|
||||
return style.mergeWith(customStyle);
|
||||
style = computeExtensionValue(context, style, extra: extra) ?? style;
|
||||
style = computeCustomValue(context, style, extra: extra) ?? style;
|
||||
return style;
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ abstract class ButtonComponent extends Component {
|
||||
this.selectedStyle,
|
||||
this.invalidStyle,
|
||||
this.onPressed,
|
||||
super.themeResolver,
|
||||
this.themeResolver,
|
||||
super.key,
|
||||
});
|
||||
|
||||
@ -53,4 +53,7 @@ abstract class ButtonComponent extends Component {
|
||||
|
||||
/// Callback on button press
|
||||
final void Function(ControlState state)? onPressed;
|
||||
|
||||
/// Theme Resolver for this component
|
||||
final ThemeResolver<dynamic, dynamic, dynamic>? themeResolver;
|
||||
}
|
||||
|
@ -16,9 +16,8 @@
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:wyatt_ui_components/src/core/utils/multi_color.dart';
|
||||
import 'package:wyatt_ui_components/src/domain/entities/theme_style.dart';
|
||||
|
||||
abstract class ButtonStyle<T> extends ThemeStyle<T> {
|
||||
abstract class ButtonStyle<T> {
|
||||
const ButtonStyle({
|
||||
this.radius,
|
||||
this.padding,
|
||||
|
@ -37,31 +37,6 @@ class FileSelectionButtonStyle extends ButtonStyle<FileSelectionButtonStyle> {
|
||||
super.shadow,
|
||||
});
|
||||
|
||||
/// Merges non-null `b` attributes in `a`
|
||||
static FileSelectionButtonStyle? merge(
|
||||
FileSelectionButtonStyle? a,
|
||||
FileSelectionButtonStyle? b,
|
||||
) {
|
||||
if (b == null) {
|
||||
return a?.copyWith();
|
||||
}
|
||||
if (a == null) {
|
||||
return b.copyWith();
|
||||
}
|
||||
|
||||
return a.copyWith(
|
||||
title: b.title,
|
||||
subTitle: b.subTitle,
|
||||
radius: b.radius,
|
||||
padding: b.padding,
|
||||
foregroundColors: b.foregroundColors,
|
||||
backgroundColors: b.backgroundColors,
|
||||
borderColors: b.borderColors,
|
||||
stroke: b.stroke,
|
||||
shadow: b.shadow,
|
||||
);
|
||||
}
|
||||
|
||||
/// Used for interpolation.
|
||||
static FileSelectionButtonStyle? lerp(
|
||||
FileSelectionButtonStyle? a,
|
||||
@ -106,15 +81,4 @@ class FileSelectionButtonStyle extends ButtonStyle<FileSelectionButtonStyle> {
|
||||
///
|
||||
/// Default to `TextTheme.labelSmall`
|
||||
final TextStyle? subTitle;
|
||||
|
||||
@override
|
||||
FileSelectionButtonStyle mergeWith(FileSelectionButtonStyle? other) =>
|
||||
FileSelectionButtonStyle.merge(this, other)!;
|
||||
|
||||
@override
|
||||
FileSelectionButtonStyle? lerpWith(
|
||||
FileSelectionButtonStyle? other,
|
||||
double t,
|
||||
) =>
|
||||
FileSelectionButtonStyle.lerp(this, other, t);
|
||||
}
|
||||
|
@ -36,30 +36,6 @@ class FlatButtonStyle extends ButtonStyle<FlatButtonStyle> {
|
||||
super.shadow,
|
||||
});
|
||||
|
||||
/// Merges non-null `b` attributes in `a`
|
||||
static FlatButtonStyle? merge(
|
||||
FlatButtonStyle? a,
|
||||
FlatButtonStyle? b,
|
||||
) {
|
||||
if (b == null) {
|
||||
return a?.copyWith();
|
||||
}
|
||||
if (a == null) {
|
||||
return b.copyWith();
|
||||
}
|
||||
|
||||
return a.copyWith(
|
||||
label: b.label,
|
||||
radius: b.radius,
|
||||
padding: b.padding,
|
||||
foregroundColors: b.foregroundColors,
|
||||
backgroundColors: b.backgroundColors,
|
||||
borderColors: b.borderColors,
|
||||
stroke: b.stroke,
|
||||
shadow: b.shadow,
|
||||
);
|
||||
}
|
||||
|
||||
/// Used for interpolation.
|
||||
static FlatButtonStyle? lerp(
|
||||
FlatButtonStyle? a,
|
||||
@ -100,10 +76,6 @@ class FlatButtonStyle extends ButtonStyle<FlatButtonStyle> {
|
||||
final TextStyle? label;
|
||||
|
||||
@override
|
||||
FlatButtonStyle mergeWith(FlatButtonStyle? other) =>
|
||||
FlatButtonStyle.merge(this, other)!;
|
||||
|
||||
@override
|
||||
FlatButtonStyle? lerpWith(FlatButtonStyle? other, double t) =>
|
||||
FlatButtonStyle.lerp(this, other, t);
|
||||
String toString() =>
|
||||
'FlatButtonStyle(label: $label), inherited: ${super.toString()}';
|
||||
}
|
||||
|
@ -36,30 +36,6 @@ class SimpleIconButtonStyle extends ButtonStyle<SimpleIconButtonStyle> {
|
||||
super.shadow,
|
||||
});
|
||||
|
||||
/// Merges non-null `b` attributes in `a`
|
||||
static SimpleIconButtonStyle? merge(
|
||||
SimpleIconButtonStyle? a,
|
||||
SimpleIconButtonStyle? b,
|
||||
) {
|
||||
if (b == null) {
|
||||
return a?.copyWith();
|
||||
}
|
||||
if (a == null) {
|
||||
return b.copyWith();
|
||||
}
|
||||
|
||||
return a.copyWith(
|
||||
dimension: b.dimension,
|
||||
radius: b.radius,
|
||||
padding: b.padding,
|
||||
foregroundColors: b.foregroundColors,
|
||||
backgroundColors: b.backgroundColors,
|
||||
borderColors: b.borderColors,
|
||||
stroke: b.stroke,
|
||||
shadow: b.shadow,
|
||||
);
|
||||
}
|
||||
|
||||
/// Used for interpolation.
|
||||
static SimpleIconButtonStyle? lerp(
|
||||
SimpleIconButtonStyle? a,
|
||||
@ -98,12 +74,4 @@ class SimpleIconButtonStyle extends ButtonStyle<SimpleIconButtonStyle> {
|
||||
///
|
||||
/// Default to `context.buttonTheme.height`
|
||||
final double? dimension;
|
||||
|
||||
@override
|
||||
SimpleIconButtonStyle mergeWith(SimpleIconButtonStyle? other) =>
|
||||
SimpleIconButtonStyle.merge(this, other)!;
|
||||
|
||||
@override
|
||||
SimpleIconButtonStyle? lerpWith(SimpleIconButtonStyle? other, double t) =>
|
||||
SimpleIconButtonStyle.lerp(this, other, t);
|
||||
}
|
||||
|
@ -37,31 +37,6 @@ class SymbolButtonStyle extends ButtonStyle<SymbolButtonStyle> {
|
||||
super.shadow,
|
||||
});
|
||||
|
||||
/// Merges non-null `b` attributes in `a`
|
||||
static SymbolButtonStyle? merge(
|
||||
SymbolButtonStyle? a,
|
||||
SymbolButtonStyle? b,
|
||||
) {
|
||||
if (b == null) {
|
||||
return a?.copyWith();
|
||||
}
|
||||
if (a == null) {
|
||||
return b.copyWith();
|
||||
}
|
||||
|
||||
return a.copyWith(
|
||||
label: b.label,
|
||||
dimension: b.dimension,
|
||||
radius: b.radius,
|
||||
padding: b.padding,
|
||||
foregroundColors: b.foregroundColors,
|
||||
backgroundColors: b.backgroundColors,
|
||||
borderColors: b.borderColors,
|
||||
stroke: b.stroke,
|
||||
shadow: b.shadow,
|
||||
);
|
||||
}
|
||||
|
||||
/// Used for interpolation.
|
||||
static SymbolButtonStyle? lerp(
|
||||
SymbolButtonStyle? a,
|
||||
@ -106,12 +81,4 @@ class SymbolButtonStyle extends ButtonStyle<SymbolButtonStyle> {
|
||||
///
|
||||
/// Default to `context.buttonTheme.height`
|
||||
final double? dimension;
|
||||
|
||||
@override
|
||||
SymbolButtonStyle mergeWith(SymbolButtonStyle? other) =>
|
||||
SymbolButtonStyle.merge(this, other)!;
|
||||
|
||||
@override
|
||||
SymbolButtonStyle? lerpWith(SymbolButtonStyle? other, double t) =>
|
||||
SymbolButtonStyle.lerp(this, other, t);
|
||||
}
|
||||
|
@ -15,11 +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/core/utils/theme_resolver.dart';
|
||||
|
||||
abstract class Component extends StatelessWidget {
|
||||
const Component({this.themeResolver, super.key});
|
||||
|
||||
/// Theme Resolver for this component
|
||||
final ThemeResolver<dynamic, dynamic, dynamic>? themeResolver;
|
||||
const Component({super.key});
|
||||
}
|
||||
|
@ -21,4 +21,3 @@ export './cards/cards.dart';
|
||||
export './component.dart';
|
||||
export './error_widget_component.dart';
|
||||
export './loading_widget_component.dart';
|
||||
export './theme_style.dart';
|
||||
|
@ -1,36 +0,0 @@
|
||||
// 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:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
class ExportableBloc<T extends StateStreamableSource<Object?>>
|
||||
extends StatelessWidget {
|
||||
const ExportableBloc({
|
||||
required this.bloc,
|
||||
required this.child,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final T bloc;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => BlocProvider<T>.value(
|
||||
value: bloc,
|
||||
child: child,
|
||||
);
|
||||
}
|
@ -18,15 +18,15 @@ import 'package:flutter/material.dart' hide ButtonStyle;
|
||||
import 'package:wyatt_component_copy_with_extension/component_copy_with_extension.dart';
|
||||
import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart';
|
||||
import 'package:wyatt_ui_kit/src/components/buttons/cubit/invalid_button_cubit.dart';
|
||||
import 'package:wyatt_ui_kit/src/components/buttons/exportable_bloc.dart';
|
||||
import 'package:wyatt_ui_kit/src/components/buttons/file_selection_button/file_selection_button_screen.dart';
|
||||
import 'package:wyatt_ui_kit/src/components/buttons/file_selection_button/file_selection_button_theme_resolver.dart';
|
||||
import 'package:wyatt_ui_kit/src/core/mixin/export_bloc_mixin.dart';
|
||||
|
||||
part 'file_selection_button.g.dart';
|
||||
|
||||
@ComponentCopyWithExtension()
|
||||
class FileSelectionButton extends FileSelectionButtonComponent
|
||||
with $FileSelectionButtonCWMixin {
|
||||
with $FileSelectionButtonCWMixin, ExportBloc<InvalidButtonCubit> {
|
||||
FileSelectionButton({
|
||||
super.leading,
|
||||
super.title,
|
||||
@ -46,6 +46,7 @@ class FileSelectionButton extends FileSelectionButtonComponent
|
||||
|
||||
final InvalidButtonCubit _cubit = InvalidButtonCubit();
|
||||
|
||||
@override
|
||||
InvalidButtonCubit get bloc => _cubit;
|
||||
|
||||
@override
|
||||
@ -81,8 +82,7 @@ class FileSelectionButton extends FileSelectionButtonComponent
|
||||
super.themeResolver as FileSelectionButtonThemeResolver?;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => ExportableBloc(
|
||||
bloc: _cubit,
|
||||
Widget build(BuildContext context) => exportBloc(
|
||||
child: FileSelectionButtonScreen(
|
||||
leading: leading,
|
||||
title: title,
|
||||
|
@ -18,14 +18,15 @@ import 'package:flutter/material.dart' hide ButtonStyle;
|
||||
import 'package:wyatt_component_copy_with_extension/component_copy_with_extension.dart';
|
||||
import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart';
|
||||
import 'package:wyatt_ui_kit/src/components/buttons/cubit/button_cubit.dart';
|
||||
import 'package:wyatt_ui_kit/src/components/buttons/exportable_bloc.dart';
|
||||
import 'package:wyatt_ui_kit/src/components/buttons/flat_button/flat_button_screen.dart';
|
||||
import 'package:wyatt_ui_kit/src/components/buttons/flat_button/flat_button_theme_resolver.dart';
|
||||
import 'package:wyatt_ui_kit/src/core/mixin/export_bloc_mixin.dart';
|
||||
|
||||
part 'flat_button.g.dart';
|
||||
|
||||
@ComponentCopyWithExtension()
|
||||
class FlatButton extends FlatButtonComponent with $FlatButtonCWMixin {
|
||||
class FlatButton extends FlatButtonComponent
|
||||
with $FlatButtonCWMixin, ExportBloc<ButtonCubit> {
|
||||
FlatButton({
|
||||
super.prefix,
|
||||
super.suffix,
|
||||
@ -43,6 +44,7 @@ class FlatButton extends FlatButtonComponent with $FlatButtonCWMixin {
|
||||
|
||||
final ButtonCubit _cubit = ButtonCubit();
|
||||
|
||||
@override
|
||||
ButtonCubit get bloc => _cubit;
|
||||
|
||||
@override
|
||||
@ -65,8 +67,7 @@ class FlatButton extends FlatButtonComponent with $FlatButtonCWMixin {
|
||||
super.themeResolver as FlatButtonThemeResolver?;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => ExportableBloc(
|
||||
bloc: _cubit,
|
||||
Widget build(BuildContext context) => exportBloc(
|
||||
child: FlatButtonScreen(
|
||||
prefix: prefix,
|
||||
suffix: suffix,
|
||||
|
@ -18,15 +18,15 @@ import 'package:flutter/material.dart' hide ButtonStyle;
|
||||
import 'package:wyatt_component_copy_with_extension/component_copy_with_extension.dart';
|
||||
import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart';
|
||||
import 'package:wyatt_ui_kit/src/components/buttons/cubit/button_cubit.dart';
|
||||
import 'package:wyatt_ui_kit/src/components/buttons/exportable_bloc.dart';
|
||||
import 'package:wyatt_ui_kit/src/components/buttons/simple_icon_button/simple_icon_button_theme_resolver.dart';
|
||||
import 'package:wyatt_ui_kit/src/components/buttons/simple_icon_button/simple_icon_screen.dart';
|
||||
import 'package:wyatt_ui_kit/src/core/mixin/export_bloc_mixin.dart';
|
||||
|
||||
part 'simple_icon_button.g.dart';
|
||||
|
||||
@ComponentCopyWithExtension()
|
||||
class SimpleIconButton extends SimpleIconButtonComponent
|
||||
with $SimpleIconButtonCWMixin {
|
||||
with $SimpleIconButtonCWMixin, ExportBloc<ButtonCubit> {
|
||||
SimpleIconButton({
|
||||
super.icon,
|
||||
super.disabledStyle,
|
||||
@ -41,6 +41,7 @@ class SimpleIconButton extends SimpleIconButtonComponent
|
||||
|
||||
final ButtonCubit _cubit = ButtonCubit();
|
||||
|
||||
@override
|
||||
ButtonCubit get bloc => _cubit;
|
||||
|
||||
@override
|
||||
@ -68,8 +69,7 @@ class SimpleIconButton extends SimpleIconButtonComponent
|
||||
super.themeResolver as SimpleIconButtonThemeResolver?;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => ExportableBloc(
|
||||
bloc: _cubit,
|
||||
Widget build(BuildContext context) => exportBloc(
|
||||
child: SimpleIconButtonScreen(
|
||||
icon: icon,
|
||||
disabledStyle: disabledStyle,
|
||||
|
@ -18,15 +18,15 @@ import 'package:flutter/material.dart' hide ButtonStyle;
|
||||
import 'package:wyatt_component_copy_with_extension/component_copy_with_extension.dart';
|
||||
import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart';
|
||||
import 'package:wyatt_ui_kit/src/components/buttons/cubit/selectable_button_cubit.dart';
|
||||
import 'package:wyatt_ui_kit/src/components/buttons/exportable_bloc.dart';
|
||||
import 'package:wyatt_ui_kit/src/components/buttons/symbol_button/symbol_button_screen.dart';
|
||||
import 'package:wyatt_ui_kit/src/components/buttons/symbol_button/symbol_button_theme_resolver.dart';
|
||||
import 'package:wyatt_ui_kit/src/core/mixin/export_bloc_mixin.dart';
|
||||
|
||||
part 'symbol_button.g.dart';
|
||||
|
||||
@ComponentCopyWithExtension()
|
||||
class SymbolButton extends SymbolButtonComponent
|
||||
with $SymbolButtonCWMixin{
|
||||
with $SymbolButtonCWMixin, ExportBloc<SelectableButtonCubit> {
|
||||
SymbolButton({
|
||||
super.icon,
|
||||
super.label,
|
||||
@ -44,6 +44,7 @@ class SymbolButton extends SymbolButtonComponent
|
||||
|
||||
final SelectableButtonCubit _cubit = SelectableButtonCubit();
|
||||
|
||||
@override
|
||||
SelectableButtonCubit get bloc => _cubit;
|
||||
|
||||
@override
|
||||
@ -73,8 +74,7 @@ class SymbolButton extends SymbolButtonComponent
|
||||
super.themeResolver as SymbolButtonThemeResolver?;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => ExportableBloc(
|
||||
bloc: _cubit,
|
||||
Widget build(BuildContext context) => exportBloc(
|
||||
child: SymbolButtonScreen(
|
||||
icon: icon,
|
||||
label: label,
|
||||
|
@ -14,12 +14,13 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
abstract class ThemeStyle<T> {
|
||||
const ThemeStyle();
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
/// Merges non-null `other` attributes in `this` and returns a copy.
|
||||
T mergeWith(T? other);
|
||||
|
||||
/// Used for interpolation.
|
||||
T? lerpWith(T? other, double t);
|
||||
mixin ExportBloc<T extends StateStreamableSource<Object?>> {
|
||||
T get bloc;
|
||||
Widget exportBloc({required Widget child}) => BlocProvider<T>.value(
|
||||
value: bloc,
|
||||
child: child,
|
||||
);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user