Skip to content

Commit e0b918d

Browse files
committed
Support disabled and hidden option, etc
1 parent 6478491 commit e0b918d

File tree

18 files changed

+550
-309
lines changed

18 files changed

+550
-309
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## [3.0.2] - 2020-01-22
2+
3+
* Support disabled and hidden option
4+
* Customizable choices wrapper padding
5+
* Single choice chips now use checkmark by default, can be configure by `choiceConfig.useCheckmark`
6+
* Improve documentation
7+
* Update example
8+
19
## [3.0.0] - 2020-01-22
210

311
* Breaking changes, more type safety, add more features, and simplify few properties

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Smart select allows you to easily convert your usual form selects into dynamic p
3535

3636
For a complete usage, please see the [example](https://pub.dev/packages/smart_select#-example-tab-).
3737

38-
To read more about classes and other references used by `smart_select`, see the [documentation](https://pub.dev/documentation/smart_select/latest/).
38+
To read more about classes and other references used by `smart_select`, see the [API Reference](https://pub.dev/documentation/smart_select/latest/).
3939

4040
## Single Choice
4141

@@ -85,10 +85,10 @@ Widget build(BuildContext context) {
8585

8686
## Build Option List
8787

88-
`options` property is `List<SmartSelectOption<T>>`, it can be input directly as in the example below
88+
`options` property is `List<SmartSelectOption<T>>`, it can be input directly as in the example below, more info about `SmartSelectOption` can be found on the [API Reference](https://pub.dev/documentation/smart_select/latest/smart_select/SmartSelectOption-class.html)
8989

9090
```
91-
SmartSelect.single/multiple(
91+
SmartSelect<T>.single/multiple(
9292
...,
9393
...,
9494
options: <SmartSelectOption<int>>[
@@ -99,7 +99,7 @@ SmartSelect.single/multiple(
9999
);
100100
```
101101

102-
or it can be created from any list using helper provided by this package, like the example below
102+
`options` also can be created from any list using helper provided by this package, like the example below
103103

104104
```
105105
List<Map<String, String>> days = [
@@ -112,7 +112,7 @@ List<Map<String, String>> days = [
112112
{ 'value': 'sun', 'title': 'Sunday' },
113113
];
114114
115-
SmartSelect.single/multiple(
115+
SmartSelect<T>.single/multiple(
116116
...,
117117
...,
118118
options: SmartSelectOption.listFrom<Map<String, String>, String>(
@@ -128,7 +128,7 @@ SmartSelect.single/multiple(
128128
By default SmartSelect will open choices modal in full page. You can change it by changing the `modalType` property with this value:
129129

130130
```
131-
SmartSelect.single/multiple(
131+
SmartSelect<T>.single/multiple(
132132
...,
133133
...,
134134
// open in full page
@@ -145,7 +145,7 @@ SmartSelect.single/multiple(
145145
By default SmartSelect will use radio for single choice and checkbox for multiple choice, but it can change by changing the `choiceType` with this value:
146146

147147
```
148-
SmartSelect.single(
148+
SmartSelect<T>.single(
149149
...,
150150
...,
151151
// default use radio
@@ -155,7 +155,7 @@ SmartSelect.single(
155155
);
156156
```
157157
```
158-
SmartSelect.multiple(
158+
SmartSelect<T>.multiple(
159159
...,
160160
...,
161161
// default use checkbox

example/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@
3737

3838
## Customize Option
3939

40-
* [List of Map](https://github.com/davigmacode/flutter_smart_select/blob/master/example/lib/features_option/option_list_of_map.dart)
41-
* [List of String](https://github.com/davigmacode/flutter_smart_select/blob/master/example/lib/features_option/option_list_of_string.dart)
42-
* [List of List Of String](https://github.com/davigmacode/flutter_smart_select/blob/master/example/lib/features_option/option_list_of_list.dart)
43-
* [Async Option & Custom Properties](https://github.com/davigmacode/flutter_smart_select/blob/master/example/lib/features_option/option_async.dart)
40+
* [Disabled Options](https://github.com/davigmacode/flutter_smart_select/blob/master/example/lib/features_option/option_disabled.dart)
41+
* [Hidden Options](https://github.com/davigmacode/flutter_smart_select/blob/master/example/lib/features_option/option_hidden.dart)
42+
* [Build Options from List of String](https://github.com/davigmacode/flutter_smart_select/blob/master/example/lib/features_option/option_list_of_string.dart)
43+
* [Build Options from List of Map](https://github.com/davigmacode/flutter_smart_select/blob/master/example/lib/features_option/option_list_of_map.dart)
44+
* [Build Options from List of List Of String](https://github.com/davigmacode/flutter_smart_select/blob/master/example/lib/features_option/option_list_of_list.dart)
45+
* [Async Option](https://github.com/davigmacode/flutter_smart_select/blob/master/example/lib/features_option/option_async.dart)
4446

4547
## Customize Modal
4648

example/art/demo/SmartSelect.apk

-9.1 KB
Binary file not shown.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:smart_select/smart_select.dart';
3+
4+
class FeaturesOptionDisabled extends StatefulWidget {
5+
@override
6+
_FeaturesOptionDisabledState createState() => _FeaturesOptionDisabledState();
7+
}
8+
9+
class _FeaturesOptionDisabledState extends State<FeaturesOptionDisabled> {
10+
11+
List _categories = [];
12+
13+
int _sort = 0;
14+
15+
List<String> _categoriesOption = [
16+
'Electronics', 'Accessories', 'Smartwatch',
17+
'Smartphone', 'Audio & Video', 'Scientific'
18+
];
19+
20+
List<String> _sortOption = [
21+
'Popular', 'Most Reviews', 'Newest',
22+
'Low Price', 'High Price',
23+
];
24+
25+
@override
26+
Widget build(BuildContext context) {
27+
return Column(
28+
children: <Widget>[
29+
Container(height: 7),
30+
Card(
31+
elevation: 3,
32+
margin: EdgeInsets.all(10),
33+
shape: RoundedRectangleBorder(
34+
borderRadius: BorderRadius.circular(5.0),
35+
),
36+
child: Row(
37+
children: <Widget>[
38+
Expanded(
39+
child: SmartSelect.multiple(
40+
title: 'Categories',
41+
value: _categories,
42+
isTwoLine: true,
43+
trailing: Icon(Icons.arrow_drop_down),
44+
options: SmartSelectOption.listFrom<String, int>(
45+
source: _categoriesOption,
46+
value: (index, item) => index,
47+
title: (index, item) => item,
48+
disabled: (index, item) => [0, 2, 5].contains(index),
49+
),
50+
choiceType: SmartSelectChoiceType.switches,
51+
modalType: SmartSelectModalType.popupDialog,
52+
modalConfig: SmartSelectModalConfig(
53+
useHeader: false,
54+
),
55+
onChange: (val) => setState(() => _categories = val),
56+
),
57+
),
58+
Container(
59+
height: 40,
60+
child: VerticalDivider(),
61+
),
62+
Expanded(
63+
child: SmartSelect.single(
64+
title: 'Sort By',
65+
value: _sort,
66+
isTwoLine: true,
67+
trailing: Icon(Icons.arrow_drop_down),
68+
options: SmartSelectOption.listFrom<String, int>(
69+
source: _sortOption,
70+
value: (index, item) => index,
71+
title: (index, item) => item,
72+
disabled: (index, item) => item.toLowerCase().contains('price'),
73+
),
74+
modalType: SmartSelectModalType.popupDialog,
75+
modalConfig: SmartSelectModalConfig(
76+
useHeader: false,
77+
),
78+
onChange: (val) => setState(() => _sort = val),
79+
),
80+
),
81+
],
82+
),
83+
),
84+
Container(height: 7),
85+
],
86+
);
87+
}
88+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:smart_select/smart_select.dart';
3+
4+
class FeaturesOptionHidden extends StatefulWidget {
5+
@override
6+
_FeaturesOptionHiddenState createState() => _FeaturesOptionHiddenState();
7+
}
8+
9+
class _FeaturesOptionHiddenState extends State<FeaturesOptionHidden> {
10+
11+
List _categories = [];
12+
13+
int _sort = 0;
14+
15+
List<String> _categoriesOption = [
16+
'Electronics', 'Accessories', 'Smartwatch',
17+
'Smartphone', 'Audio & Video', 'Scientific'
18+
];
19+
20+
List<String> _sortOption = [
21+
'Popular', 'Most Reviews', 'Newest',
22+
'Low Price', 'High Price',
23+
];
24+
25+
@override
26+
Widget build(BuildContext context) {
27+
return Column(
28+
children: <Widget>[
29+
Container(height: 7),
30+
Card(
31+
elevation: 3,
32+
margin: EdgeInsets.all(10),
33+
shape: RoundedRectangleBorder(
34+
borderRadius: BorderRadius.circular(5.0),
35+
),
36+
child: Row(
37+
children: <Widget>[
38+
Expanded(
39+
child: SmartSelect.multiple(
40+
title: 'Categories',
41+
value: _categories,
42+
isTwoLine: true,
43+
trailing: Icon(Icons.arrow_drop_down),
44+
options: SmartSelectOption.listFrom<String, int>(
45+
source: _categoriesOption,
46+
value: (index, item) => index,
47+
title: (index, item) => item,
48+
hidden: (index, item) => [0, 2, 5].contains(index),
49+
),
50+
choiceType: SmartSelectChoiceType.switches,
51+
modalType: SmartSelectModalType.popupDialog,
52+
modalConfig: SmartSelectModalConfig(
53+
useHeader: false,
54+
),
55+
onChange: (val) => setState(() => _categories = val),
56+
),
57+
),
58+
Container(
59+
height: 40,
60+
child: VerticalDivider(),
61+
),
62+
Expanded(
63+
child: SmartSelect.single(
64+
title: 'Sort By',
65+
value: _sort,
66+
isTwoLine: true,
67+
trailing: Icon(Icons.arrow_drop_down),
68+
options: SmartSelectOption.listFrom<String, int>(
69+
source: _sortOption,
70+
value: (index, item) => index,
71+
title: (index, item) => item,
72+
hidden: (index, item) => item.toLowerCase().contains('price'),
73+
),
74+
modalType: SmartSelectModalType.popupDialog,
75+
modalConfig: SmartSelectModalConfig(
76+
useHeader: false,
77+
),
78+
onChange: (val) => setState(() => _sort = val),
79+
),
80+
),
81+
],
82+
),
83+
),
84+
Container(height: 7),
85+
],
86+
);
87+
}
88+
}

example/lib/features_option/option_main.dart

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import 'package:flutter/material.dart';
22
import 'package:sticky_headers/sticky_headers.dart';
3-
import './option_list_of_map.dart';
3+
import './option_disabled.dart';
4+
import './option_hidden.dart';
45
import './option_list_of_string.dart';
6+
import './option_list_of_map.dart';
57
import './option_list_of_list.dart';
68
import './option_async.dart';
79
import '../features_header.dart';
@@ -23,19 +25,27 @@ class _FeaturesOptionState extends State<FeaturesOption> with AutomaticKeepAlive
2325
child: ListView(
2426
children: <Widget>[
2527
StickyHeader(
26-
header: FeaturesHeader('Build Options from List of Map'),
27-
content: FeaturesOptionListOfMap(),
28+
header: FeaturesHeader('Disabled Options'),
29+
content: FeaturesOptionDisabled(),
30+
),
31+
StickyHeader(
32+
header: FeaturesHeader('Hidden Options'),
33+
content: FeaturesOptionHidden(),
2834
),
2935
StickyHeader(
3036
header: FeaturesHeader('Build Options from List of String'),
3137
content: FeaturesOptionListOfString(),
3238
),
39+
StickyHeader(
40+
header: FeaturesHeader('Build Options from List of Map'),
41+
content: FeaturesOptionListOfMap(),
42+
),
3343
StickyHeader(
3444
header: FeaturesHeader('Build Options from List of List'),
3545
content: FeaturesOptionListOfList(),
3646
),
3747
StickyHeader(
38-
header: FeaturesHeader('Async Options & Custom Properties'),
48+
header: FeaturesHeader('Async Options'),
3949
content: FeaturesOptionAsync(),
4050
),
4151
],

0 commit comments

Comments
 (0)