Let's assume we have a Model class like this:
`class add_ingredients_list {
String? Ingredient_name;
String? Ingredient_mass;
String? Ingredient_mass_unit;
add_ingredients_list(
this.Ingredient_name,
this.Ingredient_mass,
this.Ingredient_mass_unit,
);
}`
and this List<add_ingredients_list> added_ingredients_list = [];
now I want to use a function to add Models to this list based on variables for
Ingredient_name,
Ingredient_mass,
Ingredient_mass_unit
can anyone give me a sample Code snipped with random values? How the function would look like?
If you want to simply add Models to this list based on variables, you can create a function like this:
void addIngredients(){
List<add_ingredients_list> added_ingredients_list = [];
add_ingredients_list instance1 = add_ingredients_list("Ingredient1Name", "IngredientMass", "IngredientUnit") //create an example instance of the class
added_ingredients_list.add(instance1);
}
If you want to get the list, you can make the function type of List<add_ingredients_list> and return your list.
If you want to say retrieve values and then add, you can add parameters to your function and then use those values in that instance created.
void addIngredients(String? name, String? mass, String? massUnit)
{
//add these values to the list
}
Note, this is just a very basic example of it. If you want a specific solution, you would need to provide more context for your problem.