Skip to content

Commit

Permalink
New label attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
JhonaCodes committed Nov 13, 2024
1 parent 64f706a commit 9f89dae
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 35 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.5.2
- Attribute label text.

## 1.5.1
- Format.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Add the dependency to your `pubspec.yaml` file:

```yaml
dependencies:
multiselect_field: ^1.5.1
multiselect_field: ^1.5.2
```
Then, install the dependencies using:
Expand Down
67 changes: 41 additions & 26 deletions lib/core/multi_select.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,32 +109,38 @@ class MultiSelectField<T> extends StatefulWidget {
final TextStyle? titleMenuStyle;
final TextStyle? itemMenuStyle;

const MultiSelectField(
{super.key,
required this.data,
required this.onSelect,
this.title,
this.defaultData,
this.useTextFilter = false,
this.decoration,
this.singleSelection = false,
this.menuHeightBaseOnContent = false,
this.menuWidthBaseOnContent = false,
this.itemMenuButton,
this.buttonStyle,
this.iconLeft,
this.iconRight,
this.menuStyle,
this.menuHeight,
this.menuWidth,
this.footer,
this.multiSelectWidget,
this.singleSelectWidget,
this.isMandatory = false,
this.itemMenuStyle,
this.titleMenuStyle,
this.textStyleSingleSelection,
this.cleanCurrentSelection = false});
final String? label;
final TextStyle? textStyleLabel;

const MultiSelectField({
super.key,
required this.data,
required this.onSelect,
this.title,
this.defaultData,
this.useTextFilter = false,
this.decoration,
this.singleSelection = false,
this.menuHeightBaseOnContent = false,
this.menuWidthBaseOnContent = false,
this.itemMenuButton,
this.buttonStyle,
this.iconLeft,
this.iconRight,
this.menuStyle,
this.menuHeight,
this.menuWidth,
this.footer,
this.multiSelectWidget,
this.singleSelectWidget,
this.isMandatory = false,
this.itemMenuStyle,
this.titleMenuStyle,
this.textStyleSingleSelection,
this.cleanCurrentSelection = false,
this.label,
this.textStyleLabel,
});

@override
State<MultiSelectField<T>> createState() => _MultiSelectFieldState<T>();
Expand Down Expand Up @@ -320,6 +326,13 @@ class _MultiSelectFieldState<T> extends State<MultiSelectField<T>>
spacing: 7,
runSpacing: _isMobile ? 0 : 7,
children: [
if (_selectedChoice.isEmpty &&
!widget.useTextFilter &&
widget.label != null)
Text(
widget.label!,
style: widget.textStyleLabel,
),
if (_selectedChoice.isNotEmpty)
..._selectedChoice.map(
(element) {
Expand Down Expand Up @@ -351,6 +364,8 @@ class _MultiSelectFieldState<T> extends State<MultiSelectField<T>>
textController: _textController,
focusNodeTextField: _focusNodeTextField,
isMobile: _isMobile,
label: widget.label,
textStyleLabel: widget.textStyleLabel,
onTap: () {
if (!val.isOpen) val.open();
},
Expand Down
16 changes: 11 additions & 5 deletions lib/core/search_multiselect_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ final class SearchMultiselectField extends StatelessWidget {
/// Callback function that handles changes in the search input.
final void Function(String value) onChange;

final String? label;
final TextStyle? textStyleLabel;

/// Creates a [SearchMultiselectField] widget.
///
/// The [textController], [isMobile], [onTap], [focusNodeTextField], and [onChange] parameters are required.
Expand All @@ -55,6 +58,8 @@ final class SearchMultiselectField extends StatelessWidget {
required this.onTap,
required this.focusNodeTextField,
required this.onChange,
this.label,
this.textStyleLabel,
});

@override
Expand All @@ -66,6 +71,7 @@ final class SearchMultiselectField extends StatelessWidget {
),
child: SearchBar(
controller: textController,
hintText: label,
padding:
const WidgetStatePropertyAll<EdgeInsetsGeometry>(EdgeInsets.zero),
elevation: const WidgetStatePropertyAll<double>(0),
Expand All @@ -89,11 +95,11 @@ final class SearchMultiselectField extends StatelessWidget {
const WidgetStatePropertyAll<Color>(Colors.transparent),
shadowColor: const WidgetStatePropertyAll<Color>(Colors.transparent),
overlayColor: const WidgetStatePropertyAll<Color>(Colors.transparent),
hintStyle: const WidgetStatePropertyAll<TextStyle>(
TextStyle(
color: Colors.transparent,
decoration: TextDecoration.none,
),
hintStyle: WidgetStatePropertyAll<TextStyle>(
textStyleLabel ??
const TextStyle(
decoration: TextDecoration.none,
),
),
onTap: onTap,
onChanged: onChange,
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: multiselect_field
description: "A class for multiple select fields that allows users to select multiple elements from a list"
version: 1.5.1
homepage: https://github.com/JhonaCodes/multiselect_field
description: "A flexible dropdown field supporting single/multiple selection modes, styles, titles, etc"
version: 1.5.2
homepage: https://github.com/JhonaCodes/multiselect_field.git

environment:
sdk: ^3.5.1
Expand Down
Binary file added test/goldens/ci/default_label.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/goldens/macos/default_label.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions test/multiselect_field_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,59 @@ void main() {
),
);
});


group('GOLDEN_TEST_LABEL', () {
goldenTest(
'Default label',
fileName: 'default_label',
builder: () => GoldenTestGroup(
scenarioConstraints: constraint,
children: [
GoldenTestScenario(
name: "Default text",
child: SizedBox(
width: 300,
height: 70,
child: MultiSelectField(
decoration: decoration,
label: "Label text",
data: () => [],
onSelect: (value, isFromDefault) {},
),
),
),
GoldenTestScenario(
name: "Label on Filter by text",
child: SizedBox(
width: 300,
height: 70,
child: MultiSelectField(
decoration: decoration,
singleSelection: true,
useTextFilter: true,
label: "Label on text filter",
data: () => [],
onSelect: (value, isFromDefault) {},
),
),
),
GoldenTestScenario(
name: "Label with default data",
child: SizedBox(
width: 300,
height: 70,
child: MultiSelectField(
decoration: decoration,
label: "Label with default data",
defaultData: [Choice('1', 'Item1'), Choice('2', 'Item2')],
data: () => [],
onSelect: (value, isFromDefault) {},
),
),
),
],
),
);
});
}

0 comments on commit 9f89dae

Please sign in to comment.