refactor(ui_component): merge flat and outline buttons in only one style

This commit is contained in:
Hugo Pointcheval 2023-02-13 17:07:39 +01:00
parent 5050e2c2bb
commit 61e28ce5e7
Signed by: hugo
GPG Key ID: 3AAC487E131E00BC
9 changed files with 75 additions and 144 deletions

View File

@ -15,24 +15,39 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import 'package:flutter/widgets.dart';
import 'package:wyatt_ui_components/src/core/enums/control_state.dart';
import 'package:wyatt_ui_components/src/domain/entities/buttons/button_style.dart';
import 'package:wyatt_ui_components/src/domain/entities/component.dart';
abstract class ButtonComponent extends Component {
const ButtonComponent({
this.state = ControlState.normal,
this.mainAxisSize = MainAxisSize.min,
this.style,
this.disabledStyle,
this.normalStyle,
this.hoveredStyle,
this.focusedStyle,
this.tappedStyle,
this.onPressed,
super.key,
});
/// Actual state of the button
final ControlState? state;
/// Main axis size
final MainAxisSize? mainAxisSize;
/// Style of this button
final ButtonStyle? style;
/// Style of this button in disabled state
final ButtonStyle? disabledStyle;
/// Style of this button in normal state
final ButtonStyle? normalStyle;
/// Style of this button in hovered state
final ButtonStyle? hoveredStyle;
/// Style of this button in focused state
final ButtonStyle? focusedStyle;
/// Style of this button in tapped state
final ButtonStyle? tappedStyle;
/// Callback on button press
final VoidCallback? onPressed;
}

View File

@ -21,7 +21,10 @@ abstract class ButtonStyle {
const ButtonStyle({
this.radius = 15,
this.padding = 10,
this.foregroundColors,
this.backgroundColors,
this.borderColors,
this.stroke = 2,
this.shadow = const BoxShadow(
blurRadius: 30,
offset: Offset(0, 5),
@ -35,9 +38,18 @@ abstract class ButtonStyle {
/// Padding and gaps of this card
final double? padding;
/// Button foreground gradient colors (from left to right)
final MultiColor? foregroundColors;
/// Button background gradient colors (from left to right)
final MultiColor? backgroundColors;
/// Border colors (from left to right).
final MultiColor? borderColors;
/// Stroke of the border
final double? stroke;
/// Drop shadow
final BoxShadow? shadow;

View File

@ -18,5 +18,3 @@ export './button_component.dart';
export './button_style.dart';
export './flat_button_component.dart';
export './flat_button_style.dart';
export './outlined_button_component.dart';
export './outlined_button_style.dart';

View File

@ -27,14 +27,30 @@ abstract class FlatButtonComponent extends ButtonComponent
this.prefix,
this.suffix,
this.label,
super.state,
super.style,
super.disabledStyle,
super.normalStyle,
super.hoveredStyle,
super.focusedStyle,
super.tappedStyle,
super.onPressed,
super.mainAxisSize,
super.key,
});
@override
FlatButtonStyle? get style;
FlatButtonStyle? get disabledStyle;
@override
FlatButtonStyle? get normalStyle;
@override
FlatButtonStyle? get hoveredStyle;
@override
FlatButtonStyle? get focusedStyle;
@override
FlatButtonStyle? get tappedStyle;
final Widget? prefix;
final Widget? suffix;

View File

@ -10,16 +10,24 @@ abstract class $FlatButtonComponentCWProxy {
FlatButtonComponent prefix(Widget? prefix);
FlatButtonComponent suffix(Widget? suffix);
FlatButtonComponent label(TextWrapper? label);
FlatButtonComponent state(ControlState? state);
FlatButtonComponent style(ButtonStyle? style);
FlatButtonComponent disabledStyle(ButtonStyle? disabledStyle);
FlatButtonComponent normalStyle(ButtonStyle? normalStyle);
FlatButtonComponent hoveredStyle(ButtonStyle? hoveredStyle);
FlatButtonComponent focusedStyle(ButtonStyle? focusedStyle);
FlatButtonComponent tappedStyle(ButtonStyle? tappedStyle);
FlatButtonComponent onPressed(void Function()? onPressed);
FlatButtonComponent mainAxisSize(MainAxisSize? mainAxisSize);
FlatButtonComponent key(Key? key);
FlatButtonComponent call({
Widget? prefix,
Widget? suffix,
TextWrapper? label,
ControlState? state,
ButtonStyle? style,
ButtonStyle? disabledStyle,
ButtonStyle? normalStyle,
ButtonStyle? hoveredStyle,
ButtonStyle? focusedStyle,
ButtonStyle? tappedStyle,
void Function()? onPressed,
MainAxisSize? mainAxisSize,
Key? key,
});

View File

@ -22,7 +22,10 @@ class FlatButtonStyle extends ButtonStyle {
const FlatButtonStyle({
super.radius = 15,
super.padding = 10,
super.foregroundColors,
super.backgroundColors,
super.borderColors,
super.stroke = 2,
super.shadow = const BoxShadow(
blurRadius: 30,
offset: Offset(0, 5),
@ -34,14 +37,19 @@ class FlatButtonStyle extends ButtonStyle {
FlatButtonStyle copyWith({
double? radius,
double? padding,
MultiColor? foregroundColors,
MultiColor? backgroundColors,
BoxShadow? shadow,
MultiColor? borderColors,
double? stroke,
BoxShadow? shadow,
}) =>
FlatButtonStyle(
radius: radius ?? this.radius,
padding: padding ?? this.padding,
foregroundColors: foregroundColors ?? this.foregroundColors,
backgroundColors: backgroundColors ?? this.backgroundColors,
borderColors: borderColors ?? this.borderColors,
stroke: stroke ?? this.stroke,
shadow: shadow ?? this.shadow,
);
}

View File

@ -1,42 +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 'outlined_button_component.g.dart';
@ComponentProxyExtension()
abstract class OutlinedButtonComponent extends ButtonComponent
with CopyWithMixin<$OutlinedButtonComponentCWProxy> {
const OutlinedButtonComponent({
this.prefix,
this.suffix,
this.label,
super.state,
super.style,
super.mainAxisSize,
super.key,
});
@override
OutlinedButtonStyle? get style;
final Widget? prefix;
final Widget? suffix;
final TextWrapper? label;
}

View File

@ -1,26 +0,0 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'outlined_button_component.dart';
// **************************************************************************
// ComponentProxyGenerator
// **************************************************************************
abstract class $OutlinedButtonComponentCWProxy {
OutlinedButtonComponent prefix(Widget? prefix);
OutlinedButtonComponent suffix(Widget? suffix);
OutlinedButtonComponent label(TextWrapper? label);
OutlinedButtonComponent state(ControlState? state);
OutlinedButtonComponent style(ButtonStyle? style);
OutlinedButtonComponent mainAxisSize(MainAxisSize? mainAxisSize);
OutlinedButtonComponent key(Key? key);
OutlinedButtonComponent call({
Widget? prefix,
Widget? suffix,
TextWrapper? label,
ControlState? state,
ButtonStyle? style,
MainAxisSize? mainAxisSize,
Key? key,
});
}

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/widgets.dart';
import 'package:wyatt_ui_components/src/core/utils/multi_color.dart';
import 'package:wyatt_ui_components/src/domain/entities/buttons/button_style.dart';
class OutlinedButtonStyle extends ButtonStyle {
const OutlinedButtonStyle({
super.radius = 15,
super.padding = 10,
super.backgroundColors,
super.shadow = const BoxShadow(
blurRadius: 30,
offset: Offset(0, 5),
color: Color.fromRGBO(0, 0, 0, 0.05),
),
this.borderColors,
this.stroke = 2,
});
/// Border colors (from left to right).
final MultiColor? borderColors;
/// Stroke of the border
final double? stroke;
@override
OutlinedButtonStyle copyWith({
double? radius,
double? padding,
MultiColor? borderColors,
MultiColor? backgroundColors,
BoxShadow? shadow,
double? stroke,
}) =>
OutlinedButtonStyle(
radius: radius ?? this.radius,
padding: padding ?? this.padding,
borderColors: borderColors ?? this.borderColors,
backgroundColors: backgroundColors ?? this.backgroundColors,
shadow: shadow ?? this.shadow,
stroke: stroke ?? this.stroke,
);
}