Skip to content

Commit ea8a9c5

Browse files
committed
Better documentation and change SmartSelectOptionGroupHeaderTheme titleStyle to textStyle
1 parent 0c6a975 commit ea8a9c5

File tree

11 files changed

+221
-38
lines changed

11 files changed

+221
-38
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## [1.0.3] - 2019-12-12
2+
3+
* Change SmartSelectOptionGroupHeaderTheme titleStyle to textStyle
4+
* Better documentation
5+
16
## [1.0.2] - 2019-12-12
27

38
* Move and rename files for better documentation

README.md

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
Smart select allows you to easily convert your usual form selects to dynamic pages with grouped radio or checkbox inputs. This widget is inspired by Smart Select component from [Framework7](https://framework7.io/).
44

5-
To read more about `smart_select`, see the [documentation](https://pub.dev/documentation/smart_select/latest/).
6-
75
# Features
86

97
* Select single or multiple choice
@@ -14,8 +12,17 @@ To read more about `smart_select`, see the [documentation](https://pub.dev/docum
1412
* Customizable label, value, and group field
1513
* Filterable option item
1614

15+
# TODO
16+
17+
* Use chip as option item
18+
* Support dark mode
19+
1720
# Usage
1821

22+
For a complete usage, please see the [example](https://pub.dev/packages/smart_select#-example-tab-).
23+
24+
To read more about classes and other references used by `smart_select`, see the [documentation](https://pub.dev/documentation/smart_select/latest/).
25+
1926
## Single Choice
2027

2128
```
@@ -193,37 +200,13 @@ Widget build(BuildContext context) {
193200
}
194201
```
195202

196-
# Reference
197-
198-
| Name | Type | Description |
199-
|------|------|-------------|
200-
| SmartSelect | Class | General usage |
201-
| SmartSelectTile | Class | Default trigger widget |
202-
| SmartSelectOption | Class | Configure option |
203-
| SmartSelectState | Class | Current state |
204-
| SmartSelectTarget | Enum | Modal type to open option |
205-
| SmartSelectOnChange | Typedef | Callback to handle change of value widget |
206-
| SmartSelectBuilder | Typedef | Builder for custom trigger widget |
207-
| SmartSelectOptionItemBuilder | Typedef | Builder for custom option item |
208-
| SmartSelectOptionItemOnChange | Typedef | Callback to handle stats of each custom option item |
209-
| SmartSelectOptionDividerBuilder | Typedef | Builder for custom option divider |
210-
| SmartSelectOptionGroupHeaderBuilder | Typedef | Builder for custom option group header |
211-
| SmartSelectOptionConfirmationBuilder | Typedef | Builder for custom confirmation widget |
212-
| SmartSelectOptionHeaderTheme | Class | Configure option header theme |
213-
| SmartSelectOptionItemTheme | Class | Configure option item theme |
214-
| SmartSelectOptionGroupHeaderTheme | Class | Configure option group header theme |
215-
216203
# Thanks
217204

218205
* [Framework7](https://framework7.io/)
219206

220-
# TODO
221-
222-
* Use chip as option item
223-
* Support dark mode
224-
225207
# License
226208

209+
```
227210
Copyright (c) 2019 Irfan Vigma Taufik
228211
229212
Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -242,4 +225,5 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
242225
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
243226
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
244227
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
245-
SOFTWARE.
228+
SOFTWARE.
229+
```

example/README.md

Whitespace-only changes.

example/lib/features_option/option_everything.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class _FeaturesOptionEverythingState extends State<FeaturesOptionEverything> {
5959
),
6060
groupHeaderTheme: SmartSelectOptionGroupHeaderTheme(
6161
backgroundColor: Colors.blueGrey[600],
62-
titleStyle: TextStyle(color: Colors.white)
62+
textStyle: TextStyle(color: Colors.white)
6363
)
6464
),
6565
onChange: (val) => setState(() => _smartphones = val)

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ packages:
127127
path: ".."
128128
relative: true
129129
source: path
130-
version: "1.0.2"
130+
version: "1.0.3"
131131
source_span:
132132
dependency: transitive
133133
description:

lib/src/choices.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,14 @@ class SmartSelectChoicesState extends State<SmartSelectChoices> {
160160
style: Theme.of(context)
161161
.textTheme
162162
.body2
163-
.merge(widget.option.groupHeaderTheme.titleStyle),
163+
.merge(widget.option.groupHeaderTheme.textStyle),
164164
),
165165
Text(
166166
_count.toString(),
167167
style: Theme.of(context)
168168
.textTheme
169169
.body2
170-
.merge(widget.option.groupHeaderTheme.titleStyle),
170+
.merge(widget.option.groupHeaderTheme.textStyle),
171171
),
172172
],
173173
),

lib/src/option.dart

Lines changed: 104 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,94 @@
11
import 'package:flutter/material.dart';
22

3+
/// A builder for custom confirmation widget
34
typedef Widget SmartSelectOptionConfirmationBuilder(
45
BuildContext context, Function onConfirm);
6+
7+
/// A builder for custom option group header widget
58
typedef Widget SmartSelectOptionGroupHeaderBuilder(String _group, int _count);
9+
10+
/// A builder for custom divider widget between option item
611
typedef Widget SmartSelectOptionDividerBuilder(BuildContext context, int index);
12+
13+
/// A builder for custom each option item widget
714
typedef Widget SmartSelectOptionItemBuilder(
815
Map item, bool checked, SmartSelectOptionItemOnChange onChange);
16+
17+
/// Callback to handle change of each custom option item
918
typedef void SmartSelectOptionItemOnChange(dynamic value, bool checked);
1019

20+
/// List of option along with its configuration
1121
class SmartSelectOption {
22+
23+
/// The list of object option items
1224
final List items;
25+
26+
/// Custom property from each option item
27+
/// that represent the label
1328
final String label;
29+
30+
/// Custom property from each option item
31+
/// that represent the value
1432
final String value;
33+
34+
/// Custom property from each option item
35+
/// that used to grouped option items
1536
final String groupBy;
37+
38+
/// Whether show the options list
39+
/// as single choice or multiple choice
1640
final bool isMultiChoice;
41+
42+
/// Whether the options list modal use header or not
1743
final bool useHeader;
44+
45+
/// Whether the option list is filterable or not
1846
final bool useFilter;
19-
final bool useDivider;
47+
48+
/// Whether the option list need to confirm
49+
/// to return the changed value
2050
final bool useConfirmation;
51+
52+
/// Whether the option item use divider or not
53+
final bool useDivider;
54+
55+
/// Modal border shape
56+
/// used in popup dialog and bottom sheet
2157
final ShapeBorder shape;
58+
59+
/// Modal elevation
60+
/// used in popup dialog and bottom sheet
2261
final double elevation;
62+
63+
/// Modal background color
2364
final Color backgroundColor;
65+
66+
/// Custom color of the glowing indicator
67+
/// when overscroll the option list
2468
final Color glowingOverscrollIndicatorColor;
69+
70+
/// Configure option header theme
2571
final SmartSelectOptionHeaderTheme headerTheme;
72+
73+
/// Configure option item theme
2674
final SmartSelectOptionItemTheme itemTheme;
75+
76+
/// Configure option group header theme
2777
final SmartSelectOptionGroupHeaderTheme groupHeaderTheme;
78+
79+
/// Builder for each custom option item
2880
final SmartSelectOptionItemBuilder itemBuilder;
81+
82+
/// Builder for custom divider widget between option item
2983
final SmartSelectOptionDividerBuilder dividerBuilder;
84+
85+
/// Builder for custom confirmation widget
3086
final SmartSelectOptionConfirmationBuilder confirmationBuilder;
87+
88+
/// Builder for custom option group header widget
3189
final SmartSelectOptionGroupHeaderBuilder groupHeaderBuilder;
3290

91+
/// Create list of option along with its configuration
3392
SmartSelectOption(
3493
this.items, {
3594
this.label = 'label',
@@ -53,6 +112,7 @@ class SmartSelectOption {
53112
this.groupHeaderBuilder,
54113
});
55114

115+
/// return a filtered list of options
56116
List filteredList(String _query) {
57117
return _query != null
58118
? items.where((_item) => _filterTest(_item, _query)).toList()
@@ -74,27 +134,48 @@ class SmartSelectOption {
74134
: false;
75135
}
76136

137+
/// return a list of group keys
77138
List groupKeys(List _items) {
78139
Set _groups = Set();
79140
_items.forEach((_item) => _groups.add(_item[groupBy]));
80141
return _groups.toList();
81142
}
82143

144+
/// return a list of group items
83145
List groupItems(List _items, String key) {
84146
return _items.where((_item) => _item[groupBy] == key).toList();
85147
}
86148
}
87149

150+
/// Configure modal option header theme
88151
class SmartSelectOptionHeaderTheme {
152+
153+
/// Header border shape
89154
final ShapeBorder shape;
155+
156+
/// Header elevation
90157
final double elevation;
158+
159+
/// Header background color
91160
final Color backgroundColor;
161+
162+
/// Header brightness
92163
final Brightness brightness;
164+
165+
/// Whether the header title is centered
93166
final bool centerTitle;
167+
168+
/// Header text style
169+
/// used by title and search field
94170
final TextStyle textStyle;
171+
172+
/// Header icon theme
95173
final IconThemeData iconTheme;
174+
175+
/// Header actions icon theme
96176
final IconThemeData actionsIconTheme;
97177

178+
/// Create a configuration of modal option header theme
98179
const SmartSelectOptionHeaderTheme({
99180
this.shape,
100181
this.elevation = 0.5,
@@ -107,12 +188,22 @@ class SmartSelectOptionHeaderTheme {
107188
});
108189
}
109190

191+
/// Configure option item theme
110192
class SmartSelectOptionItemTheme {
193+
194+
/// Checked icon color
111195
final Color checkColor;
196+
197+
/// Checkbox or radio active color
112198
final Color activeColor;
199+
200+
/// Unselected checkbox or radio color
113201
final Color unselectedColor;
202+
203+
/// Option item text style
114204
final TextStyle titleStyle;
115205

206+
/// Create a configuration of option item theme
116207
const SmartSelectOptionItemTheme({
117208
this.checkColor = Colors.white,
118209
this.activeColor = Colors.black54,
@@ -121,15 +212,25 @@ class SmartSelectOptionItemTheme {
121212
});
122213
}
123214

215+
/// Configure option group header theme
124216
class SmartSelectOptionGroupHeaderTheme {
217+
218+
/// Group header background color
125219
final Color backgroundColor;
126-
final TextStyle titleStyle;
220+
221+
/// Group header text style
222+
final TextStyle textStyle;
223+
224+
/// Group header padding
127225
final EdgeInsetsGeometry padding;
226+
227+
/// Group header height
128228
final double height;
129229

230+
/// Create a configuration of option group header theme
130231
const SmartSelectOptionGroupHeaderTheme({
131232
this.backgroundColor = const Color(0xFFECEFF1),
132-
this.titleStyle = const TextStyle(color: Colors.black54),
233+
this.textStyle = const TextStyle(color: Colors.black54),
133234
this.padding = const EdgeInsets.symmetric(horizontal: 16.0),
134235
this.height = 45.0,
135236
});

lib/src/state.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,46 @@
11
import 'package:flutter/material.dart';
22
import './option.dart';
33

4+
/// Target to open option list
45
enum SmartSelectTarget { page, popup, sheet }
6+
7+
/// A function that called when the widget value changed
58
typedef void SmartSelectOnChange(dynamic value);
9+
10+
/// Builder for custom trigger widget
611
typedef Widget SmartSelectBuilder(
712
BuildContext context, SmartSelectState state, Function showOptions);
813

14+
/// Provide an actual state of the SmartSelect
915
class SmartSelectState {
16+
17+
/// The primary content of the widget.
18+
/// Used in trigger widget and header option
1019
final String title;
20+
21+
/// The current value of the widget.
1122
final dynamic value;
23+
24+
/// List of option along with its configuration
1225
final SmartSelectOption option;
26+
27+
/// The text displayed when the value is null
1328
final String placeholder;
1429

30+
/// Create an actual state
1531
SmartSelectState({this.title, this.value, this.option, this.placeholder});
1632

33+
/// return an object or array of object
34+
/// that represent the value
1735
dynamic get valueObject {
1836
return option.isMultiChoice
1937
? option.items.where((x) => value.contains(x[option.value]))
2038
: option.items
2139
.firstWhere((x) => x[option.value] == value, orElse: () => null);
2240
}
2341

42+
/// return a string or array of string
43+
/// that represent the value
2444
dynamic get valueLabel {
2545
return option.isMultiChoice
2646
? valueObject != null && valueObject.length > 0
@@ -29,12 +49,15 @@ class SmartSelectState {
2949
: valueObject != null ? valueObject[option.label] : null;
3050
}
3151

52+
/// return a string that can be used as display
53+
/// when value is null it will display placeholder
3254
String get valueDisplay {
3355
return valueLabel != null
3456
? option.isMultiChoice ? valueLabel.join(', ') : valueLabel
3557
: placeholder ?? placeholderDefault;
3658
}
3759

60+
/// return a string that used as default placeholder
3861
String get placeholderDefault {
3962
return option.isMultiChoice ? 'Select one or more' : 'Select one';
4063
}

0 commit comments

Comments
 (0)