Skip to content

Commit

Permalink
feat(main): Segmented control (#26)
Browse files Browse the repository at this point in the history
* feat(main): AppBar

* Add segmented control

* [automated commit] lint format and import sort

* Fix mouse cursor, disable selection container and tap area

* [automated commit] lint format and import sort

---------

Co-authored-by: github-actions <[email protected]>
  • Loading branch information
2 people authored and thelukewalton committed Apr 25, 2024
1 parent 2783212 commit adb93ff
Show file tree
Hide file tree
Showing 6 changed files with 782 additions and 0 deletions.
4 changes: 4 additions & 0 deletions example/lib/home.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:zeta_example/pages/components/accordion_example.dart';
import 'package:zeta_example/pages/components/app_bar_example.dart';
import 'package:zeta_example/pages/components/avatar_example.dart';
import 'package:zeta_example/pages/components/badges_example.dart';
import 'package:zeta_example/pages/components/banner_example.dart';
Expand All @@ -18,6 +19,7 @@ import 'package:zeta_example/pages/components/navigation_bar_example.dart';
import 'package:zeta_example/pages/components/navigation_rail_example.dart';
import 'package:zeta_example/pages/components/phone_input_example.dart';
import 'package:zeta_example/pages/components/radio_example.dart';
import 'package:zeta_example/pages/components/segmented_control_example.dart';
import 'package:zeta_example/pages/components/stepper_example.dart';
import 'package:zeta_example/pages/components/switch_example.dart';
import 'package:zeta_example/pages/components/snackbar_example.dart';
Expand All @@ -43,6 +45,7 @@ class Component {

final List<Component> components = [
Component(AccordionExample.name, (context) => const AccordionExample()),
Component(AppBarExample.name, (context) => const AppBarExample()),
Component(AvatarExample.name, (context) => const AvatarExample()),
Component(BannerExample.name, (context) => const BannerExample()),
Component(BadgesExample.name, (context) => const BadgesExample()),
Expand All @@ -57,6 +60,7 @@ final List<Component> components = [
Component(PasswordInputExample.name, (context) => const PasswordInputExample()),
Component(DropdownExample.name, (context) => const DropdownExample()),
Component(ProgressExample.name, (context) => const ProgressExample()),
Component(SegmentedControlExample.name, (context) => const SegmentedControlExample()),
Component(SnackBarExample.name, (context) => const SnackBarExample()),
Component(StepperExample.name, (context) => const StepperExample()),
Component(TabsExample.name, (context) => const TabsExample()),
Expand Down
87 changes: 87 additions & 0 deletions example/lib/pages/components/segmented_control_example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import 'package:flutter/material.dart';
import 'package:zeta_example/widgets.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

class SegmentedControlExample extends StatefulWidget {
const SegmentedControlExample({super.key});

static const String name = 'SegmentedControl';

@override
State<SegmentedControlExample> createState() => _SegmentedControlExampleState();
}

class _SegmentedControlExampleState extends State<SegmentedControlExample> {
final _iconsSegments = [1, 2, 3, 4, 5];
final _numberSegments = [1, 2, 3, 4, 5];
late int _selectedIconSegment = _iconsSegments.first;
late int _selectedNumberSegment = _numberSegments.first;
late String _selectedTextSegment = _textSegments.first;
final _textSegments = ["Item 1", "Item 2", "Item 3"];

@override
Widget build(BuildContext context) {
return ExampleScaffold(
name: SegmentedControlExample.name,
child: SingleChildScrollView(
child: Column(
children: [
// Text
Padding(
padding: const EdgeInsets.all(ZetaSpacing.l),
child: ZetaSegmentedControl(
segments: [
for (final value in _textSegments)
ZetaButtonSegment(
value: value,
child: Text(value),
),
],
onChanged: (value) => setState(
() => _selectedTextSegment = value,
),
selected: _selectedTextSegment,
),
),

// Numbers
Padding(
padding: const EdgeInsets.all(ZetaSpacing.l),
child: ZetaSegmentedControl(
segments: [
for (final value in _numberSegments)
ZetaButtonSegment(
value: value,
child: Text(value.toString()),
),
],
onChanged: (value) => setState(
() => _selectedNumberSegment = value,
),
selected: _selectedNumberSegment,
),
),

// Icons
Padding(
padding: const EdgeInsets.all(ZetaSpacing.l),
child: ZetaSegmentedControl(
segments: [
for (final value in _iconsSegments)
ZetaButtonSegment(
value: value,
child: Icon(ZetaIcons.star_round),
),
],
onChanged: (value) => setState(
() => _selectedIconSegment = value,
),
selected: _selectedIconSegment,
),
),
],
),
),
);
}
}
5 changes: 5 additions & 0 deletions example/widgetbook/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import 'pages/components/password_input_widgetbook.dart';
import 'pages/components/phone_input_widgetbook.dart';
import 'pages/components/progress_widgetbook.dart';
import 'pages/components/radio_widgetbook.dart';
import 'pages/components/segmented_control_widgetbook.dart';
import 'pages/components/stepper_widgetbook.dart';
import 'pages/components/switch_widgetbook.dart';
import 'pages/components/snack_bar_widgetbook.dart';
Expand Down Expand Up @@ -115,6 +116,10 @@ class HotReload extends StatelessWidget {
],
),
WidgetbookUseCase(name: 'Radio Button', builder: (context) => radioButtonUseCase(context)),
WidgetbookUseCase(
name: 'Segmented Control',
builder: (context) => segmentedControlUseCase(context),
),
WidgetbookUseCase(name: 'Switch', builder: (context) => switchUseCase(context)),
WidgetbookUseCase(
name: 'Snack Bar',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import 'package:flutter/material.dart';
import 'package:widgetbook/widgetbook.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

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

Widget segmentedControlUseCase(BuildContext context) {
final iconsSegments = List.generate(5, (index) => index);
int selectedIconSegment = iconsSegments.first;

final rounded = context.knobs.boolean(label: "Rounded", initialValue: true);
final icon = iconKnob(context, rounded: rounded, initial: ZetaIcons.star_round);

final text = context.knobs.string(label: 'Text', initialValue: "Item");

final textSegments = List.generate(3, (index) => "$text ${index + 1}");
String selectedTextSegment = textSegments.first;

return WidgetbookTestWidget(
widget: StatefulBuilder(builder: (context, setState) {
return Column(
children: [
Padding(
padding: const EdgeInsets.all(ZetaSpacing.l),
child: ZetaSegmentedControl(
rounded: rounded,
segments: [
for (final value in iconsSegments)
ZetaButtonSegment(
value: value,
child: Icon(icon),
),
],
onChanged: (value) => setState(
() => selectedIconSegment = value,
),
selected: selectedIconSegment,
),
),
Padding(
padding: const EdgeInsets.all(ZetaSpacing.l),
child: ZetaSegmentedControl(
rounded: rounded,
segments: [
for (final value in textSegments)
ZetaButtonSegment(
value: value,
child: Text(
value,
),
),
],
onChanged: (value) => setState(
() => selectedTextSegment = value,
),
selected: selectedTextSegment,
),
),
],
);
}),
);
}
Loading

0 comments on commit adb93ff

Please sign in to comment.