diff --git a/lib/main.dart b/lib/main.dart index 441d2ef..c97aa54 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -23,8 +23,9 @@ class Recipe { String name; Cuisine cuisine; List ingredients; + String imageUrl; - Recipe({required this.name, required this.cuisine, required this.ingredients}); + Recipe({required this.name, required this.cuisine, required this.ingredients, required this.imageUrl}); String getDetails() { return 'Рецепт: $name\nКухня: ${cuisine.toString().split('.').last}\nИнгредиенты: ${ingredients.join(', ')}'; @@ -66,17 +67,20 @@ class _RecipeHomeState extends State { final RecipeManager _recipeManager = RecipeManager(); final TextEditingController _nameController = TextEditingController(); final TextEditingController _ingredientsController = TextEditingController(); + final TextEditingController _imageUrlController = TextEditingController(); Cuisine? _selectedCuisine; void _addRecipe() { final name = _nameController.text; final ingredients = _ingredientsController.text.split(',').map((s) => s.trim()).toList(); + final imageUrl = _imageUrlController.text; - if (name.isNotEmpty && ingredients.isNotEmpty && _selectedCuisine != null) { - final recipe = Recipe(name: name, cuisine: _selectedCuisine!, ingredients: ingredients); + if (name.isNotEmpty && ingredients.isNotEmpty && _selectedCuisine != null && imageUrl.isNotEmpty) { + final recipe = Recipe(name: name, cuisine: _selectedCuisine!, ingredients: ingredients, imageUrl: imageUrl); _recipeManager.addRecipe(recipe).then((_) { _nameController.clear(); _ingredientsController.clear(); + _imageUrlController.clear(); _selectedCuisine = null; setState(() {}); }); @@ -114,6 +118,10 @@ class _RecipeHomeState extends State { controller: _ingredientsController, decoration: InputDecoration(labelText: 'Ингредиенты (через запятую)'), ), + TextField( + controller: _imageUrlController, + decoration: InputDecoration(labelText: 'URL изображения'), + ), SizedBox(height: 20), ElevatedButton( onPressed: _addRecipe, @@ -126,7 +134,10 @@ class _RecipeHomeState extends State { itemBuilder: (context, index) { final recipe = _recipeManager.getRecipeAt(index); return ListTile( - title: Text(recipe?.name ?? 'Имеется ошибка'), + leading: recipe != null && recipe.imageUrl.isNotEmpty + ? Image.network(recipe.imageUrl, width: 50, height: 50, fit: BoxFit.cover) + : null, + title: Text(recipe?.name ?? 'Ошибка'), subtitle: Text(recipe?.getDetails() ?? ''), ); }, @@ -137,5 +148,4 @@ class _RecipeHomeState extends State { ), ); } - } \ No newline at end of file