-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
daa93b5
commit 090ffc7
Showing
6 changed files
with
782 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
example/lib/pages/components/segmented_control_example.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
), | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
example/widgetbook/pages/components/segmented_control_widgetbook.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
), | ||
), | ||
], | ||
); | ||
}), | ||
); | ||
} |
Oops, something went wrong.