Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #43

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 18 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ A multi select form field using alert dialog to select multiple items with check
| :------------------------ | :---------------------------------------------------------------------------------------------------------------------- |
| **title** *Widget* | Set Title of MultiSelectTextFormField. |
| **hintWidget** *Widget* | Set Hint Text of MultiSelectTextFormField. |
| **required** *bool* | Add Selection is Compulsary or not. |
| **needed** *bool* | Add Selection is Compulsary or not. |
| **errorText** *String* | Error String to be Displayed |
| **dataSource** *List<dynamic>*| List of Data as DataSource To Select. |
| **textField** *String* | Key Param from List (DataSource). |
Expand Down Expand Up @@ -57,7 +57,7 @@ A multi select form field using alert dialog to select multiple items with check
## Minimal Example

```dart
MultiSelectFormField(
MultiSelectFormField<String>(
autovalidate: false,
chipBackGroundColor: Colors.red,
chipLabelStyle: TextStyle(fontWeight: FontWeight.bold),
Expand All @@ -71,18 +71,13 @@ MultiSelectFormField(
style: TextStyle(fontSize: 16),
),
dataSource: [
{
"display": "Running",
"value": "Running",
},
{
"display": "Climbing",
"value": "Climbing",
},
{
"display": "Walking",
"value": "Walking",
},
Pair.from("Running"),
Pair.from("Climbing"),
Pair.from("Walking"),
Pair.from("Swimming"),
Pair.from("Soccer Practice"),
Pair.from("Baseball Practice"),
Pair.from("Football Practice"),
],
textField: 'display',
valueField: 'value',
Expand Down Expand Up @@ -156,7 +151,7 @@ class _MyHomePageState extends State<MyHomePage> {
children: <Widget>[
Container(
padding: EdgeInsets.all(16),
child: MultiSelectFormField(
child: MultiSelectFormField<String>(
autovalidate: false,
titleText: 'My workouts',
validator: (value) {
Expand All @@ -165,40 +160,19 @@ class _MyHomePageState extends State<MyHomePage> {
}
},
dataSource: [
{
"display": "Running",
"value": "Running",
},
{
"display": "Climbing",
"value": "Climbing",
},
{
"display": "Walking",
"value": "Walking",
},
{
"display": "Swimming",
"value": "Swimming",
},
{
"display": "Soccer Practice",
"value": "Soccer Practice",
},
{
"display": "Baseball Practice",
"value": "Baseball Practice",
},
{
"display": "Football Practice",
"value": "Football Practice",
},
Pair.from("Running"),
Pair.from("Climbing"),
Pair.from("Walking"),
Pair.from("Swimming"),
Pair.from("Soccer Practice"),
Pair.from("Baseball Practice"),
Pair.from("Football Practice"),
],
textField: 'display',
valueField: 'value',
okButtonLabel: 'OK',
cancelButtonLabel: 'CANCEL',
// required: true,
// needed: true,
hintText: 'Please choose one or more',
value: _myActivities,
onSaved: (value) {
Expand Down
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:lints/recommended.yaml
110 changes: 70 additions & 40 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,32 @@ class MyHomePage extends StatefulWidget {
}

class _MyHomePageState extends State<MyHomePage> {
List? _myActivities;
List<String>? _myActivities;
List<int>? _myInts;
late String _myActivitiesResult;
final formKey = new GlobalKey<FormState>();
late String _myIntsResult;
final formKey = GlobalKey<FormState>();

@override
void initState() {
super.initState();
_myActivities = [];
_myInts = [];
_myActivitiesResult = '';
_myIntsResult = '';
}

_saveForm() {
var form = formKey.currentState!;
final form = formKey.currentState!;
if (form.validate()) {
form.save();
setState(() {
_myActivitiesResult = _myActivities.toString();
_myIntsResult = _myInts.toString();
});
} else {
setState(() =>
_myActivitiesResult = _myIntsResult = "Error: Validation failed");
}
}

Expand All @@ -53,10 +61,11 @@ class _MyHomePageState extends State<MyHomePage> {
children: <Widget>[
Container(
padding: EdgeInsets.all(16),
child: MultiSelectFormField(
autovalidate: false,
chipBackGroundColor: Colors.blue,
chipLabelStyle: TextStyle(fontWeight: FontWeight.bold, color: Colors.white),
child: MultiSelectFormField<String>(
autovalidate: AutovalidateMode.disabled,
chipBackgroundColor: Colors.blue,
chipLabelStyle: TextStyle(
fontWeight: FontWeight.bold, color: Colors.white),
dialogTextStyle: TextStyle(fontWeight: FontWeight.bold),
checkBoxActiveColor: Colors.blue,
checkBoxCheckColor: Colors.white,
Expand All @@ -67,51 +76,72 @@ class _MyHomePageState extends State<MyHomePage> {
style: TextStyle(fontSize: 16),
),
validator: (value) {
if (value == null || value.length == 0) {
if (value == null || value.isEmpty) {
return 'Please select one or more options';
}
return null;
},
dataSource: [
{
"display": "Running",
"value": "Running",
},
{
"display": "Climbing",
"value": "Climbing",
},
{
"display": "Walking",
"value": "Walking",
},
{
"display": "Swimming",
"value": "Swimming",
},
{
"display": "Soccer Practice",
"value": "Soccer Practice",
},
{
"display": "Baseball Practice",
"value": "Baseball Practice",
},
{
"display": "Football Practice",
"value": "Football Practice",
},
Pair.from("Running"),
Pair.from("Climbing"),
Pair.from("Walking"),
Pair.from("Swimming"),
Pair.from("Soccer Practice"),
Pair.from("Baseball Practice"),
Pair.from("Football Practice"),
],
textField: 'display',
valueField: 'value',
okButtonLabel: 'OK',
cancelButtonLabel: 'CANCEL',
hintWidget: Text('Please choose one or more'),
initialValue: _myActivities,
onSaved: (value) {
if (value == null) return;
setState(() {
_myActivities = value;
_myActivities = value.toList();
});
},
),
),
Container(
padding: EdgeInsets.all(16),
child: Text(_myActivitiesResult),
),
Container(
padding: EdgeInsets.all(16),
child: MultiSelectFormField<int>(
autovalidate: AutovalidateMode.disabled,
chipBackgroundColor: Colors.blue,
chipLabelStyle: TextStyle(
fontWeight: FontWeight.bold, color: Colors.white),
dialogTextStyle: TextStyle(fontWeight: FontWeight.bold),
checkBoxActiveColor: Colors.blue,
checkBoxCheckColor: Colors.white,
dialogShapeBorder: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(12.0))),
title: Text(
"My Numbers",
style: TextStyle(fontSize: 16),
),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please select one or more options';
}
return null;
},
dataSource: [
Pair(label: "Zero", value: 0),
Pair(label: "One", value: 1),
Pair(label: "Two", value: 2),
Pair(label: "Three", value: 3),
],
okButtonLabel: 'OK',
cancelButtonLabel: 'CANCEL',
hintWidget: Text('Please choose one or more'),
initialValue: _myInts,
onSaved: (value) {
if (value == null) return;
setState(() {
_myInts = value.toList();
});
},
),
Expand All @@ -125,7 +155,7 @@ class _MyHomePageState extends State<MyHomePage> {
),
Container(
padding: EdgeInsets.all(16),
child: Text(_myActivitiesResult),
child: Text(_myIntsResult),
)
],
),
Expand Down
8 changes: 4 additions & 4 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.5.0"
version: "2.6.1"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -87,7 +87,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.1.6"
version: "0.1.7"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -141,7 +141,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.19"
version: "0.3.0"
typed_data:
dependency: transitive
description:
Expand All @@ -157,4 +157,4 @@ packages:
source: hosted
version: "2.1.0"
sdks:
dart: ">=2.12.0-0.0 <3.0.0"
dart: ">=2.12.0 <3.0.0"
1 change: 1 addition & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: example
description: Multi select form field example.
version: 1.0.0+1
publish_to: none

environment:
sdk: ">=2.12.0-0 <3.0.0"
Expand Down
Loading