Skip to content

Commit

Permalink
Bug: menu mode didn't open choices when on hosted web. #9 and icemanb…
Browse files Browse the repository at this point in the history
  • Loading branch information
lcuis committed Apr 17, 2020
1 parent 3744439 commit f0aa7cb
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 110 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
## 1.0.15

* Bug: menu mode didn't open choices when on hosted web. https://github.com/lcuis/search_choices/issues/9 and https://github.com/icemanbsi/searchable_dropdown/issues/39

## 1.0.14

* Surrounded the DropdownDialog with a StatefulBuilder to allow the refresh of the display when there is a call to updateParent through a setState.
Expand Down
91 changes: 21 additions & 70 deletions example/pubspec.lock
@@ -1,69 +1,55 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
archive:
dependency: transitive
description:
name: archive
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.11"
args:
dependency: transitive
description:
name: args
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.2"
async:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
version: "2.4.1"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.5"
version: "2.0.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.2"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.11"
convert:
version: "1.1.3"
clock:
dependency: transitive
description:
name: convert
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
crypto:
version: "1.0.1"
collection:
dependency: transitive
description:
name: crypto
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
version: "1.14.12"
cupertino_icons:
dependency: "direct main"
description:
name: cupertino_icons
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -74,13 +60,6 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
image:
dependency: transitive
description:
name: image
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.4"
matcher:
dependency: transitive
description:
Expand All @@ -101,35 +80,14 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.4"
pedantic:
dependency: transitive
description:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0+1"
petitparser:
dependency: transitive
description:
name: petitparser
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.5"
version: "1.7.0"
search_choices:
dependency: "direct dev"
description:
path: ".."
relative: true
source: path
version: "1.0.13"
version: "1.0.14"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -141,7 +99,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.5"
version: "1.7.0"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -176,7 +134,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.11"
version: "0.2.15"
typed_data:
dependency: transitive
description:
Expand All @@ -191,12 +149,5 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
xml:
dependency: transitive
description:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "3.5.0"
sdks:
dart: ">=2.4.0 <3.0.0"
dart: ">=2.6.0 <3.0.0"
84 changes: 45 additions & 39 deletions lib/search_choices.dart
Expand Up @@ -9,6 +9,11 @@ class NotGiven {
const NotGiven();
}

class PointerThisPlease<T> {
T value;
PointerThisPlease(this.value);
}

Widget prepareWidget(dynamic object,
{dynamic parameter = const NotGiven(),
Function updateParent,
Expand Down Expand Up @@ -388,7 +393,7 @@ class SearchChoices<T> extends StatefulWidget {

class _SearchChoicesState<T> extends State<SearchChoices<T>> {
List<int> selectedItems;
List<bool> displayMenu = [false];
PointerThisPlease<bool> displayMenu = PointerThisPlease<bool>(false);
Function updateParent;

TextStyle get _textStyle =>
Expand Down Expand Up @@ -516,41 +521,42 @@ class _SearchChoicesState<T> extends State<SearchChoices<T>> {
}

Widget get menuWidget {
return StatefulBuilder( // You need this, notice the parameters below:
return StatefulBuilder(
builder: (BuildContext context, StateSetter setStateFromBuilder) {
return (DropdownDialog(
items: widget.items,
hint: prepareWidget(widget.searchHint),
isCaseSensitiveSearch: widget.isCaseSensitiveSearch,
closeButton: widget.closeButton,
keyboardType: widget.keyboardType,
searchFn: widget.searchFn,
multipleSelection: widget.multipleSelection,
selectedItems: selectedItems,
doneButton: widget.doneButton,
displayItem: widget.displayItem,
validator: widget.validator,
dialogBox: widget.dialogBox,
displayMenu: displayMenu,
menuConstraints: widget.menuConstraints,
menuBackgroundColor: widget.menuBackgroundColor,
style: widget.style,
iconEnabledColor: widget.iconEnabledColor,
iconDisabledColor: widget.iconDisabledColor,
callOnPop: () {
if (!widget.dialogBox &&
widget.onChanged != null &&
selectedItems != null) {
widget.onChanged(selectedResult);
}
setState(() {});
},
updateParent: (value){
updateParent(value);
setStateFromBuilder(() {});
},
rightToLeft: widget.rightToLeft,
));});
return (DropdownDialog(
items: widget.items,
hint: prepareWidget(widget.searchHint),
isCaseSensitiveSearch: widget.isCaseSensitiveSearch,
closeButton: widget.closeButton,
keyboardType: widget.keyboardType,
searchFn: widget.searchFn,
multipleSelection: widget.multipleSelection,
selectedItems: selectedItems,
doneButton: widget.doneButton,
displayItem: widget.displayItem,
validator: widget.validator,
dialogBox: widget.dialogBox,
displayMenu: displayMenu,
menuConstraints: widget.menuConstraints,
menuBackgroundColor: widget.menuBackgroundColor,
style: widget.style,
iconEnabledColor: widget.iconEnabledColor,
iconDisabledColor: widget.iconDisabledColor,
callOnPop: () {
if (!widget.dialogBox &&
widget.onChanged != null &&
selectedItems != null) {
widget.onChanged(selectedResult);
}
setState(() {});
},
updateParent: (value) {
updateParent(value);
setStateFromBuilder(() {});
},
rightToLeft: widget.rightToLeft,
));
});
}

@override
Expand Down Expand Up @@ -614,7 +620,7 @@ class _SearchChoicesState<T> extends State<SearchChoices<T>> {
widget.onChanged(selectedResult);
}
} else {
displayMenu.first = true;
displayMenu.value = true;
}
if (mounted) {
setState(() {});
Expand Down Expand Up @@ -740,7 +746,7 @@ class _SearchChoicesState<T> extends State<SearchChoices<T>> {
style: TextStyle(color: Colors.red, fontSize: 13),
)
: validatorOutput,
displayMenu.first ? menuWidget : SizedBox.shrink(),
displayMenu.value ? menuWidget : SizedBox.shrink(),
],
);
}
Expand Down Expand Up @@ -770,7 +776,7 @@ class DropdownDialog<T> extends StatefulWidget {
final dynamic doneButton;
final Function validator;
final bool dialogBox;
final List<bool> displayMenu;
final PointerThisPlease<bool> displayMenu;
final BoxConstraints menuConstraints;
final Function callOnPop;
final Color menuBackgroundColor;
Expand Down Expand Up @@ -1043,7 +1049,7 @@ class _DropdownDialogState<T> extends State<DropdownDialog> {
if (widget.dialogBox) {
Navigator.pop(context);
} else {
widget.displayMenu.first = false;
widget.displayMenu.value = false;
if (widget.callOnPop != null) {
widget.callOnPop();
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
@@ -1,6 +1,6 @@
name: search_choices
description: Widget to let the user search through a keyword string typed on a customizable keyboard in a single or multiple choices list presented as a dropdown in a dialog box or a menu.
version: 1.0.14
version: 1.0.15
homepage: https://github.com/lcuis/search_choices
repository: https://github.com/lcuis/search_choices
issue_tracker: https://github.com/lcuis/search_choices/issues
Expand Down
1 change: 1 addition & 0 deletions search_choices.iml
Expand Up @@ -11,6 +11,7 @@
<excludeFolder url="file://$MODULE_DIR$/example/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/example/.pub" />
<excludeFolder url="file://$MODULE_DIR$/example/build" />
<excludeFolder url="file://$MODULE_DIR$/example/web/public/assets/packages" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart SDK" level="project" />
Expand Down

0 comments on commit f0aa7cb

Please sign in to comment.