flutter_form_builder
flutter_form_builder copied to clipboard
[FormBuilderDropdown] selectedItemBuilder property is broken
Bug in FormBuilderDropdown when using the selectedItemBuilder
property.
Example Dropdown component:
return FormBuilderDropdown(
name: 'groupBy',
decoration: InputDecoration(labelText: 'Group By'),
onChanged: (dynamic value) => this.onChanged(value as HoldingGroupOption),
initialValue: grouping,
hint: Text('Group By'),
// validator: FormBuilderValidators.compose([FormBuilderValidators.required(context)]),
items: items,
selectedItemBuilder: (_) => [
Text('test')
],
);
Error thrown:
The following assertion was thrown during paint():
'package:flutter/src/rendering/stack.dart': Failed assertion: line 716 pos 12: 'i == index': is not true.
Error does not appear when property is not present.
@WilliamCunhaCardoso, try to do something like this.
selectedItemBuilder: (_) => items
.map((e) => Text(
e.toString(),
))
.toList(),
Docs got example:
/// This sample shows a DropdownButton
with a dropdown button text style
/// that is different than its menu items.
///
List<String> options = <String>['One', 'Two', 'Free', 'Four'];
String dropdownValue = 'One';
@override
Widget build(BuildContext context) {
return Container(
alignment: Alignment.center,
color: Colors.blue,
child: DropdownButton<String>(
value: dropdownValue,
onChanged: (String newValue) {
setState(() {
dropdownValue = newValue;
});
},
style: TextStyle(color: Colors.blue),
selectedItemBuilder: (BuildContext context) {
return options.map((String value) {
return Text(
dropdownValue,
style: TextStyle(color: Colors.white),
);
}).toList();
},
items: options.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
);
}
Hi @socialviolation The solution of @coccyx-cyst works for you?
Due to lack of response, I will close this issue. If the bug still exists, feel free to open a new issue