refactor(ui)!: remove bloc export in buttons to be state management solution agnostic (closes #147)

This commit is contained in:
2023-02-23 16:59:56 +01:00
parent d6c9dfd8a7
commit 6c54689393
32 changed files with 673 additions and 342 deletions
@@ -15,13 +15,22 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.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';
class FlatButtons extends StatelessWidget {
class FlatButtons extends StatefulWidget {
const FlatButtons({super.key});
@override
State<FlatButtons> createState() => _FlatButtonsState();
}
class _FlatButtonsState extends State<FlatButtons> {
final _disabled = ValueNotifier(true);
final _dynamic = ValueNotifier(false);
@override
Widget build(BuildContext context) => Column(
children: [
@@ -30,56 +39,80 @@ class FlatButtons extends StatelessWidget {
style: Theme.of(context).textTheme.titleMedium,
),
const Gap(20),
Center(
// Default
const 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(
label: const TextWrapper(
label: TextWrapper(
'Voir notre savoir faire',
),
),
),
const Gap(20),
Center(
child: FlatButton(
label: const TextWrapper('Enabled'),
)
..bloc.enable()
..bloc.freeze(),
child: BlocProvider(
create: (context) => ButtonCubit()..freeze(),
child: const FlatButton(
label: TextWrapper('Enabled'),
),
),
),
const Gap(20),
// Disabled with ValueNotifier
Center(
child: FlatButton(
label: const TextWrapper('Disabled'),
)
..bloc.disable()
..bloc.freeze(),
disabled: _disabled,
),
),
const Gap(20),
Center(
child: FlatButton(
label: const TextWrapper('Hovered'),
)
..bloc.onMouseEnter()
..bloc.freeze(),
child: BlocProvider(
create: (context) => ButtonCubit()..hover(),
child: const FlatButton(
label: TextWrapper('Hovered'),
),
),
),
const Gap(20),
Center(
child: FlatButton(
label: const TextWrapper('Focused'),
)
..bloc.onFocus()
..bloc.freeze(),
child: BlocProvider(
create: (context) => ButtonCubit()..focus(),
child: const FlatButton(
label: TextWrapper('Focused'),
),
),
),
const Gap(20),
Center(
child: FlatButton(
label: const TextWrapper('Tapped'),
)
..bloc.onClickDown()
..bloc.freeze(),
child: BlocProvider(
create: (context) => ButtonCubit()..tap(),
child: const FlatButton(
label: TextWrapper('Tapped'),
),
),
),
const Gap(20),
// Dynamic, disabled with ValueNotifier and
// keep the state when the button is disabled
Row(
children: [
Checkbox(
value: !_dynamic.value,
onChanged: (value) {
setState(() {
_dynamic.value = !_dynamic.value;
});
},
),
FlatButton(
label: const TextWrapper('Dynamic'),
disabled: _dynamic,
),
],
),
const Gap(20),
],