Dropdown is not changing value on onChanged

  Kiến thức lập trình

I am fetching my firestore data and showing it in a dropdown list but in that list when i click on any item then the value or we can say hint text of dropdown doesn’t change.

StreamBuilder<QuerySnapshot>(stream: compDoc.snapshots(),builder: (context, snapshot) {String? selectedValue;if (snapshot.hasError) {return Center(child: Text("Some error occurred ${snapshot.error}"),);}List<DropdownMenuItem> compItems = [];if (!snapshot.hasData) {return const CircularProgressIndicator();} else {final selectComp = snapshot.data?.docs.toList();if (selectComp != null) {`

`    for (var comp in selectComp) {
      compItems.add(
        DropdownMenuItem(
          value: comp['name'],
          child: Text(
            comp['name'],
          ),
        ),
      );
    }
  }
  return Padding(
    padding: const EdgeInsets.all(10.0),
    child: Container(
      padding: const EdgeInsets.only(right: 15, left: 15),
      decoration: BoxDecoration(
        border: Border.all(color: Colors.grey, width: 1),
        borderRadius: BorderRadius.circular(15),
      ),
      child: DropdownButton(
        underline: const SizedBox(),
        isExpanded: true,
        hint: Text(
          "Select items",
          style: TextStyle(fontSize: 20),
        ),
        value: selectedValue,
        items: compItems,
        onChanged: (value) {
          setState(() {
            selectedValue = value;
            print(selectedValue);
          });
        },
      ),
    ),
  );
}

Kindly someone help me.. i am stuck with that thing

New contributor

Anees Dahot is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT