From d6f29de12d450070e9d51e0ce39bd6c081cf699f Mon Sep 17 00:00:00 2001 From: Amadou Tidiane Bah Date: Mon, 30 Jan 2023 13:16:52 +0000 Subject: [PATCH 1/2] replacing all de firstWhere by forEach --- lib/select_form_field.dart | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/select_form_field.dart b/lib/select_form_field.dart index a2f6c9a..69bcf1a 100644 --- a/lib/select_form_field.dart +++ b/lib/select_form_field.dart @@ -476,10 +476,12 @@ class _SelectFormFieldState extends FormFieldState { if (_effectiveController?.text != null && _effectiveController?.text != '') { - _item = widget.items?.firstWhere( - (lmItem) => lmItem['value'].toString() == _effectiveController?.text, - orElse: () => {}, - ); + widget.items?.forEach((Map lmItem) { + if (lmItem['value'].toString() == _effectiveController?.text) { + _item = lmItem; + return; + } + }); if (_item!.length > 0) { _labelController.text = @@ -536,10 +538,12 @@ class _SelectFormFieldState extends FormFieldState { ); if (lvPicked != null && lvPicked != value) { - _item = widget.items?.firstWhere( - (lmItem) => lmItem['value'].toString() == lvPicked, - orElse: () => {}, - ); + widget.items?.forEach((Map lmItem) { + if (lmItem['value'].toString() == lvPicked) { + _item = lmItem; + return; + } + }); if (_item!.length > 0) { _labelController.text = From 0660370b6fa9313b99bffc9d4abe1e85fa6405e3 Mon Sep 17 00:00:00 2001 From: Amadou Tidiane Bah Date: Wed, 1 Mar 2023 13:51:34 +0000 Subject: [PATCH 2/2] enable 'arrow_drop_down' icon to open dropdown menu --- lib/select_form_field.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/select_form_field.dart b/lib/select_form_field.dart index 69bcf1a..d7175e0 100644 --- a/lib/select_form_field.dart +++ b/lib/select_form_field.dart @@ -217,7 +217,9 @@ class SelectFormField extends FormField { width: 10, margin: EdgeInsets.all(0), child: TextButton( - onPressed: () {}, + onPressed: type == SelectFormFieldType.dialog + ? state._showSelectFormFieldDialog + : state._showSelectFormFieldMenu, child: Icon(Icons.arrow_drop_down), ), ), @@ -627,7 +629,7 @@ class _SelectFormFieldState extends FormFieldState { RelativeRect _buttonMenuPosition(BuildContext poContext) { final RenderBox loBar = poContext.findRenderObject() as RenderBox; final RenderBox loOverlay = - Overlay.of(poContext)?.context.findRenderObject() as RenderBox; + Overlay.of(poContext).context.findRenderObject() as RenderBox; const Offset loOffset = Offset.zero; final RelativeRect loPosition = RelativeRect.fromRect(