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
pls help..
CodePudding user response:
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?
CodePudding user response:
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()