refactor(ui): replace ThemeResolver by ThemeHelper in Loader / RichTextBuilder (closes #148)
This commit is contained in:
@@ -19,8 +19,7 @@ export './buttons/buttons.dart';
|
||||
export './cards/cards.dart';
|
||||
export './component.dart';
|
||||
export './error_widget_component.dart';
|
||||
export './loader_component.dart';
|
||||
export './loader_style.dart';
|
||||
export './loader/loader.dart';
|
||||
export './loading_widget_component.dart';
|
||||
export './rich_text_builder/rich_text_builder.dart';
|
||||
export './text_inputs/text_inputs.dart';
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
// 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 './loader_component.dart';
|
||||
@@ -1,82 +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:wyatt_ui_components/wyatt_wyatt_ui_components.dart';
|
||||
|
||||
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
|
||||
LoaderStyle copyWith({
|
||||
MultiColor? colors,
|
||||
double? stroke,
|
||||
}) =>
|
||||
LoaderStyle(
|
||||
colors: colors ?? this.colors,
|
||||
stroke: stroke ?? this.stroke,
|
||||
);
|
||||
|
||||
@override
|
||||
String toString() => 'LoaderStyle($colors, $stroke)';
|
||||
}
|
||||
-1
@@ -16,4 +16,3 @@
|
||||
|
||||
export 'parser.dart';
|
||||
export 'rich_text_builder_component.dart';
|
||||
export 'rich_text_builder_style.dart';
|
||||
|
||||
-1
@@ -28,7 +28,6 @@ abstract class RichTextBuilderComponent extends Component
|
||||
this.parser,
|
||||
this.defaultStyle,
|
||||
this.styles,
|
||||
super.themeResolver,
|
||||
super.key,
|
||||
});
|
||||
|
||||
|
||||
-3
@@ -11,15 +11,12 @@ abstract class $RichTextBuilderComponentCWProxy {
|
||||
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,
|
||||
});
|
||||
}
|
||||
|
||||
-79
@@ -1,79 +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 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);
|
||||
|
||||
@override
|
||||
RichTextBuilderStyle? copyWith({
|
||||
TextStyle? defaultStyle,
|
||||
Map<String, TextStyle>? styles,
|
||||
}) =>
|
||||
RichTextBuilderStyle(
|
||||
defaultStyle: defaultStyle ?? this.defaultStyle,
|
||||
styles: styles ?? this.styles,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user