Reputation: 143
So, here's the thing, I have class something like this with 81 Strings:
class Dinner{
static String drinks = "Coctail";
static String food1 = "pizza";
static String food2 = "Meat Ball";
static String desserts = "Cake";
..
..
..
..
..
[81 Strings]
}
User Selects one item from the drop down, this dropdown has all the above Strings like drinks,food1,food2,desserts
Now, I need to add this selected items values to the database, eg. if user selects "drinks" then i need to add "cocktail", to the database.
My DB post call looks something Like this:
await http.post(
body: jsonEncode({
"item": Dinner.drinks,
})
);
here in, "Dinner.drinks", drinks will change dynamically, because if user selects food1, then it be taken as "Dinner.food1"
Is these a way to insert data dynamically according the selection from dropdown?
Upvotes: 1
Views: 44
Reputation: 31219
It seems like your problem can be solved by rethinking the data structure. I don't know the full use case of this but it seems to be a case where a Map<String, String>
would fit (maybe combined with an enum as key).
Another good thing about Map
is that it is a lot easier to iterate over all the key-value pairs with e.g. yourMap.entries
.
Upvotes: 1