DropdownButton cause null item exception

2020-01-26T09:35:20

DropdownButton cause null exception as i am passing string variable in value name parameter.

  String diseases = "Select a disease";

DropdownButton<String>(
    value: diseases,
    items: model.diseases
   .map((String value) {
    return DropdownMenuItem<
    String>(
    value: value,
    child: Text(value),
     );
     }).toList(),
     onChanged: (d) {
     setState(() {
     diseases = d;
     print(
     diseases.toString());
     });
     },
     )

It works fine if I used first selected element from the array value: diseases, by value: model.diseases[0], and it also works fine if I hotreload after changing model.diseases[0] to "diseases" in value

════════ Exception Caught By widgets library ═══════════════════════════════════ The following assertion was thrown building Builder(dirty): 'package:flutter/src/material/dropdown.dart': Failed assertion: line 608 pos 15: 'items == null || items.isEmpty || value == null || items.where((DropdownMenuItem item) => item.value == value).length == 1': is not true.

Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause. In either case, please report this assertion by filing a bug on GitHub:
https://github.com/flutter/flutter/issues/new?template=BUG.md

Copyright License:
Author:「M.ArslanKhan」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.
Link to:https://stackoverflow.com/questions/59914891/dropdownbutton-cause-null-item-exception

About “DropdownButton cause null item exception” questions

DropdownButton cause null exception as i am passing string variable in value name parameter. String diseases = "Select a disease"; DropdownButton&lt;String&gt;( value: diseases, items:...
Multiple Dynamic Dependent Dropdown List it's working good untel change First DropdownButton selection i found an error &quot;Exception has occurred. _AssertionError ('package:flutter/src/material/
I was trying to implement dropdownbutton in a flutter project.Dropdownbutton list will be populated from api. I have fetched the list from api. But when I select an item, it is not showing. The e...
in this simple DropdownButton widget when i select one item, items refreshed and select value is first item of SessionsEntity list items, and i can't select another item,selecting them cause of sel...
body: Center( child: DropdownButton( items: [&quot;bad &quot;, &quot;good &quot;, &quot;ok&quot;, &quot;sad&quot;, &quot;happy&quot;] .map((e) =&gt; DropdownMenuItem..
Exception has occurred. _AssertionError ('package: flutter/src/material/dropdown.dart': Failed assertion: line 915 pos 15: 'items == null || items.isEmpty || value == null || items.where((
I am having trouble to use DropdownButton and TextEditingController at the same time. I am trying to take the user form data in a screen with text entries, parsing the data i received and sending it
I'm back with another issue with the DropdownButton. The DropdownButton is not enabled. I found this in api.flutter.dev If the onChanged callback is null or the list of items is null then the drop...
If someone can please help me with this issue. So I am able to fetch and insert into the dropdownbuttons using the code below. If i select the first dropdown then the list shows accordingly for the
I am trying to put a DropdownButton on one of my screens. I have followed several examples but I can not get it to show the selected item. It keeps showing the first item in the list. String _trxnS...

Copyright License:Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.