# flutter_smart_select
**Repository Path**: swjt-hy/flutter_smart_select
## Basic Information
- **Project Name**: flutter_smart_select
- **Description**: SmartSelect allows you to easily convert your usual form select or dropdown into dynamic page, popup dialog, or sliding bottom sheet with various choices input such as radio, checkbox, switch, chips, or even custom input. Supports single and multiple choice.
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2020-12-11
- **Last Updated**: 2020-12-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
 
SmartSelect allows you to easily convert your usual form select or dropdown into dynamic page, popup dialog, or sliding bottom sheet with various choices input such as radio, checkbox, switch, chips, or even custom input. Supports single and multiple choice. Inspired by Smart Select component from [Framework7](https://framework7.io/).
## What's New in Version 4.x.x
- Customizable every part on modal widget (header, footer, searchbar, confirm button, searchbar toggle) using style configuration or widget builder
- Validate before confirm
- Auto search on type
- Accent marks handler on search
- Highlight search result
- Chips tile widget
- Grid choice layout
- Horizotal or vertical choice list scroll direction
- Simplify class name and enum
- Configurations supports `copyWith` and `merge`
- Use `StatefulWidget` as state management
- Easy shortcut to define configuration
- Soft depends to other package
## To Do
- Right-To-Left parameter support, currently this can be achieved using widget builder
- Internally handle async choice items loader
- Custom search handler
- Choice items pagination (pull to refresh and pull to load more)
- Add more test
## Migration from 4.0.0 to 4.2.0
- `modalValidation` function nows should return `String` to indicates the changes value is not valid and `null` or empty `String` to indicates the changes value is valid
- To display tile with chips use param `S2Tile.body` and `S2TileChips`, instead of `S2ChipsTile`
## Migration from 3.0.x to 4.0.0
- The parameter `options` is removed, instead use `choiceItems`
- Simplify class name and enum
- `SmartSelectTile` to `S2Tile`
- `SmartSelectOption` to `S2Choice`
- `SmartSelectChoiceConfig` to `S2ChoiceConfig`
- `SmartSelectChoiceStyle` to `S2ChoiceStyle`
- `SmartSelectChoiceType` to `S2ChoiceType`
- `SmartSelectModalConfig` to `S2ModalConfig`
- `SmartSelectModalStyle` to `S2ModalStyle`
- `SmartSelectModalHeaderStyle` to `S2ModalHeaderStyle`
- `SmartSelectModalType` to `S2ModalType`
- The parameter `builder` now is a collection of builder (`S2SingleBuilder` or `S2MultiBuilder`), instead use `tileBuilder` to create trigger tile widget.
- The parameters `dense`, `enabled`, `isLoading`, `isTwoLine`, `leading`, `loadingText`, `padding`, `selected`, `trailing` is removed from `SmartSelect` class, instead use `builder.tile` or `tileBuilder` and return `S2Tile` widget, it's has all these parameters.
- The parameter `onChange` nows return `S2SingleState state` or `S2MultiState state` instead of `T value` or `List value`
- The parameter `choiceConfig.useWrap` is removed, instead use `choiceConfig.layout = S2ChoiceLayout.wrap`
- The parameter `choiceConfig.builder` moved to `builder.choice` or `choiceBuilder`
- The parameter `choiceConfig.titleBuilder` moved to `builder.choiceTitle` or `choiceTitleBuilder`
- The parameter `choiceConfig.subtitleBuilder` moved to `builder.choiceSubtitle` or `choiceSubtitleBuilder`
- The parameter `choiceConfig.secondaryBuilder` moved to `builder.choiceSecondary` or `choiceSecondaryBuilder`
- The parameter `choiceConfig.dividerBuilder` moved to `builder.choiceDivider` or `choiceDividerBuilder`
- The parameter `choiceConfig.emptyBuilder` moved to `builder.choiceEmpty` or `choiceEmptybuilder`
- The parameter `choiceConfig.glowingOverscrollIndicatorColor` is removed, instead use `choiceConfig.overscrollColor`
- The parameter `choiceConfig.spacing` and `choiceConfig.runSpacing` moved to `choiceConfig.style.spacing` and `choiceConfig.style.runSpacing`
- The parameter `choiceConfig.useCheckmark` moved to `choiceConfig.style.showCheckmark`
- The parameter `choiceConfig.padding` moved to `choiceConfig.style.wrapperPadding`
- The default of grouped choice is not using sticky header now, instead use `groupBuilder` like this:
```dart
dependencies:
sticky_headers: "^0.1.8"
```
```dart
import 'package:sticky_headers/sticky_headers.dart';
SmartSelect.single/multiple(
...,
...,
choiceGroupBuilder: (context, header, choices) {
return StickyHeader(
header: header,
content: choices,
);
},
);
```
# Preview
|
Single Choice |
Multiple Choice |
| Modal Type |
|
|
| Chips Widget |
|
|
| Switch Widget |
None
|
|
| Custom Tile |
|
| Modal Filter |
|
| Modal Confirm |
|
| Modal Validation |
|
| Modal Selector |
|
| Modal Shape |
|
| Choice Items |
|
| Choice Grouped |
|
| Choice Builder |
|
| Download APK |
|
# Features
* Select single or multiple choice
* Open choices modal in full page, bottom sheet, or popup dialog
* Various choices input (radio, checkbox, switch, chips, or custom widget)
* Various choices layout (list, wrap, or grid)
* Grouping choices with easy support to sticky header
* Searchable choices with highlighted result
* Disabled or hidden choices
* Customizable trigger/tile widget
* Customizable modal style
* Customizable modal header style
* Customizable modal footer
* Customizable choices style
* Build choice items from any `List`
* Easy load async choice items
* and many more
# Usage
For a complete usage, please see the [example](https://pub.dev/packages/smart_select#-example-tab-).
To read more about classes and other references used by `smart_select`, see the [API Reference](https://pub.dev/documentation/smart_select/latest/).
## Single Choice
```dart
// available configuration for single choice
SmartSelect.single({
// The primary content of the widget.
// Used in trigger widget and header option
String title,
// The text displayed when the value is null
String placeholder = 'Select one',
// The current value of the single choice widget.
@required T value,
// Called when single choice value changed
@required ValueChanged> onChange,
// choice item list
List> choiceItems,
// other available configuration
// explained below
...,
...,
})
```
```dart
// simple usage
String value = 'flutter';
List> options = [
S2Choice(value: 'ion', title: 'Ionic'),
S2Choice(value: 'flu', title: 'Flutter'),
S2Choice(value: 'rea', title: 'React Native'),
];
@override
Widget build(BuildContext context) {
return SmartSelect.single(
title: 'Frameworks',
value: value,
choiceItems: options,
onChange: (state) => setState(() => value = state.value)
);
}
```
## Multiple Choice
```dart
// available configuration for multiple choice
SmartSelect.multiple({
// The primary content of the widget.
// Used in trigger widget and header option
String title,
// The text displayed when the value is null
String placeholder = 'Select one',
// The current value of the single choice widget.
@required List value,
// Called when single choice value changed
@required ValueChanged> onChange,
// choice item list
List> choiceItems,
// other available configuration
// explained below
...,
...,
})
```
```dart
// a simple usage
List value = [2];
List> frameworks = [
S2Choice(value: 1, title: 'Ionic'),
S2Choice(value: 2, title: 'Flutter'),
S2Choice(value: 3, title: 'React Native'),
];
@override
Widget build(BuildContext context) {
return SmartSelect.multiple(
title: 'Frameworks',
value: value,
choiceItems: options,
onChange: (state) => setState(() => value = state.value),
);
}
```
## Choices
```dart
// configuration
SmartSelect.[single|multiple]({
// other configuration
...,
...,
// choice item list
List> choiceItems,
// other configuration
...,
...,
});
```
`choiceItems` can be input directly as in the example below, more info about `S2Choice` can be found on the [API Reference](https://pub.dev/documentation/smart_select/latest/smart_select/S2Choice-class.html)
```dart
SmartSelect.[single|multiple](
...,
...,
choiceItems: >[
S2Choice(value: 1, title: 'Ionic'),
S2Choice(value: 2, title: 'Flutter'),
S2Choice(value: 3, title: 'React Native'),
],
);
```
`choiceItems` also can be created from any list using helper provided by this package, like the example below
```dart
List