Compare commits

..

8 Commits

86 changed files with 405 additions and 2179 deletions

View File

@ -20,12 +20,12 @@ name: default
steps: steps:
- name: quality-check - name: quality-check
image: git.wyatt-studio.fr/wyatt-foss/flutter-melos:2.9.0-1 image: git.wyatt-studio.fr/wyatt-foss/flutter-melos:2.9.0
commands: commands:
- melos run quality-check - melos run quality-check
- melos run publish:validate - melos run publish:validate
- name: publish - name: publish
image: git.wyatt-studio.fr/wyatt-foss/flutter-melos:2.9.0-1 image: git.wyatt-studio.fr/wyatt-foss/flutter-melos:2.9.0
commands: commands:
- melos run publish:validate - melos run publish:validate

View File

@ -1,9 +0,0 @@
targets:
$default:
builders:
# Typically the builder key is just the package name, run `pub run build_runner doctor` to check your config.
wyatt_component_copy_with_gen:component_copy_with_gen:
generate_for:
# Example glob for only the Dart files under `lib/models`
- lib/**/*.dart
- example/lib/**/*.dart

View File

@ -15,11 +15,10 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; import 'package:wyatt_ui_components/src/core/utils/text_wrapper.dart';
extension StringExtension on String? { extension StringExtension on String? {
TextWrapper? wrap({TextStyle? style, MultiColor? gradientColors}) => TextWrapper? wrap({TextStyle? style, List<Color>? gradient}) => this != null
this != null ? TextWrapper(this!, style: style, gradient: gradient)
? TextWrapper(this!, style: style, gradientColors: gradientColors)
: null; : null;
} }

View File

@ -15,22 +15,17 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart';
/// Wraps [String] and [TextStyle] into one object that can be
/// a [Text] or a [RichText].
class TextWrapper { class TextWrapper {
const TextWrapper( const TextWrapper(
this.text, { this.text, {
this.style, this.style,
this.gradientColors, this.gradient,
}); });
const TextWrapper.text(this.text) factory TextWrapper.text(String text) => TextWrapper(text);
: style = null,
gradientColors = null;
final String text; final String text;
final TextStyle? style; final TextStyle? style;
final MultiColor? gradientColors; final List<Color>? gradient;
} }

View File

@ -15,7 +15,6 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:wyatt_ui_components/src/domain/entities/theme_style.dart';
/// {@template theme_resolver} /// {@template theme_resolver}
/// In charge of theme negotiation and merge. /// In charge of theme negotiation and merge.
@ -31,59 +30,63 @@ 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 the value is mandatory: a hardcoded value in "wyatt_ui_kit" is chosen.
/// - If not, the style is simply not applied. /// - If not, the style is simply not applied.
/// {@endtemplate} /// {@endtemplate}
abstract class ThemeResolver<S extends ThemeStyle<S>, T, E> { abstract class ThemeResolver<S, T, E> {
/// {@macro theme_resolver} /// {@macro theme_resolver}
const ThemeResolver(); const ThemeResolver();
S? Function(BuildContext context, {E? extra}) get customStyleFn; S? Function(BuildContext context, S extensionValue, {E? extra})
get customStyleFn;
/// Compute default value from Flutter Theme or with hardcoded values. /// Compute default value from Flutter Theme or with hardcoded values.
S computeDefaultValue(BuildContext context, {E? extra}); S computeDefaultValue(BuildContext context, {E? extra});
S? computeExtensionValueFn( S? computeExtensionValueFn(
BuildContext context, BuildContext context,
S defaultValue,
T themeExtension, { T themeExtension, {
E? extra, E? extra,
}); });
/// Compute values from the extension if found /// Compute values from the extension if found
S? _computeExtensionValue( S? _computeExtensionValue(
BuildContext context, { BuildContext context,
S defaultValue, {
E? extra, E? extra,
}) { }) {
final themeExtension = Theme.of(context).extension<T>(); final themeExtension = Theme.of(context).extension<T>();
if (themeExtension != null) { if (themeExtension != null) {
return computeExtensionValueFn( return computeExtensionValueFn(
context, context,
defaultValue,
themeExtension, themeExtension,
extra: extra, extra: extra,
); );
} }
return null; return defaultValue;
} }
/// Compute custom value /// Compute custom value
S? _computeCustomValue( S? _computeCustomValue(
BuildContext context, { BuildContext context,
S previousPhaseValue, {
E? extra, E? extra,
}) { }) {
final customStyle = customStyleFn( final customStyle = customStyleFn(
context, context,
previousPhaseValue,
extra: extra, extra: extra,
); );
if (customStyle != null) { if (customStyle != null) {
return customStyle; return customStyle;
} }
return null; return previousPhaseValue;
} }
/// Choose most suitable style for a given context. /// Choose most suitable style for a given context.
S negotiate(BuildContext context, {E? extra}) { S negotiate(BuildContext context, {E? extra}) {
S style = computeDefaultValue(context, extra: extra); S style = computeDefaultValue(context, extra: extra);
style = style = _computeExtensionValue(context, style, extra: extra) ?? style;
style.mergeWith(_computeExtensionValue(context, extra: extra)) ?? style; style = _computeCustomValue(context, style, extra: extra) ?? style;
style =
style.mergeWith(_computeCustomValue(context, extra: extra)) ?? style;
return style; return style;
} }
} }

View File

@ -26,7 +26,7 @@ abstract class ButtonComponent extends Component {
this.selectedStyle, this.selectedStyle,
this.invalidStyle, this.invalidStyle,
this.onPressed, this.onPressed,
super.themeResolver, this.themeResolver,
super.key, super.key,
}); });
@ -53,4 +53,7 @@ abstract class ButtonComponent extends Component {
/// Callback on button press /// Callback on button press
final void Function(ControlState state)? onPressed; final void Function(ControlState state)? onPressed;
/// Theme Resolver for this component
final ThemeResolver<dynamic, dynamic, dynamic>? themeResolver;
} }

View File

@ -16,9 +16,8 @@
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:wyatt_ui_components/src/core/utils/multi_color.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({ const ButtonStyle({
this.radius, this.radius,
this.padding, this.padding,

View File

@ -20,6 +20,7 @@ import 'package:copy_with_extension/copy_with_extension.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:wyatt_ui_components/src/core/utils/multi_color.dart'; import 'package:wyatt_ui_components/src/core/utils/multi_color.dart';
import 'package:wyatt_ui_components/src/domain/entities/buttons/button_style.dart'; import 'package:wyatt_ui_components/src/domain/entities/buttons/button_style.dart';
part 'file_selection_button_style.g.dart'; part 'file_selection_button_style.g.dart';
@CopyWith() @CopyWith()
@ -36,31 +37,6 @@ class FileSelectionButtonStyle extends ButtonStyle<FileSelectionButtonStyle> {
super.shadow, 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. /// Used for interpolation.
static FileSelectionButtonStyle? lerp( static FileSelectionButtonStyle? lerp(
FileSelectionButtonStyle? a, FileSelectionButtonStyle? a,
@ -105,8 +81,4 @@ class FileSelectionButtonStyle extends ButtonStyle<FileSelectionButtonStyle> {
/// ///
/// Default to `TextTheme.labelSmall` /// Default to `TextTheme.labelSmall`
final TextStyle? subTitle; final TextStyle? subTitle;
@override
FileSelectionButtonStyle mergeWith(FileSelectionButtonStyle? other) =>
FileSelectionButtonStyle.merge(this, other)!;
} }

View File

@ -20,6 +20,7 @@ import 'package:copy_with_extension/copy_with_extension.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:wyatt_ui_components/src/core/utils/multi_color.dart'; import 'package:wyatt_ui_components/src/core/utils/multi_color.dart';
import 'package:wyatt_ui_components/src/domain/entities/buttons/button_style.dart'; import 'package:wyatt_ui_components/src/domain/entities/buttons/button_style.dart';
part 'flat_button_style.g.dart'; part 'flat_button_style.g.dart';
@CopyWith() @CopyWith()
@ -35,30 +36,6 @@ class FlatButtonStyle extends ButtonStyle<FlatButtonStyle> {
super.shadow, 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. /// Used for interpolation.
static FlatButtonStyle? lerp( static FlatButtonStyle? lerp(
FlatButtonStyle? a, FlatButtonStyle? a,
@ -99,6 +76,6 @@ class FlatButtonStyle extends ButtonStyle<FlatButtonStyle> {
final TextStyle? label; final TextStyle? label;
@override @override
FlatButtonStyle mergeWith(FlatButtonStyle? other) => String toString() =>
FlatButtonStyle.merge(this, other)!; 'FlatButtonStyle(label: $label), inherited: ${super.toString()}';
} }

View File

@ -20,6 +20,7 @@ import 'package:copy_with_extension/copy_with_extension.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:wyatt_ui_components/src/core/utils/multi_color.dart'; import 'package:wyatt_ui_components/src/core/utils/multi_color.dart';
import 'package:wyatt_ui_components/src/domain/entities/buttons/button_style.dart'; import 'package:wyatt_ui_components/src/domain/entities/buttons/button_style.dart';
part 'simple_icon_button_style.g.dart'; part 'simple_icon_button_style.g.dart';
@CopyWith() @CopyWith()
@ -35,30 +36,6 @@ class SimpleIconButtonStyle extends ButtonStyle<SimpleIconButtonStyle> {
super.shadow, 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. /// Used for interpolation.
static SimpleIconButtonStyle? lerp( static SimpleIconButtonStyle? lerp(
SimpleIconButtonStyle? a, SimpleIconButtonStyle? a,
@ -97,8 +74,4 @@ class SimpleIconButtonStyle extends ButtonStyle<SimpleIconButtonStyle> {
/// ///
/// Default to `context.buttonTheme.height` /// Default to `context.buttonTheme.height`
final double? dimension; final double? dimension;
@override
SimpleIconButtonStyle mergeWith(SimpleIconButtonStyle? other) =>
SimpleIconButtonStyle.merge(this, other)!;
} }

View File

@ -20,6 +20,7 @@ import 'package:copy_with_extension/copy_with_extension.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:wyatt_ui_components/src/core/utils/multi_color.dart'; import 'package:wyatt_ui_components/src/core/utils/multi_color.dart';
import 'package:wyatt_ui_components/src/domain/entities/buttons/button_style.dart'; import 'package:wyatt_ui_components/src/domain/entities/buttons/button_style.dart';
part 'symbol_button_style.g.dart'; part 'symbol_button_style.g.dart';
@CopyWith() @CopyWith()
@ -36,31 +37,6 @@ class SymbolButtonStyle extends ButtonStyle<SymbolButtonStyle> {
super.shadow, 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. /// Used for interpolation.
static SymbolButtonStyle? lerp( static SymbolButtonStyle? lerp(
SymbolButtonStyle? a, SymbolButtonStyle? a,
@ -105,8 +81,4 @@ class SymbolButtonStyle extends ButtonStyle<SymbolButtonStyle> {
/// ///
/// Default to `context.buttonTheme.height` /// Default to `context.buttonTheme.height`
final double? dimension; final double? dimension;
@override
SymbolButtonStyle mergeWith(SymbolButtonStyle? other) =>
SymbolButtonStyle.merge(this, other)!;
} }

View File

@ -15,11 +15,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:wyatt_ui_components/src/core/utils/theme_resolver.dart';
abstract class Component extends StatelessWidget { abstract class Component extends StatelessWidget {
const Component({this.themeResolver, super.key}); const Component({super.key});
/// Theme Resolver for this component
final ThemeResolver<dynamic, dynamic, dynamic>? themeResolver;
} }

View File

@ -20,9 +20,5 @@ export './buttons/buttons.dart';
export './cards/cards.dart'; export './cards/cards.dart';
export './component.dart'; export './component.dart';
export './error_widget_component.dart'; export './error_widget_component.dart';
export './loader_component.dart';
export './loader_style.dart';
export './loading_widget_component.dart'; export './loading_widget_component.dart';
export './rich_text_builder/rich_text_builder.dart';
export './text_inputs/text_inputs.dart'; export './text_inputs/text_inputs.dart';
export './theme_style.dart';

View File

@ -1,50 +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/widgets.dart';
import 'package:wyatt_component_copy_with_extension/component_copy_with_extension.dart';
import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart';
part 'loader_component.g.dart';
@ComponentProxyExtension()
abstract class LoaderComponent extends Component
with CopyWithMixin<$LoaderComponentCWProxy> {
const LoaderComponent({
this.colors,
this.radius,
this.stroke,
this.duration,
this.flip,
super.themeResolver,
super.key,
});
/// Gradient colors from start to end.
final MultiColor? colors;
/// Loader radius
final double? radius;
/// Loader stroke width
final double? stroke;
/// Animation duration
final Duration? duration;
/// Flip the animation
final bool? flip;
}

View File

@ -1,27 +0,0 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'loader_component.dart';
// **************************************************************************
// ComponentProxyGenerator
// **************************************************************************
abstract class $LoaderComponentCWProxy {
LoaderComponent colors(MultiColor? colors);
LoaderComponent radius(double? radius);
LoaderComponent stroke(double? stroke);
LoaderComponent duration(Duration? duration);
LoaderComponent flip(bool? flip);
LoaderComponent themeResolver(
ThemeResolver<dynamic, dynamic, dynamic>? themeResolver);
LoaderComponent key(Key? key);
LoaderComponent call({
MultiColor? colors,
double? radius,
double? stroke,
Duration? duration,
bool? flip,
ThemeResolver<dynamic, dynamic, dynamic>? themeResolver,
Key? key,
});
}

View File

@ -1,75 +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 'dart:ui';
import 'package:copy_with_extension/copy_with_extension.dart';
import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart';
part 'loader_style.g.dart';
@CopyWith()
class LoaderStyle extends ThemeStyle<LoaderStyle> {
const LoaderStyle({
this.colors,
this.stroke,
});
/// Merges non-null `b` attributes in `a`
static LoaderStyle? merge(
LoaderStyle? a,
LoaderStyle? b,
) {
if (b == null) {
return a?.copyWith();
}
if (a == null) {
return b.copyWith();
}
return a.copyWith(
colors: b.colors,
stroke: b.stroke,
);
}
/// Used for interpolation.
static LoaderStyle? lerp(
LoaderStyle? a,
LoaderStyle? b,
double t,
) {
if (a == null || b == null) {
return null;
}
// b.copyWith to return b attributes even if they are not lerped
return b.copyWith(
colors: MultiColor.lerp(a.colors, b.colors, t),
stroke: lerpDouble(a.stroke, b.stroke, t),
);
}
/// Gradient colors from start to end.
final MultiColor? colors;
/// Loader stroke width
final double? stroke;
@override
LoaderStyle mergeWith(LoaderStyle? other) => LoaderStyle.merge(this, other)!;
@override
String toString() => 'LoaderStyle($colors, $stroke)';
}

View File

@ -1,67 +0,0 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'loader_style.dart';
// **************************************************************************
// CopyWithGenerator
// **************************************************************************
abstract class _$LoaderStyleCWProxy {
LoaderStyle colors(MultiColor? colors);
LoaderStyle stroke(double? stroke);
/// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `LoaderStyle(...).copyWith.fieldName(...)` to override fields one at a time with nullification support.
///
/// Usage
/// ```dart
/// LoaderStyle(...).copyWith(id: 12, name: "My name")
/// ````
LoaderStyle call({
MultiColor? colors,
double? stroke,
});
}
/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfLoaderStyle.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfLoaderStyle.copyWith.fieldName(...)`
class _$LoaderStyleCWProxyImpl implements _$LoaderStyleCWProxy {
const _$LoaderStyleCWProxyImpl(this._value);
final LoaderStyle _value;
@override
LoaderStyle colors(MultiColor? colors) => this(colors: colors);
@override
LoaderStyle stroke(double? stroke) => this(stroke: stroke);
@override
/// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `LoaderStyle(...).copyWith.fieldName(...)` to override fields one at a time with nullification support.
///
/// Usage
/// ```dart
/// LoaderStyle(...).copyWith(id: 12, name: "My name")
/// ````
LoaderStyle call({
Object? colors = const $CopyWithPlaceholder(),
Object? stroke = const $CopyWithPlaceholder(),
}) {
return LoaderStyle(
colors: colors == const $CopyWithPlaceholder()
? _value.colors
// ignore: cast_nullable_to_non_nullable
: colors as MultiColor?,
stroke: stroke == const $CopyWithPlaceholder()
? _value.stroke
// ignore: cast_nullable_to_non_nullable
: stroke as double?,
);
}
}
extension $LoaderStyleCopyWith on LoaderStyle {
/// Returns a callable class that can be used as follows: `instanceOfLoaderStyle.copyWith(...)` or like so:`instanceOfLoaderStyle.copyWith.fieldName(...)`.
// ignore: library_private_types_in_public_api
_$LoaderStyleCWProxy get copyWith => _$LoaderStyleCWProxyImpl(this);
}

View File

@ -1,120 +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/widgets.dart';
class RichTextStyleParameter {
const RichTextStyleParameter(
this.defaultStyle,
this.definedStyle,
this.styleName,
);
final TextStyle defaultStyle;
final Map<String, TextStyle> definedStyle;
final String? styleName;
TextStyle get style {
if (definedStyle.containsKey(styleName)) {
return definedStyle[styleName]!;
}
return defaultStyle;
}
RichTextStyleParameter copyWith({
TextStyle? defaultStyle,
Map<String, TextStyle>? definedStyle,
String? styleName,
}) =>
RichTextStyleParameter(
defaultStyle ?? this.defaultStyle,
definedStyle ?? this.definedStyle,
styleName ?? this.styleName,
);
}
class RichTextNode {
RichTextNode(this.nodes);
final List<RichTextNode> nodes;
static RichTextNode from(
String content,
RegExp regex,
RichTextStyleParameter styleParameter,
) {
final matches = regex.allMatches(content);
if (matches.isNotEmpty) {
// match found -> construct node with leaf/nodes
final List<RichTextNode> nodes = [];
for (var i = 0; i < matches.length; i++) {
final previousMatch = i > 0 ? matches.elementAt(i - 1) : null;
final currentMatch = matches.elementAt(i);
// non match before
final nonMatchBefore = (previousMatch != null)
? content.substring(previousMatch.end, currentMatch.start)
: content.substring(0, currentMatch.start);
nodes
..add(RichTextNode.from(nonMatchBefore, regex, styleParameter))
// match
..add(
RichTextNode.from(
currentMatch.group(2)!,
regex,
styleParameter.copyWith(styleName: currentMatch.group(1)),
),
);
}
// non match after
final nonMatchAfter = content.substring(matches.last.end);
nodes.add(RichTextNode.from(nonMatchAfter, regex, styleParameter));
return RichTextNode(nodes);
} else {
// match not found -> construct leaf
return RichTextLeaf(styleParameter.style, content);
}
}
InlineSpan toInlineSpan(RichTextParser parser) {
final children = <InlineSpan>[];
for (final node in nodes) {
children.add(node.toInlineSpan(parser));
}
return TextSpan(children: children);
}
}
class RichTextLeaf extends RichTextNode {
RichTextLeaf(this.style, this.content) : super([]);
final TextStyle style;
final String content;
@override
InlineSpan toInlineSpan(RichTextParser parser) =>
parser.nodeBuilder.call(content, style);
}
class RichTextParser {
const RichTextParser({required this.nodeBuilder});
factory RichTextParser.defaultBuilder() => RichTextParser(
nodeBuilder: (content, style) => TextSpan(
text: content,
style: style,
),
);
final InlineSpan Function(String content, TextStyle style) nodeBuilder;
}

View File

@ -1,19 +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/>.
export 'parser.dart';
export 'rich_text_builder_component.dart';
export 'rich_text_builder_style.dart';

View File

@ -1,56 +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/widgets.dart';
import 'package:wyatt_component_copy_with_extension/component_copy_with_extension.dart';
import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart';
part 'rich_text_builder_component.g.dart';
@ComponentProxyExtension()
abstract class RichTextBuilderComponent extends Component
with CopyWithMixin<$RichTextBuilderComponentCWProxy> {
const RichTextBuilderComponent({
this.text,
this.parser,
this.defaultStyle,
this.styles,
super.themeResolver,
super.key,
});
/// Full text
final String? text;
/// How to build InlineSpans
final RichTextParser? parser;
/// Default TextStyle used in this rich text component.
final TextStyle? defaultStyle;
/// Used styles in this rich text component.
///
/// e.g.
/// ```dart
/// styles = {'red': TextStyle(color: Colors.red)};
/// ```
/// will transform:
/// ```text
/// This text <red>is red</red.
/// ```
/// in "This text `is red`."
final Map<String, TextStyle>? styles;
}

View File

@ -1,25 +0,0 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'rich_text_builder_component.dart';
// **************************************************************************
// ComponentProxyGenerator
// **************************************************************************
abstract class $RichTextBuilderComponentCWProxy {
RichTextBuilderComponent text(String? text);
RichTextBuilderComponent parser(RichTextParser? parser);
RichTextBuilderComponent defaultStyle(TextStyle? defaultStyle);
RichTextBuilderComponent styles(Map<String, TextStyle>? styles);
RichTextBuilderComponent themeResolver(
ThemeResolver<dynamic, dynamic, dynamic>? themeResolver);
RichTextBuilderComponent key(Key? key);
RichTextBuilderComponent call({
String? text,
RichTextParser? parser,
TextStyle? defaultStyle,
Map<String, TextStyle>? styles,
ThemeResolver<dynamic, dynamic, dynamic>? themeResolver,
Key? key,
});
}

View File

@ -1,72 +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:copy_with_extension/copy_with_extension.dart';
import 'package:flutter/widgets.dart';
import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart';
part 'rich_text_builder_style.g.dart';
@CopyWith()
class RichTextBuilderStyle extends ThemeStyle<RichTextBuilderStyle> {
const RichTextBuilderStyle({
this.defaultStyle,
this.styles,
});
/// Merges non-null `b` attributes in `a`
static RichTextBuilderStyle? merge(
RichTextBuilderStyle? a,
RichTextBuilderStyle? b,
) {
if (b == null) {
return a?.copyWith();
}
if (a == null) {
return b.copyWith();
}
return a.copyWith(
defaultStyle: b.defaultStyle,
styles: b.styles,
);
}
/// Used for interpolation.
static RichTextBuilderStyle? lerp(
RichTextBuilderStyle? a,
RichTextBuilderStyle? b,
double t,
) {
if (a == null || b == null) {
return null;
}
// b.copyWith to return b attributes even if they are not lerped
return b.copyWith(
defaultStyle: TextStyle.lerp(a.defaultStyle, b.defaultStyle, t),
styles: b.styles, // TODO(wyatt): compute lerp value of each 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
RichTextBuilderStyle mergeWith(RichTextBuilderStyle? other) =>
RichTextBuilderStyle.merge(this, other)!;
}

View File

@ -1,71 +0,0 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'rich_text_builder_style.dart';
// **************************************************************************
// CopyWithGenerator
// **************************************************************************
abstract class _$RichTextBuilderStyleCWProxy {
RichTextBuilderStyle defaultStyle(TextStyle? defaultStyle);
RichTextBuilderStyle styles(Map<String, TextStyle>? styles);
/// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `RichTextBuilderStyle(...).copyWith.fieldName(...)` to override fields one at a time with nullification support.
///
/// Usage
/// ```dart
/// RichTextBuilderStyle(...).copyWith(id: 12, name: "My name")
/// ````
RichTextBuilderStyle call({
TextStyle? defaultStyle,
Map<String, TextStyle>? styles,
});
}
/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfRichTextBuilderStyle.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfRichTextBuilderStyle.copyWith.fieldName(...)`
class _$RichTextBuilderStyleCWProxyImpl
implements _$RichTextBuilderStyleCWProxy {
const _$RichTextBuilderStyleCWProxyImpl(this._value);
final RichTextBuilderStyle _value;
@override
RichTextBuilderStyle defaultStyle(TextStyle? defaultStyle) =>
this(defaultStyle: defaultStyle);
@override
RichTextBuilderStyle styles(Map<String, TextStyle>? styles) =>
this(styles: styles);
@override
/// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `RichTextBuilderStyle(...).copyWith.fieldName(...)` to override fields one at a time with nullification support.
///
/// Usage
/// ```dart
/// RichTextBuilderStyle(...).copyWith(id: 12, name: "My name")
/// ````
RichTextBuilderStyle call({
Object? defaultStyle = const $CopyWithPlaceholder(),
Object? styles = const $CopyWithPlaceholder(),
}) {
return RichTextBuilderStyle(
defaultStyle: defaultStyle == const $CopyWithPlaceholder()
? _value.defaultStyle
// ignore: cast_nullable_to_non_nullable
: defaultStyle as TextStyle?,
styles: styles == const $CopyWithPlaceholder()
? _value.styles
// ignore: cast_nullable_to_non_nullable
: styles as Map<String, TextStyle>?,
);
}
}
extension $RichTextBuilderStyleCopyWith on RichTextBuilderStyle {
/// Returns a callable class that can be used as follows: `instanceOfRichTextBuilderStyle.copyWith(...)` or like so:`instanceOfRichTextBuilderStyle.copyWith.fieldName(...)`.
// ignore: library_private_types_in_public_api
_$RichTextBuilderStyleCWProxy get copyWith =>
_$RichTextBuilderStyleCWProxyImpl(this);
}

View File

@ -20,7 +20,7 @@ import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart';
part 'text_input_style.g.dart'; part 'text_input_style.g.dart';
@CopyWith() @CopyWith()
class TextInputStyle extends ThemeStyle<TextInputStyle> { class TextInputStyle {
TextInputStyle({ TextInputStyle({
this.labelStyle, this.labelStyle,
this.hintStyle, this.hintStyle,
@ -99,8 +99,4 @@ class TextInputStyle extends ThemeStyle<TextInputStyle> {
iconColor: Color.lerp(a.iconColor, b.iconColor, t), iconColor: Color.lerp(a.iconColor, b.iconColor, t),
); );
} }
@override
TextInputStyle? mergeWith(TextInputStyle? other) =>
TextInputStyle.merge(this, other);
} }

View File

@ -1,22 +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/>.
abstract class ThemeStyle<T> {
const ThemeStyle();
/// Merges non-null `other` attributes in `this` and returns a copy.
T? mergeWith(T? other);
}

View File

@ -9,8 +9,8 @@ environment:
sdk: ">=2.17.0 <3.0.0" sdk: ">=2.17.0 <3.0.0"
dependencies: dependencies:
flutter: { sdk: flutter }
copy_with_extension: ^5.0.0 copy_with_extension: ^5.0.0
flutter: { sdk: flutter }
wyatt_component_copy_with_extension: wyatt_component_copy_with_extension:
git: git:
url: ssh://git@git.wyatt-studio.fr:993/Wyatt-FOSS/wyatt-packages.git url: ssh://git@git.wyatt-studio.fr:993/Wyatt-FOSS/wyatt-packages.git

View File

@ -1,8 +0,0 @@
targets:
$default:
builders:
# Typically the builder key is just the package name, run `pub run build_runner doctor` to check your config.
wyatt_component_copy_with_gen:component_copy_with_gen:
generate_for:
# Example glob for only the Dart files under `lib/models`
- lib/**/*.dart

View File

@ -20,14 +20,10 @@ import 'package:wyatt_ui_kit_example/buttons/file_selection_button/file_selectio
import 'package:wyatt_ui_kit_example/buttons/flat_button/flat_buttons.dart'; import 'package:wyatt_ui_kit_example/buttons/flat_button/flat_buttons.dart';
import 'package:wyatt_ui_kit_example/buttons/simple_icon_button/simple_icon_buttons.dart'; import 'package:wyatt_ui_kit_example/buttons/simple_icon_button/simple_icon_buttons.dart';
import 'package:wyatt_ui_kit_example/buttons/symbol_button/symbol_buttons.dart'; import 'package:wyatt_ui_kit_example/buttons/symbol_button/symbol_buttons.dart';
import 'package:wyatt_ui_kit_example/demo_page.dart';
class Buttons extends DemoPage { class Buttons extends StatelessWidget {
const Buttons({super.key}); const Buttons({super.key});
@override
String get title => 'Buttons';
@override @override
Widget build(BuildContext context) => ListView( Widget build(BuildContext context) => ListView(
cacheExtent: 1000, cacheExtent: 1000,
@ -35,7 +31,7 @@ class Buttons extends DemoPage {
const Gap(20), const Gap(20),
Align( Align(
child: Text( child: Text(
title, 'Buttons',
style: Theme.of(context).textTheme.titleLarge, style: Theme.of(context).textTheme.titleLarge,
), ),
), ),

View File

@ -31,14 +31,8 @@ class FlatButtons extends StatelessWidget {
), ),
const Gap(20), const Gap(20),
Center( Center(
/// You can overwrite global textstyle of the label with [label],
/// but if you only want to override the color/gradient of the text
/// in a particular case you can override the style that will
/// be merge during the build.
child: FlatButton( child: FlatButton(
label: const TextWrapper( label: const TextWrapper('Voir notre savoir faire'),
'Voir notre savoir faire',
),
), ),
), ),
const Gap(20), const Gap(20),

View File

@ -4,14 +4,10 @@ import 'package:wyatt_ui_kit_example/cards/information_card/information_cards.da
import 'package:wyatt_ui_kit_example/cards/portfolio_card/portfolio_cards.dart'; import 'package:wyatt_ui_kit_example/cards/portfolio_card/portfolio_cards.dart';
import 'package:wyatt_ui_kit_example/cards/quote_card/quote_cards.dart'; import 'package:wyatt_ui_kit_example/cards/quote_card/quote_cards.dart';
import 'package:wyatt_ui_kit_example/cards/skill_card/skill_cards.dart'; import 'package:wyatt_ui_kit_example/cards/skill_card/skill_cards.dart';
import 'package:wyatt_ui_kit_example/demo_page.dart';
class Cards extends DemoPage { class Cards extends StatelessWidget {
const Cards({super.key}); const Cards({super.key});
@override
String get title => 'Cards';
@override @override
Widget build(BuildContext context) => ListView( Widget build(BuildContext context) => ListView(
cacheExtent: 1000, cacheExtent: 1000,
@ -19,7 +15,7 @@ class Cards extends DemoPage {
const Gap(20), const Gap(20),
Align( Align(
child: Text( child: Text(
title, 'Cards',
style: Theme.of(context).textTheme.titleLarge, style: Theme.of(context).textTheme.titleLarge,
), ),
), ),

View File

@ -18,13 +18,13 @@ class InformationCards extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
const InformationCard( InformationCard(
icons: [ icons: const [
FlutterLogo(size: 60), FlutterLogo(size: 60),
FlutterLogo(size: 60), FlutterLogo(size: 60),
FlutterLogo(size: 60), FlutterLogo(size: 60),
], ],
title: TextWrapper('Flutter'), title: const TextWrapper('Flutter'),
subtitle: TextWrapper.text('One single code base.'), subtitle: TextWrapper.text('One single code base.'),
body: TextWrapper.text( body: TextWrapper.text(
'Cupidatat reprehenderit aliqua eiusmod Lorem. ' 'Cupidatat reprehenderit aliqua eiusmod Lorem. '
@ -58,9 +58,9 @@ class InformationCards extends StatelessWidget {
FlutterLogo(size: 60), FlutterLogo(size: 60),
], ],
title: 'Flutter'.wrap( title: 'Flutter'.wrap(
gradientColors: const MultiColor([Colors.blue, Colors.green]), gradient: [Colors.blue, Colors.green],
), ),
subtitle: const TextWrapper.text('One single code base.'), subtitle: TextWrapper.text('One single code base.'),
body: 'Cupidatat reprehenderit aliqua eiusmod Lorem. ' body: 'Cupidatat reprehenderit aliqua eiusmod Lorem. '
'Qui ipsum id ea ea nulla labore aute ullamco aute ' 'Qui ipsum id ea ea nulla labore aute ullamco aute '
'quis elit ut amet velit. Incididunt fugiat proident ' 'quis elit ut amet velit. Incididunt fugiat proident '
@ -86,8 +86,8 @@ class InformationCards extends StatelessWidget {
FlutterLogo(size: 60), FlutterLogo(size: 60),
], ],
axis: Axis.horizontal, axis: Axis.horizontal,
title: const TextWrapper.text('Flutter'), title: TextWrapper.text('Flutter'),
subtitle: const TextWrapper.text('One single code base.'), subtitle: TextWrapper.text('One single code base.'),
body: 'Cupidatat reprehenderit aliqua eiusmod Lorem. ' body: 'Cupidatat reprehenderit aliqua eiusmod Lorem. '
'Qui ipsum id ea ea nulla labore aute ullamco aute ' 'Qui ipsum id ea ea nulla labore aute ullamco aute '
'quis elit ut amet velit. Incididunt fugiat proident ' 'quis elit ut amet velit. Incididunt fugiat proident '
@ -100,10 +100,10 @@ class InformationCards extends StatelessWidget {
'magna cupidatat Lorem nulla cupidatat voluptate ' 'magna cupidatat Lorem nulla cupidatat voluptate '
'irure ex reprehenderit.' 'irure ex reprehenderit.'
.wrap( .wrap(
gradientColors: const MultiColor([ gradient: [
Colors.red, Colors.red,
Colors.orange, Colors.orange,
]), ],
), ),
), ),
const Gap(20), const Gap(20),
@ -123,14 +123,14 @@ class InformationCards extends StatelessWidget {
FlutterLogo(size: 60), FlutterLogo(size: 60),
], ],
axis: Axis.horizontal, axis: Axis.horizontal,
title: const TextWrapper.text('Flutter'), title: TextWrapper.text('Flutter'),
subtitle: 'One single code base.'.wrap( subtitle: 'One single code base.'.wrap(
// gradient: [Colors.blue, Colors.green], // gradient: [Colors.blue, Colors.green],
style: const TextStyle( style: const TextStyle(
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
body: const TextWrapper.text( body: TextWrapper.text(
'Cupidatat reprehenderit aliqua eiusmod Lorem. ' 'Cupidatat reprehenderit aliqua eiusmod Lorem. '
'Qui ipsum id ea ea nulla labore aute ullamco aute ' 'Qui ipsum id ea ea nulla labore aute ullamco aute '
'quis elit ut amet velit. Incididunt fugiat proident ' 'quis elit ut amet velit. Incididunt fugiat proident '

View File

@ -128,10 +128,10 @@ class PortfolioCards extends StatelessWidget {
), ),
projectName: const TextWrapper( projectName: const TextWrapper(
'Flutter', 'Flutter',
gradientColors: MultiColor([ gradient: [
Colors.blue, Colors.blue,
Colors.green, Colors.green,
]), ],
), ),
subtitle: const TextWrapper('Mobile / Web / Macos.'), subtitle: const TextWrapper('Mobile / Web / Macos.'),
description: const TextWrapper( description: const TextWrapper(

View File

@ -49,12 +49,7 @@ class QuoteCards extends StatelessWidget {
'quis elit ut amet velit. Incididunt fugiat proident ' 'quis elit ut amet velit. Incididunt fugiat proident '
'proident deserunt tempor Lorem cillum qui do ' 'proident deserunt tempor Lorem cillum qui do '
'ullamco Lorem magna ipsum. Ullamco cupidatat velit ' 'ullamco Lorem magna ipsum. Ullamco cupidatat velit '
.wrap( .wrap(gradient: [Colors.red, Colors.orange]),
gradientColors: const MultiColor([
Colors.red,
Colors.orange,
]),
),
avatar: const FlutterLogo( avatar: const FlutterLogo(
size: 40, size: 40,
), ),

View File

@ -44,7 +44,7 @@ class SkillCards extends StatelessWidget {
'proident deserunt tempor Lorem cillum qui do ' 'proident deserunt tempor Lorem cillum qui do '
'ullamco Lorem magna ipsum. Ullamco cupidatat velit ' 'ullamco Lorem magna ipsum. Ullamco cupidatat velit '
.wrap(), .wrap(),
skills: const [ skills: [
TextWrapper.text('Firebase'), TextWrapper.text('Firebase'),
TextWrapper.text( TextWrapper.text(
'Qui ipsum id ea ea nulla labore aute ullamco aute ', 'Qui ipsum id ea ea nulla labore aute ullamco aute ',
@ -62,14 +62,11 @@ class SkillCards extends StatelessWidget {
'proident deserunt tempor Lorem cillum qui do ' 'proident deserunt tempor Lorem cillum qui do '
'ullamco Lorem magna ipsum. Ullamco cupidatat velit ' 'ullamco Lorem magna ipsum. Ullamco cupidatat velit '
.wrap(), .wrap(),
skills: const [ skills: [
TextWrapper.text('Firebase'), TextWrapper.text('Firebase'),
TextWrapper( const TextWrapper(
'Qui ipsum id ea ea nulla labore aute ullamco aute ', 'Qui ipsum id ea ea nulla labore aute ullamco aute ',
gradientColors: MultiColor([ gradient: [Colors.red, Colors.orange],
Colors.red,
Colors.orange,
]),
), ),
TextWrapper.text('Firebase'), TextWrapper.text('Firebase'),
TextWrapper.text('Firebase'), TextWrapper.text('Firebase'),

View File

@ -3,9 +3,6 @@ import 'package:flutter/material.dart';
import 'package:gap/gap.dart'; import 'package:gap/gap.dart';
import 'package:wyatt_ui_kit_example/buttons/buttons.dart'; import 'package:wyatt_ui_kit_example/buttons/buttons.dart';
import 'package:wyatt_ui_kit_example/cards/cards.dart'; import 'package:wyatt_ui_kit_example/cards/cards.dart';
import 'package:wyatt_ui_kit_example/demo_page.dart';
import 'package:wyatt_ui_kit_example/loaders/loaders.dart';
import 'package:wyatt_ui_kit_example/rich_text_builders/rich_text_builders.dart';
import 'package:wyatt_ui_kit_example/text_input/text_inputs.dart'; import 'package:wyatt_ui_kit_example/text_input/text_inputs.dart';
import 'package:wyatt_ui_kit_example/theme/themes.dart'; import 'package:wyatt_ui_kit_example/theme/themes.dart';
@ -21,13 +18,10 @@ class Home extends StatefulWidget {
} }
class _HomeState extends State<Home> { class _HomeState extends State<Home> {
// Simply add your demo page here. final List<Widget> pages = [
final List<DemoPage> pages = const [ const Cards(),
Cards(), const Buttons(),
Buttons(), const TextInputs()
Loaders(),
RichTextBuilders(),
TextInputs(),
]; ];
int currentIndex = 0; int currentIndex = 0;
@ -38,34 +32,46 @@ class _HomeState extends State<Home> {
super.initState(); super.initState();
} }
List<Widget> _drawerTiles(BuildContext context) {
final tiles = <Widget>[];
for (var i = 0; i < pages.length; i++) {
final page = pages[i];
tiles.add(
ListTile(
title: Text(page.title),
onTap: () {
if (currentIndex != i) {
setState(() {
currentIndex = i;
});
Navigator.pop(context);
}
},
),
);
}
return tiles;
}
@override @override
Widget build(BuildContext context) => Scaffold( Widget build(BuildContext context) => Scaffold(
drawer: Drawer( drawer: Drawer(
child: ListView( child: ListView(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
children: _drawerTiles(context), children: [
ListTile(
title: const Text('Cards'),
onTap: () {
if (currentIndex != 0) {
setState(() {
currentIndex = 0;
});
Navigator.pop(context);
}
},
),
ListTile(
title: const Text('Buttons'),
onTap: () {
if (currentIndex != 1) {
setState(() {
currentIndex = 1;
});
Navigator.pop(context);
}
},
),
ListTile(
title: const Text('Text inputs'),
onTap: () {
if (currentIndex != 2) {
setState(() {
currentIndex = 2;
});
Navigator.pop(context);
}
},
),
],
), ),
), ),
appBar: AppBar( appBar: AppBar(

View File

@ -1,68 +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:gap/gap.dart';
import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart';
import 'package:wyatt_ui_kit/wyatt_ui_kit.dart';
import 'package:wyatt_ui_kit_example/demo_page.dart';
import 'package:wyatt_ui_kit_example/theme/constants.dart';
class Loaders extends DemoPage {
const Loaders({super.key});
@override
String get title => 'Loaders';
@override
Widget build(BuildContext context) => ListView(
cacheExtent: 1000,
children: [
const Gap(20),
Align(
child: Text(
title,
style: Theme.of(context).textTheme.titleLarge,
),
),
const Gap(20),
const Loader(
radius: 57,
),
const Gap(20),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Loader(
stroke: 5,
),
Gap(20),
Loader(
colors: MultiColor([Constants.green2, Constants.white]),
stroke: 5,
),
Gap(20),
Loader(
colors: MultiColor([Constants.red2, Constants.white]),
stroke: 5,
),
],
),
const Gap(20),
],
);
}

View File

@ -1,63 +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:gap/gap.dart';
import 'package:wyatt_ui_kit/wyatt_ui_kit.dart';
import 'package:wyatt_ui_kit_example/demo_page.dart';
class RichTextBuilders extends DemoPage {
const RichTextBuilders({super.key});
@override
String get title => 'RichTextBuilders';
@override
Widget build(BuildContext context) => ListView(
cacheExtent: 1000,
children: [
const Gap(20),
Align(
child: Text(
title,
style: Theme.of(context).textTheme.titleLarge,
),
),
const Gap(20),
const Padding(
padding: EdgeInsets.all(8),
child: RichTextBuilder(
text: '''
Innovation, Expertise et Accompagnement...
Notre agence de développement Wyatt Studio met tout en oeuvre pour vous aider à <gradient-blue>concrétiser vos idées</gradient-blue> de solutions informatiques et mobiles.
Vous aussi, comme beaucoup dautres <gradient-blue>agences ou startups</gradient-blue>, faites nous confiance pour la réalisation de votre projet dès maintenant !
''',
),
),
const Gap(20),
const Padding(
padding: EdgeInsets.all(8),
child: RichTextBuilder(
text: '''
Je peux être <blue>bleu</blue>, ou même <gradient-red>rouge en dégradé</gradient-red>. À vrai dire <green>je peux</green> être <gradient-blue>un peu</gradient-blue> n'importe quelle couleur.
''',
),
),
const Gap(20),
],
);
}

View File

@ -2,26 +2,15 @@ import 'package:flutter/material.dart';
import 'package:gap/gap.dart'; import 'package:gap/gap.dart';
import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart';
import 'package:wyatt_ui_kit/wyatt_ui_kit.dart'; import 'package:wyatt_ui_kit/wyatt_ui_kit.dart';
import 'package:wyatt_ui_kit_example/demo_page.dart';
class TextInputs extends DemoPage { class TextInputs extends StatefulWidget {
const TextInputs({super.key}); const TextInputs({super.key});
@override @override
Widget build(BuildContext context) => const TextInputsCore(); State<TextInputs> createState() => _TextInputsState();
@override
String get title => 'Text Inputs';
} }
class TextInputsCore extends StatefulWidget { class _TextInputsState extends State<TextInputs> {
const TextInputsCore({super.key});
@override
State<TextInputsCore> createState() => _TextInputsCoreState();
}
class _TextInputsCoreState extends State<TextInputsCore> {
final _formKey = GlobalKey<FormState>(); final _formKey = GlobalKey<FormState>();
final _controller = TextEditingController(); final _controller = TextEditingController();
final _focusNode = FocusNode(); final _focusNode = FocusNode();

View File

@ -1,127 +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:google_fonts/google_fonts.dart';
import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart';
import 'package:wyatt_ui_kit/wyatt_ui_kit.dart';
class CardTheme extends CardThemeExtension {
const CardTheme({
super.backgroundColors,
super.body,
super.borderColors,
super.secondaryBackgroundColor,
super.shadowColor,
super.subtitle,
super.title,
});
factory CardTheme.light() => CardTheme(
backgroundColors: const MultiColor.single(Color(0xFFF6F6F6)),
secondaryBackgroundColor: Colors.white,
borderColors: const MultiColor([
Color(0xFFDDE0E3),
Color(0xFFCACCD4),
]),
title: GoogleFonts.montserrat(
fontSize: 24,
fontWeight: FontWeight.w500,
color: const Color(0xFF24262A),
),
subtitle: GoogleFonts.montserrat(
fontSize: 15,
fontWeight: FontWeight.w300,
color: const Color(0xFF24262A),
),
body: GoogleFonts.montserrat(
fontSize: 12,
fontWeight: FontWeight.w300,
height: 1.7,
color: const Color(0xFF24262A),
),
);
factory CardTheme.dark() => CardTheme(
backgroundColors:
MultiColor.single(const Color(0xFFFFFFFF).withOpacity(0.04)),
secondaryBackgroundColor: const Color(0xFFFFFFFF).withOpacity(0.04),
borderColors: const MultiColor([
Color(0xFF60656A),
Color(0xFF383C40),
]),
title: GoogleFonts.montserrat(
fontSize: 24,
fontWeight: FontWeight.w500,
color: const Color(0xFFFFFFFF),
),
subtitle: GoogleFonts.montserrat(
fontSize: 15,
fontWeight: FontWeight.w300,
color: const Color(0xFFFFFFFF),
),
body: GoogleFonts.montserrat(
fontSize: 12,
fontWeight: FontWeight.w300,
height: 1.7,
color: const Color(0xFFFFFFFF),
),
);
@override
ThemeExtension<CardThemeExtension> copyWith({
MultiColor? backgroundColors,
Color? secondaryBackgroundColor,
MultiColor? borderColors,
BoxShadow? shadowColor,
TextStyle? body,
TextStyle? title,
TextStyle? subtitle,
}) =>
CardTheme(
backgroundColors: backgroundColors ?? this.backgroundColors,
secondaryBackgroundColor:
secondaryBackgroundColor ?? this.secondaryBackgroundColor,
borderColors: borderColors ?? this.borderColors,
shadowColor: shadowColor ?? this.shadowColor,
body: body ?? this.body,
title: title ?? this.title,
subtitle: subtitle ?? this.subtitle,
);
@override
ThemeExtension<CardThemeExtension> lerp(
covariant ThemeExtension<CardThemeExtension>? other,
double t,
) {
if (other is! CardTheme) {
return this;
}
return CardTheme(
backgroundColors: other.backgroundColors,
secondaryBackgroundColor: Color.lerp(
secondaryBackgroundColor,
other.secondaryBackgroundColor,
t,
),
borderColors: other.borderColors,
shadowColor: BoxShadow.lerp(shadowColor, other.shadowColor, t),
body: TextStyle.lerp(body, other.body, t),
title: TextStyle.lerp(title, other.title, t),
subtitle: TextStyle.lerp(subtitle, other.subtitle, t),
);
}
}

View File

@ -1,63 +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 'dart:ui';
import 'package:flutter/material.dart';
import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart';
import 'package:wyatt_ui_kit/wyatt_ui_kit.dart';
import 'package:wyatt_ui_kit_example/theme/constants.dart';
class LoaderTheme extends LoaderThemeExtension {
const LoaderTheme({
super.colors,
super.stroke,
});
factory LoaderTheme.light() => const LoaderTheme(
colors: MultiColor([Constants.blue1, Constants.white]),
stroke: 15,
);
factory LoaderTheme.dark() => const LoaderTheme(
colors: MultiColor([Constants.blue2, Constants.grey2]),
stroke: 15,
);
@override
ThemeExtension<LoaderThemeExtension> copyWith({
MultiColor? colors,
double? stroke,
}) =>
LoaderTheme(
colors: colors ?? this.colors,
stroke: stroke ?? this.stroke,
);
@override
ThemeExtension<LoaderThemeExtension> lerp(
covariant ThemeExtension<LoaderThemeExtension>? other,
double t,
) {
if (other is! LoaderTheme) {
return this;
}
return LoaderTheme(
colors: MultiColor.lerp(colors, other.colors, t),
stroke: lerpDouble(stroke, other.stroke, t),
);
}
}

View File

@ -1,120 +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:google_fonts/google_fonts.dart';
import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart';
import 'package:wyatt_ui_kit/wyatt_ui_kit.dart';
import 'package:wyatt_ui_kit_example/theme/constants.dart';
final Map<String, TextStyle> _styles = {
'gradient-blue': GradientTextStyle.from(
GoogleFonts.montserrat(
fontSize: 20,
fontWeight: FontWeight.w600,
color: Constants.blue1,
height: 1.8,
),
const MultiColor(Constants.blueGradient),
),
'gradient-red': GradientTextStyle.from(
GoogleFonts.montserrat(
fontSize: 20,
fontWeight: FontWeight.w600,
color: Constants.red1,
height: 1.8,
),
const MultiColor(Constants.redGradient),
),
'gradient-green': GradientTextStyle.from(
GoogleFonts.montserrat(
fontSize: 20,
fontWeight: FontWeight.w600,
color: Constants.green1,
height: 1.8,
),
const MultiColor(Constants.greenGradient),
),
'blue': GoogleFonts.montserrat(
fontSize: 20,
fontWeight: FontWeight.w600,
color: Constants.blue1,
height: 1.8,
),
'red': GoogleFonts.montserrat(
fontSize: 20,
fontWeight: FontWeight.w600,
color: Constants.red1,
height: 1.8,
),
'green': GoogleFonts.montserrat(
fontSize: 20,
fontWeight: FontWeight.w600,
color: Constants.green1,
height: 1.8,
),
};
class RichTextBuilderTheme extends RichTextBuilderThemeExtension {
const RichTextBuilderTheme({
super.defaultStyle,
super.styles,
});
factory RichTextBuilderTheme.light() => RichTextBuilderTheme(
defaultStyle: GoogleFonts.montserrat(
fontSize: 18,
fontWeight: FontWeight.w500,
color: Constants.grey3,
height: 1.8,
),
styles: _styles,
);
factory RichTextBuilderTheme.dark() => RichTextBuilderTheme(
defaultStyle: GoogleFonts.montserrat(
fontSize: 18,
fontWeight: FontWeight.w500,
color: Constants.white,
height: 1.8,
),
styles: _styles,
);
@override
ThemeExtension<RichTextBuilderThemeExtension> copyWith({
TextStyle? defaultStyle,
Map<String, TextStyle>? styles,
}) =>
RichTextBuilderTheme(
defaultStyle: defaultStyle ?? this.defaultStyle,
styles: styles ?? this.styles,
);
@override
ThemeExtension<RichTextBuilderThemeExtension> lerp(
covariant ThemeExtension<RichTextBuilderThemeExtension>? other,
double t,
) {
if (other is! RichTextBuilderTheme) {
return this;
}
return RichTextBuilderTheme(
defaultStyle: TextStyle.lerp(defaultStyle, other.defaultStyle, t),
styles: styles,
);
}
}

View File

@ -15,16 +15,14 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
import 'package:adaptive_theme/adaptive_theme.dart'; import 'package:adaptive_theme/adaptive_theme.dart';
import 'package:flutter/material.dart' hide CardTheme; import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import 'package:wyatt_ui_kit_example/theme/card_theme.dart';
import 'package:wyatt_ui_kit_example/theme/file_selection_button_theme.dart'; import 'package:wyatt_ui_kit_example/theme/file_selection_button_theme.dart';
import 'package:wyatt_ui_kit_example/theme/flat_button_theme.dart'; import 'package:wyatt_ui_kit_example/theme/flat_button_theme.dart';
import 'package:wyatt_ui_kit_example/theme/loader_theme.dart';
import 'package:wyatt_ui_kit_example/theme/rich_text_builder_theme.dart';
import 'package:wyatt_ui_kit_example/theme/simple_icon_button_theme.dart'; import 'package:wyatt_ui_kit_example/theme/simple_icon_button_theme.dart';
import 'package:wyatt_ui_kit_example/theme/symbol_button_theme.dart'; import 'package:wyatt_ui_kit_example/theme/symbol_button_theme.dart';
import 'package:wyatt_ui_kit_example/theme/text_input_theme.dart'; import 'package:wyatt_ui_kit_example/theme/text_input_theme.dart';
import 'package:wyatt_ui_kit_example/theme_extension.dart';
/// Easely switch between Material and Studio themes. /// Easely switch between Material and Studio themes.
abstract class Themes { abstract class Themes {
@ -70,27 +68,46 @@ abstract class Themes {
static ThemeData get studioLight => materialLight.copyWith( static ThemeData get studioLight => materialLight.copyWith(
appBarTheme: AppBarTheme( appBarTheme: AppBarTheme(
foregroundColor: const Color(0xFF24262A), foregroundColor: const Color.fromRGBO(36, 38, 42, 1),
backgroundColor: const Color(0xFFFFFFFF), backgroundColor: Colors.white,
titleTextStyle: GoogleFonts.montserrat( titleTextStyle: GoogleFonts.montserrat(
fontSize: 18, fontSize: 18,
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
color: const Color(0xFF24262A), color: const Color.fromRGBO(36, 38, 42, 1),
), ),
), ),
scaffoldBackgroundColor: Colors.white, scaffoldBackgroundColor: Colors.white,
extensions: <ThemeExtension<dynamic>>[ extensions: <ThemeExtension<dynamic>>[
// Cards CustomCardColorExtension(
CardTheme.light(), backgroundColors: const [
// Buttons Color.fromRGBO(246, 246, 246, 1),
],
secondaryBackgroundColors: Colors.white,
borderColor: const [
Color.fromRGBO(221, 224, 227, 1),
Color.fromRGBO(202, 204, 212, 1),
],
title: GoogleFonts.montserrat(
fontSize: 24,
fontWeight: FontWeight.w500,
color: const Color.fromRGBO(36, 38, 42, 1),
),
subtitle: GoogleFonts.montserrat(
fontSize: 15,
fontWeight: FontWeight.w300,
color: const Color.fromRGBO(36, 38, 42, 1),
),
body: GoogleFonts.montserrat(
fontSize: 12,
fontWeight: FontWeight.w300,
height: 1.7,
color: const Color.fromRGBO(36, 38, 42, 1),
),
),
FlatButtonTheme.light(), FlatButtonTheme.light(),
SymbolButtonTheme.light(), SymbolButtonTheme.light(),
SimpleIconButtonTheme.light(), SimpleIconButtonTheme.light(),
FileSelectionButtonTheme.light(), FileSelectionButtonTheme.light(),
// Loader
LoaderTheme.light(),
// Rich Text
RichTextBuilderTheme.light(),
TextInputTheme.light(), TextInputTheme.light(),
], ],
); );
@ -99,30 +116,46 @@ abstract class Themes {
static ThemeData get studioDark => materialDark.copyWith( static ThemeData get studioDark => materialDark.copyWith(
appBarTheme: AppBarTheme( appBarTheme: AppBarTheme(
foregroundColor: const Color(0xFFFFFFFF), foregroundColor: Colors.white,
backgroundColor: const Color(0xFF383C40), backgroundColor: const Color.fromRGBO(56, 60, 64, 1),
titleTextStyle: GoogleFonts.montserrat( titleTextStyle: GoogleFonts.montserrat(
fontSize: 18, fontSize: 18,
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
color: const Color(0xFFFFFFFF), color: Colors.white,
), ),
), ),
drawerTheme: const DrawerThemeData( scaffoldBackgroundColor: const Color.fromRGBO(56, 60, 64, 1),
backgroundColor: Color(0xFF383C40),
),
scaffoldBackgroundColor: const Color(0xFF383C40),
extensions: <ThemeExtension<dynamic>>[ extensions: <ThemeExtension<dynamic>>[
// Cards CustomCardColorExtension(
CardTheme.dark(), secondaryBackgroundColors: Colors.white.withOpacity(0.04),
// Buttons backgroundColors: [
Colors.white.withOpacity(0.04),
],
borderColor: const [
Color.fromRGBO(96, 101, 106, 1),
Color.fromRGBO(56, 60, 64, 1),
],
title: GoogleFonts.montserrat(
fontSize: 24,
fontWeight: FontWeight.w500,
color: Colors.white,
),
subtitle: GoogleFonts.montserrat(
fontSize: 15,
fontWeight: FontWeight.w300,
color: Colors.white,
),
body: GoogleFonts.montserrat(
fontSize: 12,
fontWeight: FontWeight.w300,
height: 1.7,
color: Colors.white,
),
),
FlatButtonTheme.dark(), FlatButtonTheme.dark(),
SymbolButtonTheme.dark(), SymbolButtonTheme.dark(),
SimpleIconButtonTheme.dark(), SimpleIconButtonTheme.dark(),
FileSelectionButtonTheme.dark(), FileSelectionButtonTheme.dark(),
// Loader
LoaderTheme.dark(),
// Rich Text
RichTextBuilderTheme.dark(),
TextInputTheme.dark(), TextInputTheme.dark(),
], ],
); );

View File

@ -0,0 +1,54 @@
import 'package:flutter/material.dart';
import 'package:wyatt_ui_kit/wyatt_ui_kit.dart' as ui_kit;
class CustomCardColorExtension extends ui_kit.CardThemeExtension {
const CustomCardColorExtension({
super.backgroundColors,
super.secondaryBackgroundColors,
super.borderColor,
super.shadowColor,
super.body,
super.title,
super.subtitle,
});
@override
CustomCardColorExtension copyWith({
List<Color>? backgroundColors,
Color? secondaryBackgroundColors,
List<Color>? borderColor,
BoxShadow? shadowColor,
TextStyle? body,
TextStyle? title,
TextStyle? subtitle,
}) =>
CustomCardColorExtension(
backgroundColors: backgroundColors ?? this.backgroundColors,
secondaryBackgroundColors:
secondaryBackgroundColors ?? this.secondaryBackgroundColors,
borderColor: borderColor ?? this.borderColor,
body: body ?? this.body,
title: title ?? this.title,
subtitle: subtitle ?? this.subtitle,
);
@override
ThemeExtension<ui_kit.CardThemeExtension> lerp(
covariant ThemeExtension<ui_kit.CardThemeExtension>? other,
double t,
) {
if (other is! CustomCardColorExtension) {
return this;
}
return CustomCardColorExtension(
secondaryBackgroundColors: Color.lerp(
secondaryBackgroundColors,
other.secondaryBackgroundColors,
t,
),
body: TextStyle.lerp(body, other.body, t),
title: TextStyle.lerp(title, other.title, t),
subtitle: TextStyle.lerp(subtitle, other.subtitle, t),
);
}
}

View File

@ -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,
);
}

View File

@ -1,49 +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:dotted_border/dotted_border.dart';
import 'package:flutter/material.dart';
import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart';
class DotterBorderChild extends StatelessWidget {
const DotterBorderChild({
required this.style,
required this.child,
super.key,
});
final FileSelectionButtonStyle style;
final Widget child;
@override
Widget build(BuildContext context) {
if (style.borderColors != null && style.stroke != null) {
return DottedBorder(
padding: EdgeInsets.zero,
dashPattern: const [5, 5],
strokeWidth: style.stroke!,
color: style.borderColors!.color,
borderType: BorderType.RRect,
radius:
style.radius?.resolve(TextDirection.ltr).bottomLeft ?? Radius.zero,
strokeCap: StrokeCap.square,
child: child,
);
} else {
return child;
}
}
}

View File

@ -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_component_copy_with_extension/component_copy_with_extension.dart';
import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.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/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_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/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'; part 'file_selection_button.g.dart';
@ComponentCopyWithExtension() @ComponentCopyWithExtension()
class FileSelectionButton extends FileSelectionButtonComponent class FileSelectionButton extends FileSelectionButtonComponent
with $FileSelectionButtonCWMixin { with $FileSelectionButtonCWMixin, ExportBloc<InvalidButtonCubit> {
FileSelectionButton({ FileSelectionButton({
super.leading, super.leading,
super.title, super.title,
@ -46,6 +46,7 @@ class FileSelectionButton extends FileSelectionButtonComponent
final InvalidButtonCubit _cubit = InvalidButtonCubit(); final InvalidButtonCubit _cubit = InvalidButtonCubit();
@override
InvalidButtonCubit get bloc => _cubit; InvalidButtonCubit get bloc => _cubit;
@override @override
@ -81,8 +82,7 @@ class FileSelectionButton extends FileSelectionButtonComponent
super.themeResolver as FileSelectionButtonThemeResolver?; super.themeResolver as FileSelectionButtonThemeResolver?;
@override @override
Widget build(BuildContext context) => ExportableBloc( Widget build(BuildContext context) => exportBloc(
bloc: _cubit,
child: FileSelectionButtonScreen( child: FileSelectionButtonScreen(
leading: leading, leading: leading,
title: title, title: title,

View File

@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
import 'package:dotted_border/dotted_border.dart';
import 'package:flutter/material.dart' hide ButtonStyle; import 'package:flutter/material.dart' hide ButtonStyle;
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:gap/gap.dart'; import 'package:gap/gap.dart';
@ -21,9 +22,9 @@ import 'package:wyatt_bloc_helper/wyatt_bloc_helper.dart';
import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.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/cubit/button_cubit.dart';
import 'package:wyatt_ui_kit/src/components/buttons/cubit/invalid_button_cubit.dart'; import 'package:wyatt_ui_kit/src/components/buttons/cubit/invalid_button_cubit.dart';
import 'package:wyatt_ui_kit/src/components/buttons/file_selection_button/dotter_border_child.dart';
import 'package:wyatt_ui_kit/src/components/buttons/file_selection_button/file_selection_button_theme_resolver.dart'; import 'package:wyatt_ui_kit/src/components/buttons/file_selection_button/file_selection_button_theme_resolver.dart';
import 'package:wyatt_ui_kit/src/components/gradients/gradient_text.dart'; import 'package:wyatt_ui_kit/src/components/gradients/gradient_text.dart';
import 'package:wyatt_ui_kit/src/core/helpers/linear_gradient_helper.dart';
class FileSelectionButtonScreen class FileSelectionButtonScreen
extends CubitScreen<InvalidButtonCubit, ButtonState> { extends CubitScreen<InvalidButtonCubit, ButtonState> {
@ -64,10 +65,10 @@ class FileSelectionButtonScreen
InvalidButtonCubit create(BuildContext context) => InvalidButtonCubit(); InvalidButtonCubit create(BuildContext context) => InvalidButtonCubit();
/// Negotiate the theme to get a complete style. /// Negotiate the theme to get a complete style.
FileSelectionButtonStyle _resolve(BuildContext context, ButtonState state) { FileSelectionButtonStyle resolve(BuildContext context, ButtonState state) {
final FileSelectionButtonThemeResolver resolver = themeResolver ?? final FileSelectionButtonThemeResolver resolver = themeResolver ??
FileSelectionButtonThemeResolver( FileSelectionButtonThemeResolver(
customStyleFn: (context, {extra}) { customStyleFn: (context, extensionValue, {extra}) {
FileSelectionButtonStyle? style; FileSelectionButtonStyle? style;
switch (extra?.state) { switch (extra?.state) {
case ControlState.disabled: case ControlState.disabled:
@ -100,9 +101,31 @@ class FileSelectionButtonScreen
return resolver.negotiate(context, extra: state); return resolver.negotiate(context, extra: state);
} }
Widget _border(
BuildContext context,
FileSelectionButtonStyle style,
Widget child,
) {
if (style.borderColors != null && style.stroke != null) {
return DottedBorder(
padding: EdgeInsets.zero,
dashPattern: const [5, 5],
strokeWidth: style.stroke!,
color: style.borderColors!.color,
borderType: BorderType.RRect,
radius:
style.radius?.resolve(TextDirection.ltr).bottomLeft ?? Radius.zero,
strokeCap: StrokeCap.square,
child: child,
);
} else {
return child;
}
}
@override @override
Widget onBuild(BuildContext context, ButtonState state) { Widget onBuild(BuildContext context, ButtonState state) {
final style = _resolve(context, state); final style = resolve(context, state);
return Focus( return Focus(
onFocusChange: (hasFocus) => onFocusChange: (hasFocus) =>
@ -135,9 +158,10 @@ class FileSelectionButtonScreen
onPressed?.call(state.state); onPressed?.call(state.state);
bloc(context).onClickUpOut(); bloc(context).onClickUpOut();
}, },
child: DotterBorderChild( child: _border(
style: style, context,
child: DecoratedBox( style,
DecoratedBox(
decoration: BoxDecoration( decoration: BoxDecoration(
color: style.backgroundColors?.color, color: style.backgroundColors?.color,
// if no gradient colors => no default value // if no gradient colors => no default value
@ -179,13 +203,19 @@ class FileSelectionButtonScreen
/// buttonStyle.foregroundColor.colors ?? /// buttonStyle.foregroundColor.colors ??
/// null /// null
/// ///
/// More infos in `ThemeResolver` class /// More infos in `negociate()` method
if (title != null) ...[ if (title != null) ...[
Text( Text(
title!.text, title!.text,
style: title!.style ?? style.title, style: title!.style ?? style.title,
).toGradient( ).toGradient(
gradientColors: style.foregroundColors, LinearGradientHelper.fromNullableColors(
title?.gradient ??
((style.foregroundColors?.isGradient ??
false)
? style.foregroundColors?.colors
: null),
),
), ),
], ],
@ -199,14 +229,20 @@ class FileSelectionButtonScreen
/// buttonStyle.foregroundColor.colors ?? /// buttonStyle.foregroundColor.colors ??
/// null /// null
/// ///
/// More infos in `ThemeResolver` class /// More infos in `negociate()` method
if (subTitle != null) ...[ if (subTitle != null) ...[
const Gap(5), const Gap(5),
Text( Text(
subTitle!.text, subTitle!.text,
style: subTitle!.style ?? style.subTitle, style: subTitle!.style ?? style.subTitle,
).toGradient( ).toGradient(
gradientColors: style.foregroundColors, LinearGradientHelper.fromNullableColors(
subTitle?.gradient ??
((style.foregroundColors?.isGradient ??
false)
? style.foregroundColors?.colors
: null),
),
), ),
], ],
], ],

View File

@ -73,17 +73,19 @@ class FileSelectionButtonThemeResolver extends ThemeResolver<
@override @override
final FileSelectionButtonStyle? Function( final FileSelectionButtonStyle? Function(
BuildContext context, { BuildContext context,
FileSelectionButtonStyle? extensionValue, {
ButtonState? extra, ButtonState? extra,
}) customStyleFn; }) customStyleFn;
@override @override
FileSelectionButtonStyle? computeExtensionValueFn( FileSelectionButtonStyle? computeExtensionValueFn(
BuildContext context, BuildContext context,
FileSelectionButtonStyle defaultValue,
FileSelectionButtonThemeExtension themeExtension, { FileSelectionButtonThemeExtension themeExtension, {
ButtonState? extra, ButtonState? extra,
}) { }) {
FileSelectionButtonStyle? style; FileSelectionButtonStyle? style = defaultValue;
switch (extra?.state) { switch (extra?.state) {
case ControlState.disabled: case ControlState.disabled:
style = themeExtension.disabledStyle; style = themeExtension.disabledStyle;

View File

@ -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_component_copy_with_extension/component_copy_with_extension.dart';
import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.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/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_screen.dart';
import 'package:wyatt_ui_kit/src/components/buttons/flat_button/flat_button_theme_resolver.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'; part 'flat_button.g.dart';
@ComponentCopyWithExtension() @ComponentCopyWithExtension()
class FlatButton extends FlatButtonComponent with $FlatButtonCWMixin { class FlatButton extends FlatButtonComponent
with $FlatButtonCWMixin, ExportBloc<ButtonCubit> {
FlatButton({ FlatButton({
super.prefix, super.prefix,
super.suffix, super.suffix,
@ -43,6 +44,7 @@ class FlatButton extends FlatButtonComponent with $FlatButtonCWMixin {
final ButtonCubit _cubit = ButtonCubit(); final ButtonCubit _cubit = ButtonCubit();
@override
ButtonCubit get bloc => _cubit; ButtonCubit get bloc => _cubit;
@override @override
@ -65,8 +67,7 @@ class FlatButton extends FlatButtonComponent with $FlatButtonCWMixin {
super.themeResolver as FlatButtonThemeResolver?; super.themeResolver as FlatButtonThemeResolver?;
@override @override
Widget build(BuildContext context) => ExportableBloc( Widget build(BuildContext context) => exportBloc(
bloc: _cubit,
child: FlatButtonScreen( child: FlatButtonScreen(
prefix: prefix, prefix: prefix,
suffix: suffix, suffix: suffix,

View File

@ -23,6 +23,7 @@ import 'package:wyatt_ui_kit/src/components/buttons/cubit/button_cubit.dart';
import 'package:wyatt_ui_kit/src/components/buttons/flat_button/flat_button_theme_resolver.dart'; import 'package:wyatt_ui_kit/src/components/buttons/flat_button/flat_button_theme_resolver.dart';
import 'package:wyatt_ui_kit/src/components/gradients/gradient_box_border.dart'; import 'package:wyatt_ui_kit/src/components/gradients/gradient_box_border.dart';
import 'package:wyatt_ui_kit/src/components/gradients/gradient_text.dart'; import 'package:wyatt_ui_kit/src/components/gradients/gradient_text.dart';
import 'package:wyatt_ui_kit/src/core/helpers/linear_gradient_helper.dart';
class FlatButtonScreen extends CubitScreen<ButtonCubit, ButtonState> { class FlatButtonScreen extends CubitScreen<ButtonCubit, ButtonState> {
const FlatButtonScreen({ const FlatButtonScreen({
@ -58,10 +59,10 @@ class FlatButtonScreen extends CubitScreen<ButtonCubit, ButtonState> {
ButtonCubit create(BuildContext context) => ButtonCubit(); ButtonCubit create(BuildContext context) => ButtonCubit();
/// Negotiate the theme to get a complete style. /// Negotiate the theme to get a complete style.
FlatButtonStyle _resolve(BuildContext context, ControlState state) { FlatButtonStyle resolve(BuildContext context, ControlState state) {
final FlatButtonThemeResolver resolver = themeResolver ?? final FlatButtonThemeResolver resolver = themeResolver ??
FlatButtonThemeResolver( FlatButtonThemeResolver(
customStyleFn: (context, {extra}) { customStyleFn: (context, extensionValue, {extra}) {
switch (extra) { switch (extra) {
case ControlState.disabled: case ControlState.disabled:
return disabledStyle; return disabledStyle;
@ -82,7 +83,7 @@ class FlatButtonScreen extends CubitScreen<ButtonCubit, ButtonState> {
@override @override
Widget onBuild(BuildContext context, ButtonState state) { Widget onBuild(BuildContext context, ButtonState state) {
final style = _resolve(context, state.state); final style = resolve(context, state.state);
return Focus( return Focus(
onFocusChange: (hasFocus) => onFocusChange: (hasFocus) =>
@ -183,7 +184,12 @@ class FlatButtonScreen extends CubitScreen<ButtonCubit, ButtonState> {
label!.text, label!.text,
style: label!.style ?? style.label, style: label!.style ?? style.label,
).toGradient( ).toGradient(
gradientColors: style.foregroundColors, LinearGradientHelper.fromNullableColors(
label?.gradient ??
((style.foregroundColors?.isGradient ?? false)
? style.foregroundColors?.colors
: null),
),
) )
], ],
Gap(style.padding?.vertical ?? 10), Gap(style.padding?.vertical ?? 10),

View File

@ -69,13 +69,15 @@ class FlatButtonThemeResolver extends ThemeResolver<FlatButtonStyle,
@override @override
final FlatButtonStyle? Function( final FlatButtonStyle? Function(
BuildContext context, { BuildContext context,
FlatButtonStyle? extensionValue, {
ControlState? extra, ControlState? extra,
}) customStyleFn; }) customStyleFn;
@override @override
FlatButtonStyle? computeExtensionValueFn( FlatButtonStyle? computeExtensionValueFn(
BuildContext context, BuildContext context,
FlatButtonStyle defaultValue,
FlatButtonThemeExtension themeExtension, { FlatButtonThemeExtension themeExtension, {
ControlState? extra, ControlState? extra,
}) { }) {

View File

@ -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_component_copy_with_extension/component_copy_with_extension.dart';
import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.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/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_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/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'; part 'simple_icon_button.g.dart';
@ComponentCopyWithExtension() @ComponentCopyWithExtension()
class SimpleIconButton extends SimpleIconButtonComponent class SimpleIconButton extends SimpleIconButtonComponent
with $SimpleIconButtonCWMixin { with $SimpleIconButtonCWMixin, ExportBloc<ButtonCubit> {
SimpleIconButton({ SimpleIconButton({
super.icon, super.icon,
super.disabledStyle, super.disabledStyle,
@ -41,6 +41,7 @@ class SimpleIconButton extends SimpleIconButtonComponent
final ButtonCubit _cubit = ButtonCubit(); final ButtonCubit _cubit = ButtonCubit();
@override
ButtonCubit get bloc => _cubit; ButtonCubit get bloc => _cubit;
@override @override
@ -68,8 +69,7 @@ class SimpleIconButton extends SimpleIconButtonComponent
super.themeResolver as SimpleIconButtonThemeResolver?; super.themeResolver as SimpleIconButtonThemeResolver?;
@override @override
Widget build(BuildContext context) => ExportableBloc( Widget build(BuildContext context) => exportBloc(
bloc: _cubit,
child: SimpleIconButtonScreen( child: SimpleIconButtonScreen(
icon: icon, icon: icon,
disabledStyle: disabledStyle, disabledStyle: disabledStyle,

View File

@ -67,13 +67,15 @@ class SimpleIconButtonThemeResolver extends ThemeResolver<SimpleIconButtonStyle,
@override @override
final SimpleIconButtonStyle? Function( final SimpleIconButtonStyle? Function(
BuildContext context, { BuildContext context,
SimpleIconButtonStyle? extensionValue, {
ControlState? extra, ControlState? extra,
}) customStyleFn; }) customStyleFn;
@override @override
SimpleIconButtonStyle? computeExtensionValueFn( SimpleIconButtonStyle? computeExtensionValueFn(
BuildContext context, BuildContext context,
SimpleIconButtonStyle defaultValue,
SimpleIconButtonThemeExtension themeExtension, { SimpleIconButtonThemeExtension themeExtension, {
ControlState? extra, ControlState? extra,
}) { }) {

View File

@ -52,10 +52,10 @@ class SimpleIconButtonScreen extends CubitScreen<ButtonCubit, ButtonState> {
ButtonCubit create(BuildContext context) => ButtonCubit(); ButtonCubit create(BuildContext context) => ButtonCubit();
/// Negotiate the theme to get a complete style. /// Negotiate the theme to get a complete style.
SimpleIconButtonStyle _resolve(BuildContext context, ControlState state) { SimpleIconButtonStyle resolve(BuildContext context, ControlState state) {
final SimpleIconButtonThemeResolver resolver = themeResolver ?? final SimpleIconButtonThemeResolver resolver = themeResolver ??
SimpleIconButtonThemeResolver( SimpleIconButtonThemeResolver(
customStyleFn: (context, {extra}) { customStyleFn: (context, extensionValue, {extra}) {
switch (extra) { switch (extra) {
case ControlState.disabled: case ControlState.disabled:
return disabledStyle; return disabledStyle;
@ -76,7 +76,7 @@ class SimpleIconButtonScreen extends CubitScreen<ButtonCubit, ButtonState> {
@override @override
Widget onBuild(BuildContext context, ButtonState state) { Widget onBuild(BuildContext context, ButtonState state) {
final style = _resolve(context, state.state); final style = resolve(context, state.state);
return Focus( return Focus(
onFocusChange: (hasFocus) => onFocusChange: (hasFocus) =>

View File

@ -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_component_copy_with_extension/component_copy_with_extension.dart';
import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.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/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_screen.dart';
import 'package:wyatt_ui_kit/src/components/buttons/symbol_button/symbol_button_theme_resolver.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'; part 'symbol_button.g.dart';
@ComponentCopyWithExtension() @ComponentCopyWithExtension()
class SymbolButton extends SymbolButtonComponent class SymbolButton extends SymbolButtonComponent
with $SymbolButtonCWMixin{ with $SymbolButtonCWMixin, ExportBloc<SelectableButtonCubit> {
SymbolButton({ SymbolButton({
super.icon, super.icon,
super.label, super.label,
@ -44,6 +44,7 @@ class SymbolButton extends SymbolButtonComponent
final SelectableButtonCubit _cubit = SelectableButtonCubit(); final SelectableButtonCubit _cubit = SelectableButtonCubit();
@override
SelectableButtonCubit get bloc => _cubit; SelectableButtonCubit get bloc => _cubit;
@override @override
@ -73,8 +74,7 @@ class SymbolButton extends SymbolButtonComponent
super.themeResolver as SymbolButtonThemeResolver?; super.themeResolver as SymbolButtonThemeResolver?;
@override @override
Widget build(BuildContext context) => ExportableBloc( Widget build(BuildContext context) => exportBloc(
bloc: _cubit,
child: SymbolButtonScreen( child: SymbolButtonScreen(
icon: icon, icon: icon,
label: label, label: label,

View File

@ -24,6 +24,7 @@ import 'package:wyatt_ui_kit/src/components/buttons/cubit/selectable_button_cubi
import 'package:wyatt_ui_kit/src/components/buttons/symbol_button/symbol_button_theme_resolver.dart'; import 'package:wyatt_ui_kit/src/components/buttons/symbol_button/symbol_button_theme_resolver.dart';
import 'package:wyatt_ui_kit/src/components/gradients/gradient_box_border.dart'; import 'package:wyatt_ui_kit/src/components/gradients/gradient_box_border.dart';
import 'package:wyatt_ui_kit/src/components/gradients/gradient_text.dart'; import 'package:wyatt_ui_kit/src/components/gradients/gradient_text.dart';
import 'package:wyatt_ui_kit/src/core/helpers/linear_gradient_helper.dart';
class SymbolButtonScreen class SymbolButtonScreen
extends CubitScreen<SelectableButtonCubit, ButtonState> { extends CubitScreen<SelectableButtonCubit, ButtonState> {
@ -60,10 +61,10 @@ class SymbolButtonScreen
SelectableButtonCubit create(BuildContext context) => SelectableButtonCubit(); SelectableButtonCubit create(BuildContext context) => SelectableButtonCubit();
/// Negotiate the theme to get a complete style. /// Negotiate the theme to get a complete style.
SymbolButtonStyle _resolve(BuildContext context, ButtonState state) { SymbolButtonStyle resolve(BuildContext context, ButtonState state) {
final SymbolButtonThemeResolver resolver = themeResolver ?? final SymbolButtonThemeResolver resolver = themeResolver ??
SymbolButtonThemeResolver( SymbolButtonThemeResolver(
customStyleFn: (context, {extra}) { customStyleFn: (context, extensionValue, {extra}) {
SymbolButtonStyle? style; SymbolButtonStyle? style;
switch (extra?.state) { switch (extra?.state) {
case ControlState.disabled: case ControlState.disabled:
@ -95,7 +96,7 @@ class SymbolButtonScreen
@override @override
Widget onBuild(BuildContext context, ButtonState state) { Widget onBuild(BuildContext context, ButtonState state) {
final style = _resolve(context, state); final style = resolve(context, state);
return Focus( return Focus(
onFocusChange: (hasFocus) => onFocusChange: (hasFocus) =>
@ -196,7 +197,12 @@ class SymbolButtonScreen
label!.text, label!.text,
style: label!.style ?? style.label, style: label!.style ?? style.label,
).toGradient( ).toGradient(
gradientColors: style.foregroundColors, LinearGradientHelper.fromNullableColors(
label?.gradient ??
((style.foregroundColors?.isGradient ?? false)
? style.foregroundColors?.colors
: null),
),
), ),
], ],
], ],

View File

@ -69,17 +69,19 @@ class SymbolButtonThemeResolver extends ThemeResolver<SymbolButtonStyle,
@override @override
final SymbolButtonStyle? Function( final SymbolButtonStyle? Function(
BuildContext context, { BuildContext context,
SymbolButtonStyle? extensionValue, {
ButtonState? extra, ButtonState? extra,
}) customStyleFn; }) customStyleFn;
@override @override
SymbolButtonStyle? computeExtensionValueFn( SymbolButtonStyle? computeExtensionValueFn(
BuildContext context, BuildContext context,
SymbolButtonStyle defaultValue,
SymbolButtonThemeExtension themeExtension, { SymbolButtonThemeExtension themeExtension, {
ButtonState? extra, ButtonState? extra,
}) { }) {
SymbolButtonStyle? style; SymbolButtonStyle? style = defaultValue;
switch (extra?.state) { switch (extra?.state) {
case ControlState.disabled: case ControlState.disabled:
style = themeExtension.disabledStyle; style = themeExtension.disabledStyle;

View File

@ -80,7 +80,7 @@ class InformationCard extends InformationCardComponent
body!.text, body!.text,
textType: TextType.body, textType: TextType.body,
style: body!.style, style: body!.style,
gradientColors: body!.gradientColors, gradient: body!.gradient,
), ),
], ],
], ],

View File

@ -44,7 +44,7 @@ class InformationCardTitles extends StatelessWidget {
title!.text, title!.text,
textType: TextType.title, textType: TextType.title,
style: title!.style, style: title!.style,
gradientColors: title!.gradientColors, gradient: title!.gradient,
), ),
], ],
if (subtitle != null) ...[ if (subtitle != null) ...[
@ -53,7 +53,7 @@ class InformationCardTitles extends StatelessWidget {
subtitle!.text, subtitle!.text,
textType: TextType.subtitle, textType: TextType.subtitle,
style: subtitle!.style, style: subtitle!.style,
gradientColors: subtitle!.gradientColors, gradient: subtitle!.gradient,
), ),
], ],
], ],

View File

@ -73,7 +73,7 @@ class PortfolioCard extends PortfolioCardComponent with $PortfolioCardCWMixin {
description!.text, description!.text,
textType: TextType.body, textType: TextType.body,
style: description!.style, style: description!.style,
gradientColors: description!.gradientColors, gradient: description!.gradient,
), ),
const Gap(20), const Gap(20),
PortfolioCardHeader( PortfolioCardHeader(
@ -108,7 +108,7 @@ class PortfolioCard extends PortfolioCardComponent with $PortfolioCardCWMixin {
description!.text, description!.text,
textType: TextType.body, textType: TextType.body,
style: description!.style, style: description!.style,
gradientColors: description!.gradientColors, gradient: description!.gradient,
), ),
], ],
if (ctas != null) ...[const Gap(20), ...ctas!], if (ctas != null) ...[const Gap(20), ...ctas!],

View File

@ -71,7 +71,7 @@ class PortfolioCardHeader extends StatelessWidget {
color: secondaryBackgroundColors ?? color: secondaryBackgroundColors ??
Theme.of(context) Theme.of(context)
.extension<CardThemeExtension>() .extension<CardThemeExtension>()
?.secondaryBackgroundColor, ?.secondaryBackgroundColors,
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
), ),
child: Text( child: Text(

View File

@ -20,7 +20,8 @@ import 'package:wyatt_component_copy_with_extension/component_copy_with_extensio
import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart';
import 'package:wyatt_ui_kit/src/components/cards/widgets/card_text.dart'; import 'package:wyatt_ui_kit/src/components/cards/widgets/card_text.dart';
import 'package:wyatt_ui_kit/src/components/cards/widgets/card_wrapper.dart'; import 'package:wyatt_ui_kit/src/components/cards/widgets/card_wrapper.dart';
import 'package:wyatt_ui_kit/wyatt_ui_kit.dart'; import 'package:wyatt_ui_kit/src/components/gradients/gradient_text.dart';
import 'package:wyatt_ui_kit/src/core/extensions/theme_extensions.dart';
part 'quote_card.g.dart'; part 'quote_card.g.dart';
@ -62,11 +63,9 @@ class QuoteCard extends QuoteCardComponent with $QuoteCardCWMixin {
alignment: Alignment.topLeft, alignment: Alignment.topLeft,
child: GradientText( child: GradientText(
'', '',
style: GradientTextStyle.from( gradient: gradient,
context.textTheme.titleLarge style: context.textTheme.titleLarge
?.copyWith(fontWeight: FontWeight.bold), ?.copyWith(fontWeight: FontWeight.bold),
MultiColor(gradient?.colors),
),
), ),
), ),
if (quote != null) ...[ if (quote != null) ...[
@ -74,7 +73,7 @@ class QuoteCard extends QuoteCardComponent with $QuoteCardCWMixin {
quote!.text, quote!.text,
textType: TextType.body, textType: TextType.body,
style: quote!.style, style: quote!.style,
gradientColors: quote!.gradientColors, gradient: quote!.gradient,
), ),
], ],
const Gap(15), const Gap(15),
@ -83,11 +82,9 @@ class QuoteCard extends QuoteCardComponent with $QuoteCardCWMixin {
alignment: Alignment.bottomRight, alignment: Alignment.bottomRight,
child: GradientText( child: GradientText(
'', '',
style: GradientTextStyle.from( gradient: gradient,
context.textTheme.titleLarge style: context.textTheme.titleLarge
?.copyWith(fontWeight: FontWeight.bold), ?.copyWith(fontWeight: FontWeight.bold),
MultiColor(gradient?.colors),
),
), ),
), ),
Row( Row(
@ -105,7 +102,7 @@ class QuoteCard extends QuoteCardComponent with $QuoteCardCWMixin {
name!.text, name!.text,
textType: TextType.body, textType: TextType.body,
style: name!.style, style: name!.style,
gradientColors: name!.gradientColors, gradient: name!.gradient,
), ),
], ],
if (subtitle != null) ...[ if (subtitle != null) ...[
@ -113,7 +110,7 @@ class QuoteCard extends QuoteCardComponent with $QuoteCardCWMixin {
subtitle!.text, subtitle!.text,
textType: TextType.subtitle, textType: TextType.subtitle,
style: subtitle!.style, style: subtitle!.style,
gradientColors: subtitle!.gradientColors, gradient: subtitle!.gradient,
), ),
], ],
], ],

View File

@ -70,7 +70,7 @@ class SkillCard extends SkillCardComponent with $SkillCardCWMixin {
description!.text, description!.text,
textType: TextType.body, textType: TextType.body,
style: description!.style, style: description!.style,
gradientColors: description!.gradientColors, gradient: description!.gradient,
), ),
const Gap(25), const Gap(25),
], ],

View File

@ -46,7 +46,7 @@ class SkillCardHeader extends StatelessWidget {
color: secondaryBackgroundColors ?? color: secondaryBackgroundColors ??
Theme.of(context) Theme.of(context)
.extension<CardThemeExtension>() .extension<CardThemeExtension>()
?.secondaryBackgroundColor, ?.secondaryBackgroundColors,
), ),
child: gradient != null child: gradient != null
? GradientIcon( ? GradientIcon(
@ -67,7 +67,7 @@ class SkillCardHeader extends StatelessWidget {
title!.text, title!.text,
textType: TextType.title, textType: TextType.title,
style: title!.style, style: title!.style,
gradientColors: title!.gradientColors, gradient: title!.gradient,
), ),
], ],
], ],

View File

@ -50,7 +50,7 @@ class SkillCardSkills extends StatelessWidget {
e.text, e.text,
textType: TextType.body, textType: TextType.body,
style: e.style, style: e.style,
gradientColors: e.gradientColors, gradient: e.gradient,
), ),
), ),
], ],

View File

@ -15,7 +15,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; import 'package:wyatt_ui_kit/src/components/gradients/gradient_text.dart';
import 'package:wyatt_ui_kit/wyatt_ui_kit.dart'; import 'package:wyatt_ui_kit/wyatt_ui_kit.dart';
enum TextType { enum TextType {
@ -28,13 +28,13 @@ class CardText extends StatelessWidget {
const CardText( const CardText(
this.data, { this.data, {
required this.textType, required this.textType,
this.gradient,
this.style, this.style,
this.gradientColors,
super.key, super.key,
}); });
final TextType textType; final TextType textType;
final TextStyle? style; final TextStyle? style;
final MultiColor? gradientColors; final List<Color>? gradient;
final String data; final String data;
TextStyle? _getStyle(BuildContext context) { TextStyle? _getStyle(BuildContext context) {
@ -58,5 +58,9 @@ class CardText extends StatelessWidget {
Widget build(BuildContext context) => Text( Widget build(BuildContext context) => Text(
data, data,
style: _getStyle(context), style: _getStyle(context),
).toGradient(gradientColors: gradientColors); ).toGradient(
LinearGradientHelper.fromNullableColors(
gradient,
),
);
} }

View File

@ -110,10 +110,8 @@ class _CardWrapperState extends State<CardWrapper> {
if (extensionCardColor != null && if (extensionCardColor != null &&
extensionCardColor.backgroundColors != null && extensionCardColor.backgroundColors != null &&
extensionCardColor.backgroundColors!.isGradient) { extensionCardColor.backgroundColors!.length >= 2) {
return LinearGradient( return LinearGradient(colors: extensionCardColor.backgroundColors!);
colors: extensionCardColor.backgroundColors!.colors,
);
} }
} }
return null; return null;
@ -128,8 +126,9 @@ class _CardWrapperState extends State<CardWrapper> {
Theme.of(context).extension<CardThemeExtension>(); Theme.of(context).extension<CardThemeExtension>();
if (extensionCardColor != null && if (extensionCardColor != null &&
extensionCardColor.backgroundColors != null) { extensionCardColor.backgroundColors != null &&
return extensionCardColor.backgroundColors!.color; extensionCardColor.backgroundColors!.length == 1) {
return extensionCardColor.backgroundColors!.first;
} }
} }
return Theme.of(context).cardColor; return Theme.of(context).cardColor;
@ -152,16 +151,16 @@ class _CardWrapperState extends State<CardWrapper> {
final extensionCardColor = final extensionCardColor =
Theme.of(context).extension<CardThemeExtension>(); Theme.of(context).extension<CardThemeExtension>();
if (extensionCardColor != null && if (extensionCardColor != null &&
extensionCardColor.borderColors != null) { extensionCardColor.borderColor != null) {
if (extensionCardColor.borderColors!.isGradient) { if (extensionCardColor.borderColor!.length >= 2) {
return CustomGradientBoxBorder( return CustomGradientBoxBorder(
gradient: LinearGradient( gradient: LinearGradient(
colors: extensionCardColor.borderColors!.colors, colors: extensionCardColor.borderColor!,
), ),
); );
} else if (extensionCardColor.backgroundColors!.colors.isNotEmpty) { } else if (extensionCardColor.backgroundColors!.isNotEmpty) {
return Border.all( return Border.all(
color: extensionCardColor.backgroundColors!.color, color: extensionCardColor.backgroundColors!.first,
); );
} }
} }

View File

@ -16,7 +16,4 @@
export './buttons/buttons.dart'; export './buttons/buttons.dart';
export './cards/cards.dart'; export './cards/cards.dart';
export './gradients/gradients.dart';
export './loader/loader.dart';
export './rich_text_builder/rich_text_builder.dart';
export './text_inputs/text_input.dart'; export './text_inputs/text_input.dart';

View File

@ -17,29 +17,16 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart';
import 'package:wyatt_ui_kit/wyatt_ui_kit.dart';
extension GradientTextExtension on Text { extension GradientTextExtension on Text {
/// If this text contains a [GradientTextStyle] it simply transforms it in GradientText toGradient(Gradient? gradient) =>
/// [GradientText], if not it needs a [MultiColor]. GradientText.from(this, gradient);
GradientText toGradient({MultiColor? gradientColors}) {
if (style is GradientTextStyle?) {
// Gradient
final gradientStyle = (style as GradientTextStyle?)?.gradientColors;
return GradientText.from(this, gradientStyle ?? gradientColors);
}
return GradientText.from(this, gradientColors);
}
GradientText toFlutterGradient(Gradient? gradient) =>
GradientText.from(this, MultiColor(gradient?.colors));
} }
class GradientText extends Text { class GradientText extends Text {
const GradientText( const GradientText(
super.data, { super.data, {
this.gradient,
super.style, super.style,
super.strutStyle, super.strutStyle,
super.textAlign, super.textAlign,
@ -56,10 +43,10 @@ class GradientText extends Text {
super.key, super.key,
}); });
factory GradientText.from(Text text, MultiColor? gradientColors) => factory GradientText.from(Text text, Gradient? gradient) => GradientText(
GradientText(
text.data ?? '', text.data ?? '',
style: GradientTextStyle.from(text.style, gradientColors), style: text.style,
gradient: gradient,
strutStyle: text.strutStyle, strutStyle: text.strutStyle,
textAlign: text.textAlign, textAlign: text.textAlign,
textDirection: text.textDirection, textDirection: text.textDirection,
@ -75,24 +62,20 @@ class GradientText extends Text {
key: text.key, key: text.key,
); );
final Gradient? gradient;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (style is GradientTextStyle?) {
// Gradient
final gradientStyle = (style as GradientTextStyle?)?.gradientColors;
final gradient = (gradientStyle?.isGradient ?? false)
? LinearGradientHelper.fromMultiColor(gradientStyle!)
: null;
if (gradient != null) { if (gradient != null) {
return ShaderMask( return ShaderMask(
blendMode: BlendMode.srcIn, blendMode: BlendMode.srcIn,
shaderCallback: (bounds) => gradient.createShader( shaderCallback: (bounds) => gradient!.createShader(
Rect.fromLTWH(0, 0, bounds.width, bounds.height), Rect.fromLTWH(0, 0, bounds.width, bounds.height),
), ),
child: super.build(context), child: super.build(context),
); );
} } else {
}
return super.build(context); return super.build(context);
} }
} }
}

View File

@ -1,85 +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/widgets.dart';
import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart';
class GradientTextStyle extends TextStyle {
const GradientTextStyle({
this.gradientColors,
super.inherit,
super.color,
super.backgroundColor,
super.fontSize,
super.fontWeight,
super.fontStyle,
super.letterSpacing,
super.wordSpacing,
super.textBaseline,
super.height,
super.leadingDistribution,
super.locale,
super.foreground,
super.background,
super.shadows,
super.fontFeatures,
super.fontVariations,
super.decoration,
super.decorationColor,
super.decorationStyle,
super.decorationThickness,
super.debugLabel,
super.fontFamily,
super.fontFamilyFallback,
super.package,
super.overflow,
});
factory GradientTextStyle.from(
TextStyle? textStyle,
MultiColor? gradientColors,
) =>
GradientTextStyle(
gradientColors: gradientColors,
inherit: textStyle?.inherit ?? true,
color: textStyle?.color,
backgroundColor: textStyle?.backgroundColor,
fontSize: textStyle?.fontSize,
fontWeight: textStyle?.fontWeight,
fontStyle: textStyle?.fontStyle,
letterSpacing: textStyle?.letterSpacing,
wordSpacing: textStyle?.wordSpacing,
textBaseline: textStyle?.textBaseline,
height: textStyle?.height,
leadingDistribution: textStyle?.leadingDistribution,
locale: textStyle?.locale,
foreground: textStyle?.foreground,
background: textStyle?.background,
shadows: textStyle?.shadows,
fontFeatures: textStyle?.fontFeatures,
fontVariations: textStyle?.fontVariations,
decoration: textStyle?.decoration,
decorationColor: textStyle?.decorationColor,
decorationStyle: textStyle?.decorationStyle,
decorationThickness: textStyle?.decorationThickness,
debugLabel: textStyle?.debugLabel,
fontFamily: textStyle?.fontFamily,
fontFamilyFallback: textStyle?.fontFamilyFallback,
overflow: textStyle?.overflow,
);
final MultiColor? gradientColors;
}

View File

@ -1,20 +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/>.
export 'gradient_box_border.dart';
export 'gradient_icon.dart';
export 'gradient_text.dart';
export 'gradient_text_style.dart';

View File

@ -1,135 +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 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_animate/flutter_animate.dart';
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/loader/loader_theme_resolver.dart';
import 'package:wyatt_ui_kit/wyatt_ui_kit.dart';
part 'loader.g.dart';
@ComponentCopyWithExtension()
class Loader extends LoaderComponent with $LoaderCWMixin {
const Loader({
super.colors,
super.radius,
super.stroke,
super.duration,
super.flip,
super.themeResolver,
super.key,
});
@override
LoaderThemeResolver? get themeResolver =>
super.themeResolver as LoaderThemeResolver?;
/// Negotiate the theme to get a complete style.
LoaderStyle _resolve(BuildContext context) {
final LoaderThemeResolver resolver = themeResolver ??
LoaderThemeResolver(
customStyleFn: (context, {extra}) => LoaderStyle(
colors: colors,
stroke: stroke,
),
);
return resolver.negotiate(context);
}
@override
Widget build(BuildContext context) {
final style = _resolve(context);
final dimension =
(radius != null) ? radius! * 2 : context.buttonTheme.height;
return SizedBox.square(
dimension: dimension,
child: RepaintBoundary(
child: CustomPaint(
painter: _LoaderPainter(
style.colors!,
dimension / 2,
style.stroke!,
flip: flip ?? false,
),
)
.animate(
onPlay: (controller) => controller.repeat(),
)
.rotate(
duration: duration ?? 900.ms,
begin: (flip ?? false) ? 0 : 1,
end: (flip ?? false) ? 1 : 0,
),
),
);
}
}
class _LoaderPainter extends CustomPainter {
_LoaderPainter(
this.colors,
this.radius,
this.stroke, {
required this.flip,
});
final MultiColor colors;
final double radius;
final double stroke;
final bool flip;
@override
void paint(Canvas canvas, Size size) {
final center = Offset(size.width / 2, size.height / 2);
final circleSurface = Rect.fromCircle(center: center, radius: radius);
final dotColor = colors.color;
final dotCenter =
Offset(size.width / 2 + (flip ? -radius : radius), size.height / 2);
final gradient =
colors.isGradient ? colors.colors : [colors.color, colors.color];
final gradientCirclePainter = Paint()
..shader = SweepGradient(
colors: (flip ? gradient.reversed : gradient).toList(),
transform: flip ? const GradientRotation(pi) : null,
).createShader(circleSurface)
..strokeWidth = stroke
..style = PaintingStyle.stroke
..strokeCap = StrokeCap.round;
final dotPainter = Paint()
..color = dotColor
..style = PaintingStyle.fill
..strokeCap = StrokeCap.round;
canvas
..drawCircle(center, radius, gradientCirclePainter)
..drawCircle(dotCenter, stroke / 2, dotPainter);
}
@override
bool shouldRepaint(_LoaderPainter oldDelegate) => false;
@override
bool shouldRebuildSemantics(_LoaderPainter oldDelegate) => false;
}

View File

@ -1,51 +0,0 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'loader.dart';
// **************************************************************************
// ComponentCopyWithGenerator
// **************************************************************************
class $LoaderCWProxyImpl implements $LoaderComponentCWProxy {
const $LoaderCWProxyImpl(this._value);
final Loader _value;
@override
Loader colors(MultiColor? colors) => this(colors: colors);
@override
Loader radius(double? radius) => this(radius: radius);
@override
Loader stroke(double? stroke) => this(stroke: stroke);
@override
Loader duration(Duration? duration) => this(duration: duration);
@override
Loader flip(bool? flip) => this(flip: flip);
@override
Loader themeResolver(
ThemeResolver<dynamic, dynamic, dynamic>? themeResolver) =>
this(themeResolver: themeResolver);
@override
Loader key(Key? key) => this(key: key);
@override
Loader call({
MultiColor? colors,
double? radius,
double? stroke,
Duration? duration,
bool? flip,
ThemeResolver<dynamic, dynamic, dynamic>? themeResolver,
Key? key,
}) =>
Loader(
colors: colors ?? _value.colors,
radius: radius ?? _value.radius,
stroke: stroke ?? _value.stroke,
duration: duration ?? _value.duration,
flip: flip ?? _value.flip,
themeResolver: themeResolver ?? _value.themeResolver,
key: key ?? _value.key,
);
}
mixin $LoaderCWMixin on Component {
$LoaderComponentCWProxy get copyWith => $LoaderCWProxyImpl(this as Loader);
}

View File

@ -1,58 +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:wyatt_ui_components/wyatt_wyatt_ui_components.dart';
import 'package:wyatt_ui_kit/wyatt_ui_kit.dart';
class LoaderThemeResolver
extends ThemeResolver<LoaderStyle, LoaderThemeExtension, void> {
const LoaderThemeResolver({
required this.customStyleFn,
});
/// Values taken from <https://api.flutter.dev/flutter/material/ElevatedButton/defaultStyleOf.html>
@override
LoaderStyle computeDefaultValue(
BuildContext context, {
void extra,
}) =>
LoaderStyle(
colors: MultiColor([
Theme.of(context).progressIndicatorTheme.color ??
context.colorScheme.primary,
context.colorScheme.onPrimary,
]),
stroke: 4,
);
@override
final LoaderStyle? Function(
BuildContext context, {
void extra,
}) customStyleFn;
@override
LoaderStyle? computeExtensionValueFn(
BuildContext context,
LoaderThemeExtension themeExtension, {
void extra,
}) =>
LoaderStyle(
colors: themeExtension.colors,
stroke: themeExtension.stroke,
);
}

View File

@ -1,98 +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: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/rich_text_builder/rich_text_builder_theme_resolver.dart';
import 'package:wyatt_ui_kit/wyatt_ui_kit.dart';
part 'rich_text_builder.g.dart';
@ComponentCopyWithExtension()
class RichTextBuilder extends RichTextBuilderComponent
with $RichTextBuilderCWMixin {
const RichTextBuilder({
super.text,
super.parser,
super.defaultStyle,
super.styles,
super.themeResolver,
super.key,
});
@override
RichTextBuilderThemeResolver? get themeResolver =>
super.themeResolver as RichTextBuilderThemeResolver?;
/// Negotiate the theme to get a complete style.
RichTextBuilderStyle _resolve(BuildContext context) {
final RichTextBuilderThemeResolver resolver = themeResolver ??
RichTextBuilderThemeResolver(
customStyleFn: (context, {extra}) => RichTextBuilderStyle(
defaultStyle: defaultStyle,
styles: styles,
),
);
return resolver.negotiate(context);
}
@override
Widget build(BuildContext context) {
final style = _resolve(context);
final RegExp regex = RegExp(r'<(.*?)>(.*?)<\/\1>');
final root = RichTextNode.from(
text ?? '',
regex,
RichTextStyleParameter(
style.defaultStyle!,
style.styles ?? {},
null,
),
);
final customParser = parser ??
RichTextParser(
nodeBuilder: (content, style) {
if (style is GradientTextStyle?) {
return WidgetSpan(
child: GradientText(
content,
style: style,
softWrap: true,
textHeightBehavior: const TextHeightBehavior(
applyHeightToLastDescent: false,
),
),
style: style,
);
}
return TextSpan(
text: content,
style: style,
);
},
);
return SelectionArea(
child: Text.rich(
TextSpan(children: [root.toInlineSpan(customParser)]),
textHeightBehavior:
const TextHeightBehavior(applyHeightToLastDescent: false),
),
);
}
}

View File

@ -1,50 +0,0 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'rich_text_builder.dart';
// **************************************************************************
// ComponentCopyWithGenerator
// **************************************************************************
class $RichTextBuilderCWProxyImpl implements $RichTextBuilderComponentCWProxy {
const $RichTextBuilderCWProxyImpl(this._value);
final RichTextBuilder _value;
@override
RichTextBuilder text(String? text) => this(text: text);
@override
RichTextBuilder parser(RichTextParser? parser) => this(parser: parser);
@override
RichTextBuilder defaultStyle(TextStyle? defaultStyle) =>
this(defaultStyle: defaultStyle);
@override
RichTextBuilder styles(Map<String, TextStyle>? styles) =>
this(styles: styles);
@override
RichTextBuilder themeResolver(
ThemeResolver<dynamic, dynamic, dynamic>? themeResolver) =>
this(themeResolver: themeResolver);
@override
RichTextBuilder key(Key? key) => this(key: key);
@override
RichTextBuilder call({
String? text,
RichTextParser? parser,
TextStyle? defaultStyle,
Map<String, TextStyle>? styles,
ThemeResolver<dynamic, dynamic, dynamic>? themeResolver,
Key? key,
}) =>
RichTextBuilder(
text: text ?? _value.text,
parser: parser ?? _value.parser,
defaultStyle: defaultStyle ?? _value.defaultStyle,
styles: styles ?? _value.styles,
themeResolver: themeResolver ?? _value.themeResolver,
key: key ?? _value.key,
);
}
mixin $RichTextBuilderCWMixin on Component {
$RichTextBuilderComponentCWProxy get copyWith =>
$RichTextBuilderCWProxyImpl(this as RichTextBuilder);
}

View File

@ -1,53 +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:wyatt_ui_components/wyatt_wyatt_ui_components.dart';
import 'package:wyatt_ui_kit/wyatt_ui_kit.dart';
class RichTextBuilderThemeResolver extends ThemeResolver<RichTextBuilderStyle,
RichTextBuilderThemeExtension, void> {
const RichTextBuilderThemeResolver({
required this.customStyleFn,
});
/// Values taken from <https://api.flutter.dev/flutter/material/ElevatedButton/defaultStyleOf.html>
@override
RichTextBuilderStyle computeDefaultValue(
BuildContext context, {
void extra,
}) =>
RichTextBuilderStyle(
defaultStyle: context.textTheme.bodyMedium,
);
@override
final RichTextBuilderStyle? Function(
BuildContext context, {
void extra,
}) customStyleFn;
@override
RichTextBuilderStyle? computeExtensionValueFn(
BuildContext context,
RichTextBuilderThemeExtension themeExtension, {
void extra,
}) =>
RichTextBuilderStyle(
defaultStyle: themeExtension.defaultStyle,
styles: themeExtension.styles,
);
}

View File

@ -195,7 +195,7 @@ class TextInputScreen extends CubitScreen<TextInputCubit, TextInputState> {
TextInputStyle _resolve(BuildContext context, TextInputState state) { TextInputStyle _resolve(BuildContext context, TextInputState state) {
final resolver = TextInputThemeResolver( final resolver = TextInputThemeResolver(
customStyleFn: (context, {extra}) { customStyleFn: (context, extensionValue, {extra}) {
TextInputStyle? textInputStyle; TextInputStyle? textInputStyle;
switch (extra?.controlState) { switch (extra?.controlState) {
case ControlState.focused: case ControlState.focused:
@ -230,7 +230,10 @@ class TextInputScreen extends CubitScreen<TextInputCubit, TextInputState> {
break; break;
} }
return TextInputStyle.merge(textInputStyle, style); return TextInputStyle.merge(
extensionValue,
TextInputStyle.merge(textInputStyle, style),
);
}, },
); );

View File

@ -28,7 +28,8 @@ class TextInputThemeResolver extends ThemeResolver<TextInputStyle,
@override @override
final TextInputStyle? Function( final TextInputStyle? Function(
BuildContext context, { BuildContext context,
TextInputStyle extensionValue, {
TextInputState? extra, TextInputState? extra,
}) customStyleFn; }) customStyleFn;
@ -125,6 +126,7 @@ class TextInputThemeResolver extends ThemeResolver<TextInputStyle,
@override @override
TextInputStyle? computeExtensionValueFn( TextInputStyle? computeExtensionValueFn(
BuildContext context, BuildContext context,
TextInputStyle defaultValue,
TextInputThemeExtension themeExtension, { TextInputThemeExtension themeExtension, {
TextInputState? extra, TextInputState? extra,
}) { }) {
@ -162,6 +164,9 @@ class TextInputThemeResolver extends ThemeResolver<TextInputStyle,
break; break;
} }
return TextInputStyle.merge(textInputStyle, style); return TextInputStyle.merge(
defaultValue,
TextInputStyle.merge(textInputStyle, style),
);
} }
} }

View File

@ -14,10 +14,13 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
abstract class DemoPage extends StatelessWidget { mixin ExportBloc<T extends StateStreamableSource<Object?>> {
const DemoPage({super.key}); T get bloc;
Widget exportBloc({required Widget child}) => BlocProvider<T>.value(
String get title; value: bloc,
child: child,
);
} }

View File

@ -15,13 +15,12 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart';
abstract class CardThemeExtension extends ThemeExtension<CardThemeExtension> { abstract class CardThemeExtension extends ThemeExtension<CardThemeExtension> {
const CardThemeExtension({ const CardThemeExtension({
this.backgroundColors, this.backgroundColors,
this.secondaryBackgroundColor, this.secondaryBackgroundColors,
this.borderColors, this.borderColor,
this.shadowColor, this.shadowColor,
this.body, this.body,
this.title, this.title,
@ -29,9 +28,9 @@ abstract class CardThemeExtension extends ThemeExtension<CardThemeExtension> {
}); });
// Colors // Colors
final MultiColor? backgroundColors; final List<Color>? backgroundColors;
final Color? secondaryBackgroundColor; final Color? secondaryBackgroundColors;
final MultiColor? borderColors; final List<Color>? borderColor;
final BoxShadow? shadowColor; final BoxShadow? shadowColor;
// TextStyles // TextStyles

View File

@ -16,6 +16,4 @@
export './button_theme_extension/button_theme_extension.dart'; export './button_theme_extension/button_theme_extension.dart';
export './card_theme_extension.dart'; export './card_theme_extension.dart';
export './loader_theme_extension.dart'; export 'text_input_theme_extension.dart';
export './rich_text_builder_theme_extension.dart';
export './text_input_theme_extension.dart';

View File

@ -1,32 +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:wyatt_ui_components/wyatt_wyatt_ui_components.dart';
abstract 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;
}

View File

@ -1,31 +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';
abstract 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;
}

View File

@ -17,10 +17,9 @@ dependencies:
gap: ^2.0.1 gap: ^2.0.1
meta: ^1.8.0 meta: ^1.8.0
wyatt_bloc_helper: wyatt_bloc_helper:
hosted: git:
url: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub/ url: ssh://git@git.wyatt-studio.fr:993/Wyatt-FOSS/wyatt-packages.git
name: wyatt_bloc_helper path: packages/wyatt_bloc_helper
version: 2.0.0
wyatt_component_copy_with_extension: wyatt_component_copy_with_extension:
git: git:
url: ssh://git@git.wyatt-studio.fr:993/Wyatt-FOSS/wyatt-packages.git url: ssh://git@git.wyatt-studio.fr:993/Wyatt-FOSS/wyatt-packages.git

View File

@ -0,0 +1 @@
// TODO(wyatt): add some tests