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

F editable labels #2

Open
wants to merge 3 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
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@

## [1.0.3] - 13-Sep-2019

* Updated image location
* Updated image location

## [1.0.4] 0 03-Oct-2019

* Added optional override parameters for invalid and empty text. Localization and Customization.
* Added onValueChange() callback for onClear() to reset state (if is used as a filter).
18 changes: 14 additions & 4 deletions lib/dropdownfield.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import 'package:flutter/services.dart';
///
///labelStyle - TextStyle - Optional styling for Label text. Default is normal, gray colored font of size 18.0
///
///emptyFieldText - String - Override text for empty field (Localization).
///
///invalidFieldText - String - Override text for invalid field (Localization).
///
///required - bool - True will validate that this field has a non-null/non-empty value. Default is false
///
///enabled - bool - False will disable the field. You can unset this to use the Dropdown field as a read only form field. Default is true
Expand Down Expand Up @@ -47,6 +51,8 @@ class DropDownField extends FormField<String> {
final String labelText;
final TextStyle labelStyle;
final TextStyle textStyle;
final String emptyFieldText;
final String invalidValueText;
final bool required;
final bool enabled;
final List<dynamic> items;
Expand All @@ -63,10 +69,13 @@ class DropDownField extends FormField<String> {
final TextEditingController controller;

DropDownField(
{Key key,
{
Key key,
this.controller,
this.value,
this.required: false,
this.emptyFieldText: 'This field cannot be empty!',
this.invalidValueText: 'Invalid value in this field!',
this.icon,
this.hintText,
this.hintStyle: const TextStyle(
Expand Down Expand Up @@ -129,7 +138,7 @@ class DropDownField extends FormField<String> {
validator: (String newValue) {
if (required) {
if (newValue == null || newValue.isEmpty)
return 'This field cannot be empty!';
return emptyFieldText;
}

//Items null check added since there could be an initial brief period of time
Expand All @@ -138,7 +147,7 @@ class DropDownField extends FormField<String> {
if (strict &&
newValue.isNotEmpty &&
!items.contains(newValue))
return 'Invalid value in this field!';
return invalidValueText;
}

return null;
Expand Down Expand Up @@ -205,6 +214,7 @@ class DropDownFieldState extends FormFieldState<String> {
setState(() {
_effectiveController.text = '';
});
if (widget.onValueChanged != null) widget.onValueChanged('');
}

@override
Expand Down Expand Up @@ -307,4 +317,4 @@ class DropDownFieldState extends FormFieldState<String> {
});
}
}
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: dropdownfield
description: Custom Flutter Widget that mimicks the standard Android auto-complete dropdown field. Has many options for customizing the behavior of this field.
version: 1.0.3
version: 1.0.4
author: Jagannathan S <jagan.srinivasan@gmail.com>
homepage: https://github.com/jagan999/dropdownfield

Expand Down