-
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.
* create ZetaSelectInput * add extra parameters; improve * leading icon; error handling in example * _MenuPosition * widgetbook * restore all menu items on each open * fix setState * initialize _menuSize with Size.zero
- Loading branch information
1 parent
6619de3
commit 07ddba1
Showing
6 changed files
with
866 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
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,113 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:zeta_example/widgets.dart'; | ||
import 'package:zeta_flutter/zeta_flutter.dart'; | ||
|
||
class SelectInputExample extends StatefulWidget { | ||
static const String name = 'SelectInput'; | ||
const SelectInputExample({super.key}); | ||
|
||
@override | ||
State<SelectInputExample> createState() => _SelectInputExampleState(); | ||
} | ||
|
||
class _SelectInputExampleState extends State<SelectInputExample> { | ||
String? _errorText; | ||
ZetaSelectInputItem? selectedItem = ZetaSelectInputItem( | ||
value: 'Item 1', | ||
); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final zeta = Zeta.of(context); | ||
|
||
return ExampleScaffold( | ||
name: 'Select Input', | ||
child: Center( | ||
child: SingleChildScrollView( | ||
child: SizedBox( | ||
width: 320, | ||
child: Column( | ||
children: [ | ||
ZetaSelectInput( | ||
label: Row( | ||
children: [ | ||
Text('Label'), | ||
Padding( | ||
padding: const EdgeInsets.only(left: 6), | ||
child: Text( | ||
'*', | ||
style: TextStyle(color: zeta.colors.red.shade60), | ||
), | ||
), | ||
], | ||
), | ||
hint: 'Default hint text', | ||
leadingIcon: Icon(ZetaIcons.star_round), | ||
hasError: _errorText != null, | ||
errorText: _errorText, | ||
onChanged: (item) { | ||
setState(() { | ||
selectedItem = item; | ||
if (item != null) { | ||
_errorText = null; | ||
} | ||
}); | ||
}, | ||
onTextChanged: (value) { | ||
setState(() { | ||
if (value.isEmpty) { | ||
_errorText = 'Required'; | ||
} else { | ||
_errorText = null; | ||
} | ||
}); | ||
}, | ||
selectedItem: selectedItem, | ||
items: [ | ||
ZetaSelectInputItem( | ||
value: 'Item 1', | ||
), | ||
ZetaSelectInputItem( | ||
value: 'Item 2', | ||
), | ||
ZetaSelectInputItem( | ||
value: 'Item 3', | ||
), | ||
ZetaSelectInputItem( | ||
value: 'Item 4', | ||
), | ||
ZetaSelectInputItem( | ||
value: 'Item 5', | ||
), | ||
ZetaSelectInputItem( | ||
value: 'Item 6', | ||
), | ||
ZetaSelectInputItem( | ||
value: 'Item 7', | ||
), | ||
ZetaSelectInputItem( | ||
value: 'Item 8', | ||
), | ||
ZetaSelectInputItem( | ||
value: 'Item 9', | ||
), | ||
ZetaSelectInputItem( | ||
value: 'Item 10', | ||
), | ||
ZetaSelectInputItem( | ||
value: 'Item 11', | ||
), | ||
ZetaSelectInputItem( | ||
value: 'Item 12', | ||
), | ||
], | ||
), | ||
const SizedBox(height: 120), | ||
], | ||
), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
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
99 changes: 99 additions & 0 deletions
99
example/widgetbook/pages/components/select_input_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,99 @@ | ||
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 selectInputUseCase(BuildContext context) { | ||
final zeta = Zeta.of(context); | ||
final items = [ | ||
ZetaSelectInputItem(value: 'Item 1'), | ||
ZetaSelectInputItem(value: 'Item 2'), | ||
ZetaSelectInputItem(value: 'Item 3'), | ||
ZetaSelectInputItem(value: 'Item 4'), | ||
ZetaSelectInputItem(value: 'Item 5'), | ||
ZetaSelectInputItem(value: 'Item 6'), | ||
ZetaSelectInputItem(value: 'Item 7'), | ||
ZetaSelectInputItem(value: 'Item 8'), | ||
ZetaSelectInputItem(value: 'Item 9'), | ||
ZetaSelectInputItem(value: 'Item 10'), | ||
ZetaSelectInputItem(value: 'Item 11'), | ||
ZetaSelectInputItem(value: 'Item 12'), | ||
]; | ||
late ZetaSelectInputItem? selectedItem = items.first; | ||
String? _errorText; | ||
final label = context.knobs.string( | ||
label: 'Label', | ||
initialValue: 'Label', | ||
); | ||
final hint = context.knobs.string( | ||
label: 'Hint', | ||
initialValue: 'Default hint text', | ||
); | ||
final rounded = context.knobs.boolean(label: 'Rounded', initialValue: true); | ||
final enabled = context.knobs.boolean(label: 'Enabled', initialValue: true); | ||
final required = context.knobs.boolean(label: 'Required', initialValue: true); | ||
final size = context.knobs.list<ZetaWidgetSize>( | ||
label: 'Size', | ||
options: ZetaWidgetSize.values, | ||
labelBuilder: (size) => size.name, | ||
); | ||
final iconData = iconKnob( | ||
context, | ||
name: "Icon", | ||
rounded: rounded, | ||
initial: rounded ? ZetaIcons.star_round : ZetaIcons.star_sharp, | ||
); | ||
|
||
return WidgetbookTestWidget( | ||
widget: StatefulBuilder( | ||
builder: (context, setState) { | ||
return Padding( | ||
padding: const EdgeInsets.all(ZetaSpacing.m), | ||
child: ZetaSelectInput( | ||
rounded: rounded, | ||
enabled: enabled, | ||
size: size, | ||
label: Row( | ||
children: [ | ||
Text(label), | ||
if (required) | ||
Padding( | ||
padding: const EdgeInsets.only(left: 6), | ||
child: Text( | ||
'*', | ||
style: TextStyle(color: zeta.colors.red.shade60), | ||
), | ||
), | ||
], | ||
), | ||
hint: hint, | ||
leadingIcon: Icon(iconData), | ||
hasError: _errorText != null, | ||
errorText: _errorText, | ||
onChanged: (item) { | ||
setState(() { | ||
selectedItem = item; | ||
if (item != null) { | ||
_errorText = null; | ||
} | ||
}); | ||
}, | ||
onTextChanged: (value) { | ||
setState(() { | ||
if (required && value.isEmpty) { | ||
_errorText = 'Required'; | ||
} else { | ||
_errorText = null; | ||
} | ||
}); | ||
}, | ||
selectedItem: selectedItem, | ||
items: items, | ||
), | ||
); | ||
}, | ||
), | ||
); | ||
} |
Oops, something went wrong.