I am unable to resolve this error. I have implemented a custom drop down and it generate this error
DropDownWidget( list: ["Patient","HouseholdMember","Communityrepresentative","Other"], data: whofollowUp, hint: getTranslated(context, "select"), heading: getTranslated(context, "followup_patient"), ),
the custom drop down that is generating this error and I don't have the option to use the default one that comes with flutter
class DropDownWidget extends StatelessWidget { final ValueNotifier<dynamic> data; final String heading; final List<String> list; final String hint; final bool showPadding; final Color outlineColor; final Function onChange; final bool isDecode; DropDownWidget( {Key key, this.data, this.heading, this.list, this.outlineColor = const Color(0xffC4C4C4), this.hint, this.onChange, this.isDecode = false, this.showPadding = true}) : super(key: key); @override Widget build(BuildContext context) { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Padding( padding: const EdgeInsets.only(bottom: 8.0, left: 8), child: Text( heading, style: TextStyle( color: AppColor.primarypurple, fontSize: 14, fontWeight: FontWeight.w500), ), ), Container( height: 40, padding: EdgeInsets.only(left: 8, right: 8), width: ResponsiveSize.sizeWidth(context), decoration: BoxDecoration( color: AppColor.backGrey, borderRadius: BorderRadius.circular(10), border: Border.all(width: 2, color: AppColor.darkBlue)), child: ValueListenableBuilder( valueListenable: data, builder: (ctx, value, child) => DropdownButtonHideUnderline( child: DropdownButton( isExpanded: true, items: list.map((var val) { return new DropdownMenuItem( value: isDecode ? ((jsonDecode(val))["id"]).toString() : val, child: new Text( isDecode ? ((jsonDecode(val))["name"]).toString(): val, maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle( fontSize: 14, color: AppColor.primaryColor, fontWeight: FontWeight.w600), ), ); }).toList(), // hint: Text( // hint, // maxLines: 1, // overflow: TextOverflow.ellipsis, // style: TextStyle( // fontSize: 14, // color: AppColor.darkBlue, // fontWeight: FontWeight.w400), // ), value: value, icon: Icon( Icons.keyboard_arrow_down, color: AppColor.darkBlue, ), onChanged: onChange == null ? (newVal) { data.value = newVal; } : (newVal) { data.value = newVal; onChange(); }), ), ), ), const SizedBox( height: 15, ) ], ); } }
This is a custom drop down which I am trying to use it in my class and it is giving this error which I am unable to resolve
It seems that you have a repetitive (or no matched) value for your dropdown items. One of these 4 solutions would be helpful (check them as follow):
value:isDecode ? ((jsonDecode(val))["id"]).toString() :val,
isDecode
is false and you have a REPETITIVE element in your list!value
parameter. In the other words maybe it does not match with any item's value:value: value,
check it out and let me know the result.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.