Skip to content

Commit 0f37ba4

Browse files
committed
Fix bug when value is null for multiple choice
1 parent 1e11ddf commit 0f37ba4

File tree

19 files changed

+170
-36
lines changed

19 files changed

+170
-36
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## [2.0.1] - 2019-12-21
2+
3+
* fix bug when value is null for multiple choice
4+
* update demo and add video preview example
5+
16
## [2.0.0] - 2019-12-20
27

38
* Use Provider as state management

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ Smart select allows you to easily convert your usual form selects into dynamic p
44

55
# Demo
66

7+
## Preview
8+
9+
[![Watch the demo](https://img.youtube.com/vi/bcHELDM8hWg/maxresdefault.jpg)](https://youtu.be/bcHELDM8hWg)
10+
11+
## Download
12+
713
[![Demo App](https://github.com/davigmacode/flutter_smart_select/raw/master/example/art/qr/apk.png "Demo App")](https://github.com/davigmacode/flutter_smart_select/blob/master/example/art/demo/SmartSelect.apk?raw=true)
814

915
# Features

example/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Demo App
22

3+
## Preview
4+
5+
[![Watch the demo](https://img.youtube.com/vi/bcHELDM8hWg/maxresdefault.jpg)](https://youtu.be/bcHELDM8hWg)
6+
7+
## Download
8+
39
[![Demo App](https://github.com/davigmacode/flutter_smart_select/raw/master/example/art/qr/apk.png "Demo App")](https://github.com/davigmacode/flutter_smart_select/blob/master/example/art/demo/SmartSelect.apk?raw=true)
410

511
# Source Code
@@ -26,7 +32,7 @@
2632
* [Leading Widget](https://github.com/davigmacode/flutter_smart_select/blob/master/example/lib/features_tile/tile_leading.dart)
2733
* [Custom Trailing Widget](https://github.com/davigmacode/flutter_smart_select/blob/master/example/lib/features_tile/tile_trailing.dart)
2834
* [Loading Stats](https://github.com/davigmacode/flutter_smart_select/blob/master/example/lib/features_tile/tile_loading.dart)
29-
* [Custom Tile Builder]((https://github.com/davigmacode/flutter_smart_select/blob/master/example/lib/features_tile/tile_builder.dart))
35+
* [Custom Tile Builder](https://github.com/davigmacode/flutter_smart_select/blob/master/example/lib/features_tile/tile_builder.dart)
3036

3137

3238
## Customize Option

example/art/demo/SmartSelect.apk

3.74 KB
Binary file not shown.

example/art/qr/apk.png

-13.5 KB
Loading

example/lib/features.dart

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,9 @@ import './features_option/option_main.dart';
66
import './features_modal/modal_main.dart';
77
import './features_choices/choices_main.dart';
88

9-
class Features extends StatefulWidget {
10-
@override
11-
_FeaturesState createState() => _FeaturesState();
12-
}
13-
14-
class _FeaturesState extends State<Features> with AutomaticKeepAliveClientMixin<Features> {
15-
16-
@override
17-
bool get wantKeepAlive => true;
18-
9+
class Features extends StatelessWidget {
1910
@override
2011
Widget build(BuildContext context) {
21-
super.build(context);
2212
return DefaultTabController(
2313
length: 6,
2414
child: Scaffold(
@@ -39,7 +29,7 @@ class _FeaturesState extends State<Features> with AutomaticKeepAliveClientMixin<
3929
actions: <Widget>[
4030
IconButton(
4131
icon: Icon(Icons.help_outline),
42-
onPressed: () => _about(),
32+
onPressed: () => _about(context),
4333
)
4434
],
4535
),
@@ -57,7 +47,7 @@ class _FeaturesState extends State<Features> with AutomaticKeepAliveClientMixin<
5747
);
5848
}
5949

60-
void _about() {
50+
void _about(BuildContext context) {
6151
showDialog(
6252
context: context,
6353
builder: (_) => Dialog(

example/lib/features_choices/choices_main.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,19 @@ import './choices_divider.dart';
55
import './choices_theme.dart';
66
import '../features_header.dart';
77

8-
class FeaturesChoices extends StatelessWidget {
8+
class FeaturesChoices extends StatefulWidget {
9+
@override
10+
_FeaturesChoicesState createState() => _FeaturesChoicesState();
11+
}
12+
13+
class _FeaturesChoicesState extends State<FeaturesChoices> with AutomaticKeepAliveClientMixin<FeaturesChoices> {
14+
15+
@override
16+
bool get wantKeepAlive => true;
17+
918
@override
1019
Widget build(BuildContext context) {
20+
super.build(context);
1121
return Scrollbar(
1222
child:ListView(
1323
children: <Widget>[

example/lib/features_modal/modal_main.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,19 @@ import './modal_header.dart';
77
import './modal_headerless.dart';
88
import '../features_header.dart';
99

10-
class FeaturesModal extends StatelessWidget {
10+
class FeaturesModal extends StatefulWidget {
11+
@override
12+
_FeaturesModalState createState() => _FeaturesModalState();
13+
}
14+
15+
class _FeaturesModalState extends State<FeaturesModal> with AutomaticKeepAliveClientMixin<FeaturesModal> {
16+
17+
@override
18+
bool get wantKeepAlive => true;
19+
1120
@override
1221
Widget build(BuildContext context) {
22+
super.build(context);
1323
return Scrollbar(
1424
child:ListView(
1525
children: <Widget>[

example/lib/features_multi/multi_main.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,19 @@ import './multi_chips.dart';
77
import './multi_switches.dart';
88
import '../features_header.dart';
99

10-
class FeaturesMulti extends StatelessWidget {
10+
class FeaturesMulti extends StatefulWidget {
11+
@override
12+
_FeaturesMultiState createState() => _FeaturesMultiState();
13+
}
14+
15+
class _FeaturesMultiState extends State<FeaturesMulti> with AutomaticKeepAliveClientMixin<FeaturesMulti> {
16+
17+
@override
18+
bool get wantKeepAlive => true;
19+
1120
@override
1221
Widget build(BuildContext context) {
22+
super.build(context);
1323
return Scrollbar(
1424
child:ListView(
1525
children: <Widget>[

example/lib/features_option/option_async.dart

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:flutter/material.dart';
22
import 'package:smart_select/smart_select.dart';
33
import 'package:dio/dio.dart';
4+
import 'package:flutter_svg/flutter_svg.dart';
45

56
class FeaturesOptionAsync extends StatefulWidget {
67
@override
@@ -11,7 +12,11 @@ class _FeaturesOptionAsyncState extends State<FeaturesOptionAsync> {
1112

1213
String _user;
1314
List _users = [];
14-
bool _isLoading;
15+
bool _usersIsLoading;
16+
17+
List _country;
18+
List _countries = [];
19+
bool _countriesIsLoading;
1520

1621
@override
1722
Widget build(BuildContext context) {
@@ -23,9 +28,9 @@ class _FeaturesOptionAsyncState extends State<FeaturesOptionAsync> {
2328
value: _user,
2429
option: SmartSelectOptionConfig(
2530
_users,
26-
value: (_item) => _item['email'],
27-
title: (_item) => _item['name']['first'] + ' ' + _item['name']['last'],
28-
subtitle: (_item) => _item['email'],
31+
value: (data) => data['email'],
32+
title: (data) => data['name']['first'] + ' ' + data['name']['last'],
33+
subtitle: (data) => data['email'],
2934
groupBy: 'gender',
3035
),
3136
modal: SmartSelectModalConfig(useFilter: true),
@@ -40,7 +45,7 @@ class _FeaturesOptionAsyncState extends State<FeaturesOptionAsync> {
4045
title: state.title,
4146
value: state.valueDisplay,
4247
isTwoLine: true,
43-
isLoading: _isLoading,
48+
isLoading: _usersIsLoading,
4449
leading: Builder(
4550
builder: (context) {
4651
String avatarUrl = state.valueObject != null
@@ -56,6 +61,30 @@ class _FeaturesOptionAsyncState extends State<FeaturesOptionAsync> {
5661
},
5762
onChange: (val) => setState(() => _user = val),
5863
),
64+
Divider(indent: 20),
65+
SmartSelect(
66+
title: 'Country',
67+
value: _country,
68+
isTwoLine: true,
69+
isMultiChoice: true,
70+
option: SmartSelectOptionConfig(
71+
_countries,
72+
value: (data) => data['subregion'] + ' - ' + data['name'],
73+
title: (data) => data['name'],
74+
subtitle: ['capital'],
75+
groupBy: 'region',
76+
),
77+
modal: SmartSelectModalConfig(useFilter: true),
78+
choice: SmartSelectChoiceConfig(
79+
type: SmartSelectChoiceType.checkboxes,
80+
),
81+
leading: Container(
82+
width: 40,
83+
height: 40,
84+
child: Icon(Icons.flag),
85+
),
86+
onChange: (val) => setState(() => _country = val),
87+
),
5988
Container(height: 7),
6089
],
6190
);
@@ -66,19 +95,32 @@ class _FeaturesOptionAsyncState extends State<FeaturesOptionAsync> {
6695
super.initState();
6796

6897
_getUsers();
98+
_getCountries();
6999
}
70100

71101
void _getUsers() async {
72102
try {
73-
setState(() => _isLoading = true);
103+
setState(() => _usersIsLoading = true);
74104
String url = "https://randomuser.me/api/?inc=gender,name,nat,picture,email&results=25";
75105
Response res = await Dio().get(url);
76-
setState(() {
77-
_users = res.data['results'];
78-
_isLoading = false;
79-
});
106+
setState(() =>_users = res.data['results'].cast<Map>());
107+
} catch (e) {
108+
print(e);
109+
} finally {
110+
setState(() => _usersIsLoading = false);
111+
}
112+
}
113+
114+
void _getCountries() async {
115+
try {
116+
setState(() => _countriesIsLoading = true);
117+
String url = "http://restcountries.eu/rest/v2/all?fields=name;capital;flag;region;subregion";
118+
Response res = await Dio().get(url);
119+
setState(() => _countries = res.data.cast<Map>());
80120
} catch (e) {
81121
print(e);
122+
} finally {
123+
setState(() => _countriesIsLoading = false);
82124
}
83125
}
84126
}

0 commit comments

Comments
 (0)