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

displayValue property added to display value in conjunction with name. #36

Open
wants to merge 2 commits into
base: theme_changes
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ isEnabled=false to disable textfield,default value true
### enableSearch
enableSearch=true to enable search option in dropdown,as of now this feature enabled only for single selection dropdown

### displayValue
to display value in conjunction with name and display the value on selection.
more specifically, country code in selection dropdown show 'Bangladesh(+880)' and display '+880' on selection - where name is 'Bangladesh' and value is '+880'.


### displayCompleteItem
set displayCompleteItem=true, if you want show complete list of selected item in textfield else it will display like "number_of_item item selected"
Expand Down
23 changes: 16 additions & 7 deletions lib/dropdown_textfield.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class DropDownTextField extends StatefulWidget {
this.validator,
this.isEnabled = true,
this.enableSearch = false,
this.displayValue = false,
this.readOnly = true,
this.dropdownRadius = 12,
this.textFieldDecoration,
Expand Down Expand Up @@ -137,6 +138,7 @@ class DropDownTextField extends StatefulWidget {
multiController = controller,
isMultiSelection = true,
enableSearch = false,
displayValue = false,
readOnly = true,
searchAutofocus = false,
searchKeyboardType = null,
Expand Down Expand Up @@ -192,6 +194,9 @@ class DropDownTextField extends StatefulWidget {
///by setting enableSearch=true enable search option in dropdown,as of now this feature enabled only for single selection dropdown
final bool enableSearch;

///by setting displayValue=true enable displaying the 'value' instead of 'name' and in list it will show 'name(value)'
final bool? displayValue;

final bool readOnly;

///set displayCompleteItem=true, if you want show complete list of item in textfield else it will display like "number_of_item item selected"
Expand Down Expand Up @@ -442,15 +447,15 @@ class _DropDownTextFieldState extends State<DropDownTextField>
} else {
if (widget.singleController != null) {
if (widget.singleController!.dropDownValue != null) {
_cnt.text = widget.singleController!.dropDownValue!.name;
_cnt.text = (widget.displayValue?? false) ? widget.singleController!.dropDownValue!.value : widget.singleController!.dropDownValue!.name;
} else {
_cnt.clear();
}
}
}

_listTileTextStyle =
(widget.listTextStyle ?? Theme.of(context).textTheme.subtitle1)!;
(widget.listTextStyle ?? Theme.of(context).textTheme.titleMedium)!;
_listTileHeight =
_textWidgetSize("dummy Text", _listTileTextStyle).height +
_listPadding.top +
Expand Down Expand Up @@ -669,7 +674,7 @@ class _DropDownTextFieldState extends State<DropDownTextField>
builder: buildOverlay,
))),
);
overlay?.insert(_isScrollPadding ? _entry2! : _entry!);
overlay.insert(_isScrollPadding ? _entry2! : _entry!);
}

_openOutSideClickOverlay(BuildContext context) {
Expand All @@ -687,7 +692,7 @@ class _DropDownTextFieldState extends State<DropDownTextField>
),
);
});
overlay2?.insert(_barrierOverlay!);
overlay2.insert(_barrierOverlay!);
}

void hideOverlay() {
Expand Down Expand Up @@ -767,13 +772,14 @@ class _DropDownTextFieldState extends State<DropDownTextField>
mainFocusNode: _textFieldFocusNode,
searchFocusNode: _searchFocusNode,
enableSearch: widget.enableSearch,
displayValue: widget.displayValue,
height: _height,
listTileHeight: _listTileHeight,
dropDownList: _dropDownList,
listTextStyle: _listTileTextStyle,
onChanged: (item) {
setState(() {
_cnt.text = item.name;
_cnt.text = (widget.displayValue?? false) ? item.value : item.name;
_isExpanded = !_isExpanded;
});
if (widget.singleController != null) {
Expand Down Expand Up @@ -868,6 +874,7 @@ class SingleSelection extends StatefulWidget {
required this.onChanged,
required this.height,
required this.enableSearch,
this.displayValue,
required this.searchHeight,
required this.searchFocusNode,
required this.mainFocusNode,
Expand All @@ -889,6 +896,7 @@ class SingleSelection extends StatefulWidget {
final double height;
final double listTileHeight;
final bool enableSearch;
final bool? displayValue;
final double searchHeight;
final FocusNode searchFocusNode;
final FocusNode mainFocusNode;
Expand Down Expand Up @@ -1025,7 +1033,7 @@ class _SingleSelectionState extends State<SingleSelection> {
alignment: Alignment.centerLeft,
child: FittedBox(
fit: BoxFit.fitHeight,
child: Text(newDropDownList[index].name,
child: Text((widget.displayValue?? false) ? '${newDropDownList[index].name}(${newDropDownList[index].value})' : newDropDownList[index].name,
style: widget.listTextStyle),
),
),
Expand Down Expand Up @@ -1311,7 +1319,8 @@ class _KeyboardVisibilityBuilderState extends State<KeyboardVisibilityBuilder>

@override
void didChangeMetrics() {
final bottomInset = WidgetsBinding.instance.window.viewInsets.bottom;
// final bottomInset = WidgetsBinding.instance.window.viewInsets.bottom;
final bottomInset = WidgetsBinding.instance.platformDispatcher.views.first.viewInsets.bottom;
final newValue = bottomInset > 0.0;
if (newValue != _isKeyboardVisible) {
setState(() {
Expand Down