0

I have a dropdown button consisting of names of the days of a week. When i click on any day from the dropdown then the data corresponding to that day is fetched without any problem. But when i try to change the option like if i select monday first the data is shown then i again click the dropdown and select another day the data corresponding to it is not fetched. How to fix it?.

Here is my code

class messDiary extends StatefulWidget {
  messDiary({Key? key}) : super(key: key) {}

  @override
  State<messDiary> createState() => _messDiaryState();
}

class _messDiaryState extends State<messDiary> {
  String valueChoose = 'Select a day';

  final DocumentReference _collectListData =
      FirebaseFirestore.instance.collection('messdiary').doc('days');

  late Stream<DocumentSnapshot> _streamCollectList;
  @override
  void initState() {
    super.initState();
    whatIsToday = DateFormat('EEEE').format(DateTime.now());
    _streamCollectList = _collectListData.snapshots();
  }

  @override
  Widget build(BuildContext context) {
   return Scaffold(
  child: AwesomeDropDown(
                dropDownList: const [
                  "Monday",
                  "Tuesday",
                  "Wednesday",
                  "Thursday",
                  "Friday",
                  "Saturday",
                  "Sunday"
                ],
                selectedItem: valueChoose,
                onDropDownItemClick: (selectedItem) {
                  setState(() {
                    valueChoose = selectedItem;
                  });
                },
                selectedItemTextStyle: const TextStyle(
                    color: Colors.white, fontWeight: FontWeight.bold),
                dropDownListTextStyle: const TextStyle(color: Colors.black),
                dropDownIcon: const Icon(
                  Icons.expand_circle_down,
                  color: Color(0xFF4A4C5C),
                ),
                dropDownBGColor: const Color(0xFF292A35),
              ),
              const SizedBox(
                height: 10,
              ),
              valueChoose == "Select a day"
                  ? const SizedBox()
                  : Container(
                      width: width * .95,
                      height: height * 0.4,
                      decoration: const BoxDecoration(
                          color: Color(0xFF292A35),
                          borderRadius: BorderRadius.all(Radius.circular(15))),
                      child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: StreamBuilder<DocumentSnapshot>(
                            stream: _streamCollectList,
                            builder: (context,
                                AsyncSnapshot<DocumentSnapshot> snapshot) {
                              if (!snapshot.hasData) {
                                return const Center(
                                  child: CircularProgressIndicator(),
                                );
                              }
                              var otherSnaps = snapshot.data!;
                              return ListView.separated(
                                physics: const NeverScrollableScrollPhysics(),
                                itemBuilder: (context, index) {
                                  var allDayMeals = otherSnaps[valueChoose]
                                      .map(
                                        (e) => ThisDaysItems(
                                          dayTime: e['daytime'],
                                          meal: e['title'],
                                        ),
                                      )
                                      .toList();
                                  final List<ThisDaysItems> mealsData = [
                                    ...allDayMeals
                                  ];
                                  final itemName = mealsData[index];
                                  return MealDayList(
                                      daytime: itemName.dayTime,
                                      meal: itemName.meal);
                                },
                                itemCount: 4,
                                separatorBuilder:
                                    (BuildContext context, int index) {
                                  return const Divider(
                                    color: Colors.white12,
                                  );
                                },
                              );
                            }),
   );
   }
   }

This is my app list image(s)

  1. Initial stage when nothing is selected

sample screen of my apps list

2.when i select monday for first time

monday selected

  1. when tuesday selected nothing is changing same list

tuesday is selected

Hexated
  • 3
  • 4

0 Answers0