Skip to content

Commit

Permalink
Merge pull request #245 from AhmedLSayed9/feature/value_and_multi_val…
Browse files Browse the repository at this point in the history
…ue_listenables

Introduce valueListenable and multiValueListenable
  • Loading branch information
AhmedLSayed9 authored Mar 9, 2024
2 parents 6310ff3 + b5faa4c commit 3c29b93
Show file tree
Hide file tree
Showing 17 changed files with 303 additions and 239 deletions.
159 changes: 80 additions & 79 deletions README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import 'package:dropdown_button2/dropdown_button2.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

class CustomDropdownButton2 extends StatelessWidget {
const CustomDropdownButton2({
required this.hint,
required this.value,
required this.valueListenable,
required this.dropdownItems,
required this.onChanged,
this.selectedItemBuilder,
Expand Down Expand Up @@ -33,7 +34,7 @@ class CustomDropdownButton2 extends StatelessWidget {
super.key,
});
final String hint;
final String? value;
final ValueListenable<String?>? valueListenable;
final List<String> dropdownItems;
final ValueChanged<String?>? onChanged;
final DropdownButtonBuilder? selectedItemBuilder;
Expand Down Expand Up @@ -76,7 +77,7 @@ class CustomDropdownButton2 extends StatelessWidget {
),
),
),
value: value,
valueListenable: valueListenable,
items: dropdownItems
.map((String item) => DropdownItem<String>(
value: item,
Expand Down
10 changes: 4 additions & 6 deletions packages/dropdown_button2/example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class _MyHomePageState extends State<MyHomePage> {
'Item7',
'Item8',
];
String? selectedValue;
final valueListenable = ValueNotifier<String?>(null);

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -82,11 +82,9 @@ class _MyHomePageState extends State<MyHomePage> {
),
))
.toList(),
value: selectedValue,
onChanged: (String? value) {
setState(() {
selectedValue = value;
});
valueListenable: valueListenable,
onChanged: (value) {
valueListenable.value = value;
},
buttonStyleData: ButtonStyleData(
height: 50,
Expand Down
Loading

0 comments on commit 3c29b93

Please sign in to comment.