Skip to content

Commit

Permalink
Component ZetaSwitch (#6)
Browse files Browse the repository at this point in the history
* create ZetaSwitch

* ZetaSwitch using MaterialSwitch

* widgetbook for ZetaSwitch

* remove hover; fix initState

* add showHover parameter

* add comments 'Zeta change' in material_switch.dart

* remove size parameter and factory constructors

* fix example and widgetbook
  • Loading branch information
atanasyordanov21 authored and thelukewalton committed Apr 12, 2024
1 parent 5329362 commit 9c57528
Show file tree
Hide file tree
Showing 7 changed files with 1,284 additions and 0 deletions.
2 changes: 2 additions & 0 deletions example/lib/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:zeta_example/pages/components/dialpad_example.dart';
import 'package:zeta_example/pages/components/dropdown_example.dart';
import 'package:zeta_example/pages/components/list_item_example.dart';
import 'package:zeta_example/pages/components/navigation_bar_example.dart';
import 'package:zeta_example/pages/components/switch_example.dart';
import 'package:zeta_example/pages/theme/color_example.dart';
import 'package:zeta_example/pages/components/password_input_example.dart';
import 'package:zeta_example/pages/components/progress_example.dart';
Expand Down Expand Up @@ -46,6 +47,7 @@ final List<Component> components = [
Component(DropdownExample.name, (context) => const DropdownExample()),
Component(ProgressExample.name, (context) => const ProgressExample()),
Component(DialPadExample.name, (context) => const DialPadExample()),
Component(SwitchExample.name, (context) => const SwitchExample()),
];

final List<Component> theme = [
Expand Down
45 changes: 45 additions & 0 deletions example/lib/pages/components/switch_example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import 'package:flutter/material.dart';
import 'package:zeta_example/widgets.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

class SwitchExample extends StatefulWidget {
static const String name = 'Switch';

const SwitchExample({Key? key}) : super(key: key);

@override
State<SwitchExample> createState() => _SwitchExampleState();
}

class _SwitchExampleState extends State<SwitchExample> {
bool? isOn = false;
bool isEnabled = true;

@override
Widget build(BuildContext context) {
return ExampleScaffold(
name: 'Switch',
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ZetaSwitch(
value: isOn,
onChanged: isEnabled ? (value) => setState(() => isOn = value) : null,
),
ZetaButton(
label: isEnabled ? 'Disable' : 'Enable',
onPressed: () => setState(() => isEnabled = !isEnabled),
),
],
),
],
),
),
);
}
}
2 changes: 2 additions & 0 deletions example/widgetbook/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import 'pages/components/list_item_widgetbook.dart';
import 'pages/components/navigation_bar_widgetbook.dart';
import 'pages/components/password_input_widgetbook.dart';
import 'pages/components/progress_widgetbook.dart';
import 'pages/components/switch_widgetbook.dart';
import 'pages/theme/color_widgetbook.dart';
import 'pages/theme/radius_widgetbook.dart';
import 'pages/theme/spacing_widgetbook.dart';
Expand Down Expand Up @@ -88,6 +89,7 @@ class HotReload extends StatelessWidget {
WidgetbookUseCase(name: 'Circle', builder: (context) => progressCircleUseCase(context))
],
),
WidgetbookUseCase(name: 'Switch', builder: (context) => switchUseCase(context)),
]..sort((a, b) => a.name.compareTo(b.name)),
),
WidgetbookCategory(
Expand Down
32 changes: 32 additions & 0 deletions example/widgetbook/pages/components/switch_widgetbook.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:flutter/material.dart';
import 'package:widgetbook/widgetbook.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

import '../../test/test_components.dart';

Widget switchUseCase(BuildContext context) {
bool? isOn = false;

return WidgetbookTestWidget(
widget: StatefulBuilder(
builder: (context, setState) {
ValueChanged<bool?>? onChanged = context.knobs.boolean(label: 'Enabled', initialValue: true)
? (value) => setState(() => isOn = value)
: null;
return Padding(
padding: const EdgeInsets.all(ZetaSpacing.x5),
child: Column(
children: [
Text('Switch'),
ZetaSwitch(
value: isOn,
onChanged: onChanged,
),
Text(isOn == true ? 'On' : 'Off'),
],
),
);
},
),
);
}
Loading

0 comments on commit 9c57528

Please sign in to comment.