refactor(ui)!: remove bloc export in buttons to be state management solution agnostic (closes #147)
This commit is contained in:
@@ -15,14 +15,23 @@
|
||||
// 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';
|
||||
import 'package:wyatt_ui_kit_example/theme/constants.dart';
|
||||
|
||||
class SymbolButtons extends StatelessWidget {
|
||||
class SymbolButtons extends StatefulWidget {
|
||||
const SymbolButtons({super.key});
|
||||
|
||||
@override
|
||||
State<SymbolButtons> createState() => _SymbolButtonsState();
|
||||
}
|
||||
|
||||
class _SymbolButtonsState extends State<SymbolButtons> {
|
||||
final _disabled = ValueNotifier(true);
|
||||
final _dynamic = ValueNotifier(false);
|
||||
|
||||
Icon _icon(BuildContext context) => Icon(
|
||||
Icons.android,
|
||||
size: 25,
|
||||
@@ -45,47 +54,70 @@ class SymbolButtons extends StatelessWidget {
|
||||
icon: _icon(context),
|
||||
),
|
||||
const Gap(20),
|
||||
SymbolButton(
|
||||
label: const TextWrapper('Enabled'),
|
||||
icon: _icon(context),
|
||||
)
|
||||
..bloc.enable()
|
||||
..bloc.freeze(),
|
||||
BlocProvider(
|
||||
create: (context) => SelectableButtonCubit()..freeze(),
|
||||
child: SymbolButton(
|
||||
label: const TextWrapper('Enabled'),
|
||||
icon: _icon(context),
|
||||
),
|
||||
),
|
||||
const Gap(20),
|
||||
// Disabled
|
||||
SymbolButton(
|
||||
label: const TextWrapper('Disabled'),
|
||||
icon: _icon(context),
|
||||
)
|
||||
..bloc.disable()
|
||||
..bloc.freeze(),
|
||||
disabled: _disabled,
|
||||
),
|
||||
const Gap(20),
|
||||
SymbolButton(
|
||||
label: const TextWrapper('Hovered'),
|
||||
icon: _icon(context),
|
||||
)
|
||||
..bloc.onMouseEnter()
|
||||
..bloc.freeze(),
|
||||
BlocProvider(
|
||||
create: (context) => SelectableButtonCubit()..hover(),
|
||||
child: SymbolButton(
|
||||
label: const TextWrapper('Hovered'),
|
||||
icon: _icon(context),
|
||||
),
|
||||
),
|
||||
const Gap(20),
|
||||
SymbolButton(
|
||||
label: const TextWrapper('Focused'),
|
||||
icon: _icon(context),
|
||||
)
|
||||
..bloc.onFocus()
|
||||
..bloc.freeze(),
|
||||
BlocProvider(
|
||||
create: (context) => SelectableButtonCubit()..focus(),
|
||||
child: SymbolButton(
|
||||
label: const TextWrapper('Focused'),
|
||||
icon: _icon(context),
|
||||
),
|
||||
),
|
||||
const Gap(20),
|
||||
SymbolButton(
|
||||
label: const TextWrapper('Tapped'),
|
||||
icon: _icon(context),
|
||||
)
|
||||
..bloc.onClickDown()
|
||||
..bloc.freeze(),
|
||||
BlocProvider(
|
||||
create: (context) => SelectableButtonCubit()..tap(),
|
||||
child: SymbolButton(
|
||||
label: const TextWrapper('Tapped'),
|
||||
icon: _icon(context),
|
||||
),
|
||||
),
|
||||
const Gap(20),
|
||||
SymbolButton(
|
||||
label: const TextWrapper('Selected'),
|
||||
icon: _icon(context),
|
||||
)
|
||||
..bloc.select()
|
||||
..bloc.freeze(),
|
||||
BlocProvider(
|
||||
create: (context) => SelectableButtonCubit()..select(),
|
||||
child: SymbolButton(
|
||||
label: const TextWrapper('Selected'),
|
||||
icon: _icon(context),
|
||||
),
|
||||
),
|
||||
const Gap(20),
|
||||
Row(
|
||||
children: [
|
||||
Checkbox(
|
||||
value: !_dynamic.value,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_dynamic.value = !_dynamic.value;
|
||||
});
|
||||
},
|
||||
),
|
||||
SymbolButton(
|
||||
label: const TextWrapper('Dynamic'),
|
||||
icon: _icon(context),
|
||||
disabled: _dynamic,
|
||||
),
|
||||
],
|
||||
),
|
||||
const Gap(20),
|
||||
DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
|
||||
Reference in New Issue
Block a user