mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
get ready to support showing images in the ingredient preview
note: the image doesn't seem to be set yet, but at least the UI is now ready for it
This commit is contained in:
@@ -368,9 +368,9 @@ class _IngredientLogFormState extends State<IngredientLogForm> {
|
||||
builder: (BuildContext context, AsyncSnapshot<Ingredient> snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
_mealItem.ingredient = snapshot.data!;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 16),
|
||||
child:
|
||||
return ListTile(
|
||||
leading: IngredientAvatar(ingredient: _mealItem.ingredient),
|
||||
title:
|
||||
Text(getShortNutritionValues(_mealItem.nutritionalValues, context)),
|
||||
);
|
||||
} else if (snapshot.hasError) {
|
||||
|
||||
@@ -20,13 +20,11 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:wger/helpers/consts.dart';
|
||||
import 'package:wger/helpers/misc.dart';
|
||||
import 'package:wger/models/nutrition/log.dart';
|
||||
import 'package:wger/models/nutrition/meal.dart';
|
||||
import 'package:wger/models/nutrition/meal_item.dart';
|
||||
import 'package:wger/providers/nutrition.dart';
|
||||
import 'package:wger/screens/form_screen.dart';
|
||||
import 'package:wger/widgets/core/core.dart';
|
||||
import 'package:wger/widgets/nutrition/charts.dart';
|
||||
import 'package:wger/widgets/nutrition/forms.dart';
|
||||
import 'package:wger/widgets/nutrition/helpers.dart';
|
||||
@@ -208,18 +206,7 @@ class MealItemWidget extends StatelessWidget {
|
||||
final values = _item.nutritionalValues;
|
||||
|
||||
return ListTile(
|
||||
leading: _item.ingredient.image != null
|
||||
? GestureDetector(
|
||||
child: CircleAvatar(backgroundImage: NetworkImage(_item.ingredient.image!.image)),
|
||||
onTap: () async {
|
||||
if (_item.ingredient.image!.objectUrl != '') {
|
||||
return launchURL(_item.ingredient.image!.objectUrl, context);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
},
|
||||
)
|
||||
: const CircleIconAvatar(Icon(Icons.image, color: Colors.grey)),
|
||||
leading: IngredientAvatar(ingredient: _item.ingredient),
|
||||
title: Text(
|
||||
'${_item.amount.toStringAsFixed(0)}$unit ${_item.ingredient.name}',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
@@ -273,18 +260,7 @@ class LogDiaryItemWidget extends StatelessWidget {
|
||||
final values = _item.nutritionalValues;
|
||||
|
||||
return ListTile(
|
||||
leading: _item.ingredient.image != null
|
||||
? GestureDetector(
|
||||
child: CircleAvatar(backgroundImage: NetworkImage(_item.ingredient.image!.image)),
|
||||
onTap: () async {
|
||||
if (_item.ingredient.image!.objectUrl != '') {
|
||||
return launchURL(_item.ingredient.image!.objectUrl, context);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
},
|
||||
)
|
||||
: const CircleIconAvatar(Icon(Icons.image, color: Colors.grey)),
|
||||
leading: IngredientAvatar(ingredient: _item.ingredient),
|
||||
title: Text(
|
||||
'${_item.amount.toStringAsFixed(0)}$unit ${_item.ingredient.name}',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
|
||||
@@ -25,9 +25,11 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:wger/helpers/consts.dart';
|
||||
import 'package:wger/helpers/misc.dart';
|
||||
import 'package:wger/helpers/platform.dart';
|
||||
import 'package:wger/helpers/ui.dart';
|
||||
import 'package:wger/models/exercises/ingredient_api.dart';
|
||||
import 'package:wger/models/nutrition/ingredient.dart';
|
||||
import 'package:wger/models/nutrition/log.dart';
|
||||
import 'package:wger/models/nutrition/nutritional_plan.dart';
|
||||
import 'package:wger/providers/nutrition.dart';
|
||||
@@ -335,3 +337,23 @@ class NutritionDiaryEntry extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class IngredientAvatar extends StatelessWidget {
|
||||
final Ingredient ingredient;
|
||||
|
||||
const IngredientAvatar({super.key, required this.ingredient});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ingredient.image != null
|
||||
? GestureDetector(
|
||||
child: CircleAvatar(backgroundImage: NetworkImage(ingredient.image!.image)),
|
||||
onTap: () async {
|
||||
if (ingredient.image!.objectUrl != '') {
|
||||
return launchURL(ingredient.image!.objectUrl, context);
|
||||
}
|
||||
},
|
||||
)
|
||||
: const CircleIconAvatar(Icon(Icons.image, color: Colors.grey));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user