|
1 | 1 | # chips_choice |
2 | 2 |
|
3 | | -A new Flutter package project. |
| 3 | +Lite version of [smart_select](https://pub.dev/packages/smart_select) package, zero dependencies, an easy way to provide a single or multiple choice chips. |
4 | 4 |
|
5 | | -## Getting Started |
| 5 | +## Demo |
6 | 6 |
|
7 | | -This project is a starting point for a Dart |
8 | | -[package](https://flutter.dev/developing-packages/), |
9 | | -a library module containing code that can be shared easily across |
10 | | -multiple Flutter or Dart projects. |
| 7 | +### Preview |
11 | 8 |
|
12 | | -For help getting started with Flutter, view our |
13 | | -[online documentation](https://flutter.dev/docs), which offers tutorials, |
14 | | -samples, guidance on mobile development, and a full API reference. |
| 9 | + |
| 10 | + |
| 11 | +### Download |
| 12 | + |
| 13 | +[](https://github.com/davigmacode/flutter_chips_choice/blob/master/example/art/ChipsChoice.apk?raw=true) |
| 14 | + |
| 15 | + |
| 16 | +## Features |
| 17 | + |
| 18 | +* Select single or multiple choice |
| 19 | +* Display in scrollable or wrapped List |
| 20 | +* Customizable choice input |
| 21 | +* Build choice option from any List |
| 22 | + |
| 23 | +## Usage |
| 24 | + |
| 25 | +For a complete usage, please see the [example](https://pub.dev/packages/chips_choice#-example-tab-). |
| 26 | + |
| 27 | +To read more about classes and other references used by `chips_choice`, see the [documentation](https://pub.dev/documentation/chips_choice/latest/). |
| 28 | + |
| 29 | +### Single Choice |
| 30 | + |
| 31 | +``` |
| 32 | +int tag = 1; |
| 33 | +List<String> options = [ |
| 34 | + 'News', 'Entertainment', 'Politics', |
| 35 | + 'Automotive', 'Sports', 'Education', |
| 36 | + 'Fashion', 'Travel', 'Food', 'Tech', |
| 37 | + 'Science', |
| 38 | +]; |
| 39 | +
|
| 40 | +// ChipsChoice<T>.single |
| 41 | +ChipsChoice<int>.single( |
| 42 | + value: tag, |
| 43 | + options: ChipsChoiceOption.listFrom<int, String>( |
| 44 | + source: options, |
| 45 | + value: (i, v) => i, |
| 46 | + label: (i, v) => v, |
| 47 | + ), |
| 48 | + onChanged: (val) => setState(() => tag = val), |
| 49 | +); |
| 50 | +
|
| 51 | +``` |
| 52 | + |
| 53 | +### Multiple Choice |
| 54 | + |
| 55 | +``` |
| 56 | +List<String> tags = []; |
| 57 | +List<String> options = [ |
| 58 | + 'News', 'Entertainment', 'Politics', |
| 59 | + 'Automotive', 'Sports', 'Education', |
| 60 | + 'Fashion', 'Travel', 'Food', 'Tech', |
| 61 | + 'Science', |
| 62 | +]; |
| 63 | +
|
| 64 | +// ChipsChoice<T>.multiple |
| 65 | +ChipsChoice<String>.multiple( |
| 66 | + value: tags, |
| 67 | + options: ChipsChoiceOption.listFrom<String, String>( |
| 68 | + source: options, |
| 69 | + value: (i, v) => v, |
| 70 | + label: (i, v) => v, |
| 71 | + ), |
| 72 | + onChanged: (val) => setState(() => tags = val), |
| 73 | +); |
| 74 | +``` |
| 75 | + |
| 76 | +### Build Options List |
| 77 | + |
| 78 | +`options` property is `List<ChipsChoiceOption<T>>`, it can be input directly as in the example below, more info about `ChipsChoiceOption` can be found on the [API Reference](https://pub.dev/documentation/chips_choice/latest/chips_choice/ChipsChoiceOption-class.html) |
| 79 | + |
| 80 | +``` |
| 81 | +ChipsChoice<T>.single/multiple( |
| 82 | + ..., |
| 83 | + ..., |
| 84 | + options: <ChipsChoiceOption<int>>[ |
| 85 | + ChipsChoiceOption<int>(value: 1, label: 'Entertainment'), |
| 86 | + ChipsChoiceOption<int>(value: 2, label: 'Education'), |
| 87 | + ChipsChoiceOption<int>(value: 3, label: 'Fashion'), |
| 88 | + ], |
| 89 | +); |
| 90 | +``` |
| 91 | + |
| 92 | +`options` also can be created from any list using helper provided by this package, like the example below |
| 93 | + |
| 94 | +``` |
| 95 | +List<Map<String, String>> days = [ |
| 96 | + { 'value': 'mon', 'title': 'Monday' }, |
| 97 | + { 'value': 'tue', 'title': 'Tuesday' }, |
| 98 | + { 'value': 'wed', 'title': 'Wednesday' }, |
| 99 | + { 'value': 'thu', 'title': 'Thursday' }, |
| 100 | + { 'value': 'fri', 'title': 'Friday' }, |
| 101 | + { 'value': 'sat', 'title': 'Saturday' }, |
| 102 | + { 'value': 'sun', 'title': 'Sunday' }, |
| 103 | +]; |
| 104 | +
|
| 105 | +ChipsChoice<T>.single/multiple( |
| 106 | + ..., |
| 107 | + ..., |
| 108 | + options: ChipsChoiceOption.listFrom<T, Map<String, String>>( |
| 109 | + source: days, |
| 110 | + value: (index, item) => item['value'], |
| 111 | + label: (index, item) => item['title'], |
| 112 | + ), |
| 113 | +); |
| 114 | +``` |
| 115 | + |
| 116 | +### Scrollable or Wrapped List |
| 117 | + |
| 118 | +``` |
| 119 | +ChipsChoice<T>.single/multiple( |
| 120 | + ..., |
| 121 | + ..., |
| 122 | + isWrapped: false/true, |
| 123 | +); |
| 124 | +``` |
| 125 | + |
| 126 | +## License |
| 127 | + |
| 128 | +``` |
| 129 | +Copyright (c) 2020 Irfan Vigma Taufik |
| 130 | +
|
| 131 | +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
| 132 | +
|
| 133 | +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |
| 134 | +
|
| 135 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 136 | +``` |
0 commit comments