diff --git a/packages/wyatt_ui_kit/example/lib/buttons/buttons.dart b/packages/wyatt_ui_kit/example/lib/buttons/buttons.dart
index 3b049711..363ced46 100644
--- a/packages/wyatt_ui_kit/example/lib/buttons/buttons.dart
+++ b/packages/wyatt_ui_kit/example/lib/buttons/buttons.dart
@@ -24,11 +24,12 @@ const _color2 = Color(0xFF446DF4);
const _color3 = Color.fromARGB(255, 26, 132, 247);
const _color4 = Color.fromARGB(255, 19, 68, 228);
const _colors = [_color1, _color2];
-const _colorsDarken = [_color2, _color3];
+const _colorsDarken = [_color3, _color4];
const _disabled = Color(0xFF6B7280);
const _background = Color(0xFF16191D);
const _disabledBackground = Color(0xFF16191D + 0x66FFFFFF);
const _disabledColors = [Color(0xFF60656A), Color(0xFF383C40)];
+const _selectedColors = [Color(0xFF50CE99), Color(0xFF339572)];
class Buttons extends StatelessWidget {
const Buttons({super.key});
@@ -41,30 +42,30 @@ class Buttons extends StatelessWidget {
style: Theme.of(context).textTheme.titleLarge,
),
const Gap(20),
- const FlatButton(
- label: TextWrapper('Voir notre savoir faire'),
- normalStyle: FlatButtonStyle(
+ FlatButton(
+ label: const TextWrapper('Voir notre savoir faire'),
+ normalStyle: const FlatButtonStyle(
foregroundColors: MultiColor(_colors),
backgroundColors: MultiColor.single(Colors.transparent),
borderColors: MultiColor(_colors),
stroke: 3,
),
- hoveredStyle: FlatButtonStyle(
+ hoveredStyle: const FlatButtonStyle(
foregroundColors: MultiColor.single(Colors.white),
backgroundColors: MultiColor(_colors),
borderColors: MultiColor(_colors),
stroke: 3,
),
- tappedStyle: FlatButtonStyle(
+ tappedStyle: const FlatButtonStyle(
foregroundColors: MultiColor.single(Colors.white),
backgroundColors: MultiColor(_colorsDarken),
borderColors: MultiColor(_colorsDarken),
stroke: 3,
),
- prefix: Icon(
+ prefix: const Icon(
Icons.arrow_forward_rounded,
),
- suffix: Icon(
+ suffix: const Icon(
Icons.arrow_forward_rounded,
),
),
@@ -169,7 +170,7 @@ class Buttons extends StatelessWidget {
),
const Gap(20),
FlatButton(
- onPressed: () => print('pressed'),
+ onPressed: (state) => print('pressed, from $state'),
label: TextWrapper(
'Démarrer mon projet',
style:
@@ -191,6 +192,72 @@ class Buttons extends StatelessWidget {
backgroundColors: MultiColor.single(Colors.red),
),
),
+ const Gap(20),
+ ColoredBox(
+ color: _background,
+ child: Center(
+ child: Column(
+ children: [
+ const Gap(20),
+ SymbolButton(
+ icon: const Icon(
+ Icons.android,
+ size: 25,
+ ),
+ label: const TextWrapper('Texte'),
+ normalStyle: const SymbolButtonStyle(
+ borderColors: MultiColor(_disabledColors),
+ foregroundColors: MultiColor.single(Colors.white),
+ backgroundColors: MultiColor.single(_disabledBackground),
+ stroke: 1,
+ ),
+ hoveredStyle: const SymbolButtonStyle(
+ borderColors: MultiColor(_disabledColors),
+ foregroundColors: MultiColor.single(Colors.white),
+ backgroundColors: MultiColor.single(_background),
+ stroke: 1,
+ ),
+ selectedStyle: const SymbolButtonStyle(
+ borderColors: MultiColor(_selectedColors),
+ foregroundColors: MultiColor.single(Colors.white),
+ backgroundColors: MultiColor.single(_disabledBackground),
+ stroke: 1,
+ ),
+ )
+ ..bloc.onClickUpIn()
+ ..bloc.freeze(),
+ const Gap(20),
+ SymbolButton(
+ icon: const Icon(
+ Icons.android,
+ size: 25,
+ ),
+ label: const TextWrapper('Texte'),
+ normalStyle: const SymbolButtonStyle(
+ borderColors: MultiColor(_disabledColors),
+ foregroundColors: MultiColor.single(Colors.white),
+ backgroundColors: MultiColor.single(_disabledBackground),
+ stroke: 1,
+ ),
+ hoveredStyle: const SymbolButtonStyle(
+ borderColors: MultiColor(_disabledColors),
+ foregroundColors: MultiColor.single(Colors.white),
+ backgroundColors: MultiColor.single(_background),
+ stroke: 1,
+ ),
+ selectedStyle: const SymbolButtonStyle(
+ borderColors: MultiColor(_selectedColors),
+ foregroundColors: MultiColor.single(Colors.white),
+ backgroundColors: MultiColor.single(_disabledBackground),
+ stroke: 1,
+ ),
+ )..bloc.freeze(),
+ const Gap(20),
+ ],
+ ),
+ ),
+ ),
+ const Gap(20),
],
);
}
diff --git a/packages/wyatt_ui_kit/lib/src/components/buttons/buttons.dart b/packages/wyatt_ui_kit/lib/src/components/buttons/buttons.dart
index 654c0f72..c8bab7cb 100644
--- a/packages/wyatt_ui_kit/lib/src/components/buttons/buttons.dart
+++ b/packages/wyatt_ui_kit/lib/src/components/buttons/buttons.dart
@@ -15,3 +15,4 @@
// along with this program. If not, see .
export './flat_button/flat_button.dart';
+export './symbol_button/symbol_button.dart';
diff --git a/packages/wyatt_ui_kit/lib/src/components/buttons/cubit/button_cubit.dart b/packages/wyatt_ui_kit/lib/src/components/buttons/cubit/button_cubit.dart
index 1af53d3c..d317a181 100644
--- a/packages/wyatt_ui_kit/lib/src/components/buttons/cubit/button_cubit.dart
+++ b/packages/wyatt_ui_kit/lib/src/components/buttons/cubit/button_cubit.dart
@@ -1,65 +1,99 @@
+// 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 .
+
import 'dart:async';
+import 'package:equatable/equatable.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart';
-class ButtonCubit extends Cubit {
- ButtonCubit() : super(ControlState.normal);
+part 'button_state.dart';
+
+class ButtonCubit extends Cubit {
+ ButtonCubit() : super(const ButtonState.initial(ControlState.normal));
FutureOr onMouseEnter() async {
- if (state == ControlState.disabled) {
+ if (state.isDisabled || state.isFreezed) {
return;
}
- emit(ControlState.hovered);
+ emit(state.copyWith(state: ControlState.hovered));
}
FutureOr onMouseLeave() async {
- if (state == ControlState.disabled) {
+ if (state.isDisabled || state.isFreezed) {
return;
}
- emit(ControlState.normal);
+
+ emit(state.copyWith(state: ControlState.normal));
}
FutureOr onFocus() async {
- if (state == ControlState.disabled) {
+ if (state.isDisabled || state.isFreezed) {
return;
}
- emit(ControlState.focused);
+ emit(state.copyWith(state: ControlState.focused));
}
FutureOr onUnfocus() async {
- if (state == ControlState.disabled) {
+ if (state.isDisabled || state.isFreezed) {
return;
}
- emit(ControlState.normal);
+ emit(state.copyWith(state: ControlState.normal));
}
FutureOr onClickDown() async {
- if (state == ControlState.disabled) {
+ if (state.isDisabled || state.isFreezed) {
return;
}
- emit(ControlState.tapped);
+ emit(state.copyWith(state: ControlState.tapped));
}
FutureOr onClickUpIn() async {
- if (state == ControlState.disabled) {
+ if (state.isDisabled) {
return;
}
- emit(ControlState.hovered);
+ emit(state.copyWith(state: ControlState.hovered));
}
FutureOr onClickUpOut() async {
- if (state == ControlState.disabled) {
+ if (state.isDisabled) {
return;
}
- emit(ControlState.normal);
+ emit(state.copyWith(state: ControlState.normal));
}
FutureOr disable() async {
- emit(ControlState.disabled);
+ if (state.isFreezed) {
+ return;
+ }
+ emit(state.copyWith(state: ControlState.disabled));
}
FutureOr enable() async {
- emit(ControlState.normal);
+ if (state.isFreezed) {
+ return;
+ }
+ emit(state.copyWith(state: ControlState.normal));
+ }
+
+ FutureOr freeze() async {
+ emit(state.copyWith(freezed: true));
+ }
+
+ FutureOr unfreeze() async {
+ emit(state.copyWith(freezed: false));
}
}
diff --git a/packages/wyatt_ui_kit/lib/src/components/buttons/cubit/button_state.dart b/packages/wyatt_ui_kit/lib/src/components/buttons/cubit/button_state.dart
new file mode 100644
index 00000000..1d2e5350
--- /dev/null
+++ b/packages/wyatt_ui_kit/lib/src/components/buttons/cubit/button_state.dart
@@ -0,0 +1,71 @@
+// ignore_for_file: public_member_api_docs, sort_constructors_first
+// 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 .
+
+part of 'button_cubit.dart';
+
+class ButtonState extends Equatable {
+ const ButtonState({
+ required this.state,
+ required this.selected,
+ required this.invalid,
+ required this.freezed,
+ });
+
+ const ButtonState.initial(this.state)
+ : selected = false,
+ invalid = false,
+ freezed = false;
+
+ final ControlState state;
+
+ // Not in control state, because a button state can be
+ // a control state + extra state
+ // e.g : hover + invalid, or selected + tapped
+ final bool selected;
+ final bool invalid;
+ final bool freezed;
+
+ bool get isDisabled => state.isDisabled();
+ bool get isEnabled => state.isEnabled();
+ bool get isFocused => state.isFocused();
+ bool get isHovered => state.isHovered();
+ bool get isTapped => state.isTapped();
+
+ // only for consistence
+ bool get isSelected => selected;
+ bool get isInvalid => invalid;
+ bool get isFreezed => freezed;
+
+ @override
+ List