feat(ui_component): add loader component and style

This commit is contained in:
Hugo Pointcheval 2023-02-16 15:12:40 +01:00
parent 63bbde8213
commit a47c28a4d6
Signed by: hugo
GPG Key ID: 3AAC487E131E00BC
4 changed files with 165 additions and 0 deletions

View File

@ -20,5 +20,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 './loading_widget_component.dart';
export './theme_style.dart';

View File

@ -0,0 +1,50 @@
// Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import 'package:flutter/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

@ -0,0 +1,27 @@
// 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

@ -0,0 +1,86 @@
// 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? lerpWith(LoaderStyle? other, double t) =>
LoaderStyle.lerp(this, other, t);
@override
LoaderStyle copyWith({
MultiColor? colors,
double? stroke,
}) =>
LoaderStyle(
colors: colors ?? this.colors,
stroke: stroke ?? this.stroke,
);
@override
String toString() => 'LoaderStyle($colors, $stroke)';
}