From e0cf3611437cadfd9d73d1107e05654e3bdfcdd6 Mon Sep 17 00:00:00 2001 From: prouxhere <139827218+prouxhere@users.noreply.github.com> Date: Wed, 23 Oct 2024 21:37:37 -0300 Subject: [PATCH] add: dropdownColor parameter. --- lib/multiselect.dart | 56 ++++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/lib/multiselect.dart b/lib/multiselect.dart index a93e629..4d37504 100644 --- a/lib/multiselect.dart +++ b/lib/multiselect.dart @@ -1,10 +1,8 @@ library multiselect; - import 'package:flutter/material.dart'; import 'package:states_rebuilder/states_rebuilder.dart'; - class _TheState {} var _theState = RM.inject(() => _TheState()); @@ -29,7 +27,12 @@ class _SelectRow extends StatelessWidget { final bool selected; final String text; - const _SelectRow({Key? key, required this.onChange, required this.selected, required this.text}) : super(key: key); + const _SelectRow( + {Key? key, + required this.onChange, + required this.selected, + required this.text}) + : super(key: key); @override Widget build(BuildContext context) { @@ -82,6 +85,9 @@ class DropDownMultiSelect extends StatefulWidget { /// this text is shown when there is no selection final String? whenEmpty; + //define background color to dropdown dialog + final Color? dropdownColor; + /// a function to build custom childern final Widget Function(List selectedValues)? childBuilder; @@ -104,7 +110,8 @@ class DropDownMultiSelect extends StatefulWidget { final Widget? hint; /// selectedValue separator - final String separator; + final T? separator; + /// style for the selected values final TextStyle? selectedValuesStyle; @@ -114,6 +121,7 @@ class DropDownMultiSelect extends StatefulWidget { required this.selectedValues, required this.onChanged, this.whenEmpty, + this.dropdownColor, this.icon, this.hint, this.hintStyle, @@ -125,14 +133,15 @@ class DropDownMultiSelect extends StatefulWidget { this.decoration, this.validator, this.readOnly = false, - this.separator = ' , ', + this.separator, }) : super(key: key); @override _DropDownMultiSelectState createState() => _DropDownMultiSelectState(); } -class _DropDownMultiSelectState extends State> { +class _DropDownMultiSelectState + extends State> { @override Widget build(BuildContext context) { return Container( @@ -142,20 +151,26 @@ class _DropDownMultiSelectState extends State widget.childBuilder != null ? widget.childBuilder!(widget.selectedValues) : Padding( - padding: - widget.decoration !=null ? widget.decoration!.contentPadding !=null ? widget.decoration!.contentPadding! : EdgeInsets.symmetric(horizontal: 10) : EdgeInsets.symmetric(horizontal: 10), + padding: widget.decoration != null + ? widget.decoration!.contentPadding != null + ? widget.decoration!.contentPadding! + : EdgeInsets.symmetric(horizontal: 10) + : EdgeInsets.symmetric(horizontal: 10), child: Padding( - padding: const EdgeInsets.only(right: 20), child: Text(widget.selectedValues.length > 0 - ? widget.selectedValues - .reduce((a, b) => a + widget.separator + b) + ? widget.selectedValues.map((e) => e.toString()).reduce( + (a, b) => + a + + (widget.separator != null + ? widget.separator.toString() + : ',') + + b) : widget.whenEmpty ?? ''), ))), - - Container( child: DropdownButtonFormField( + dropdownColor: widget.dropdownColor, hint: widget.hint, style: widget.hintStyle, icon: widget.icon, @@ -173,7 +188,9 @@ class _DropDownMultiSelectState extends State 0 ? widget.selectedValues[0] : null, + value: widget.selectedValues.length > 0 + ? widget.selectedValues[0] + : null, selectedItemBuilder: (context) { return widget.options .map((e) => DropdownMenuItem( @@ -233,7 +250,16 @@ class _DropDownMultiSelectState extends State 0 ? widget.selectedValues.map((e) => e.toString()).reduce((a, b) => a.toString() + ' , ' + b.toString()) : widget.whenEmpty ?? '', + widget.selectedValues.length > 0 + ? widget.selectedValues + .map((e) => e.toString()) + .reduce((a, b) => + a.toString() + + (widget.separator != null + ? widget.separator.toString() + : ',') + + b.toString()) + : widget.whenEmpty ?? '', style: widget.selectedValuesStyle, ), ))),