skip to Main Content

this is my cod

This is the list that i created….

final List<ThisDaysItems> daysMealList = [
  ThisDaysItems(
      dayName: "Monday",
      breakfast: "Upma & kadala curry",
      lunch: "Rice & Fish fry",
      snacks: "Bun & tea",
      dinner: "Rice & Chicken curry"),
  ThisDaysItems(
      dayName: "Tuesday",
      breakfast: "Upma & kadala curry",
      lunch: "Rice & Fish fry",
      snacks: "Bun & tea",
      dinner: "Rice & Chicken curry"),
];

This is the Dropdown I am using..

AwesomeDropDown(
  dropDownList: const [
    "Monday",
    ...
  ],
  selectedItem: valueChoose,
  onDropDownItemClick: (selectedItem) {
    setState(() {
      valueChoose = selectedItem;
    });
    if (valueChoose == "Monday") {
      setState(() {
        itemName = daysMealList[0];
      });
    } else if (valueChoose == "Tuesday") {
      setState(() {
        itemName = daysMealList[1];
      });
    }
    print(itemName.toString());
  },
),

this is the Listview.builder that I used to list. and in the listview, Mealdaylist is a refactored widget

 ListView.builder(
        itemBuilder: (context, index) {
          return MealDayList(
              dayName: itemName.dayName,
              breakfast: itemName.breakfast,
              lunch: itemName.lunch,
              snacks: itemName.snacks,
              dinner: itemName.dinner);
        },
        itemCount: 1,
      ),
    ),

I want to update contents(that from the list) according to the day selected in the dropdown list

This is how it looks like

pls help..

2

Answers


  1. simply use setState(() {itemIndex = 1;});. Then you can select the content above with whatever your data is like Text(meal[itemIndex].title). Does this answer your question, it is a bit vague about your precise issue?

    Login or Signup to reply.
  2. It’s hard to tell without a running snippet, but you can do the following:

    use .where() on your list to filter for the selected day:

    final selectedDay = daysMealList
                          .firstWhere((element) => element.dayName == value);
    

    And then return this in the ListView.builder()

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search