Flutter-Ernaehrungsapp/lib/android/components/card/card_data_food_component.dart

57 lines
2.0 KiB
Dart
Raw Normal View History

2023-05-29 22:04:44 +02:00
import 'package:ernaehrung/android/components/card/card_food_item_component.dart';
import 'package:ernaehrung/android/models/food.dart';
import 'package:flutter/material.dart';
2023-06-02 20:02:32 +02:00
import '../../config/format_helper.dart';
2023-05-29 22:04:44 +02:00
class CardDataFoodComponent extends StatelessWidget {
final List<Food> foods;
2023-06-02 19:21:06 +02:00
final Color color;
2023-05-29 22:04:44 +02:00
2023-06-02 19:21:06 +02:00
const CardDataFoodComponent(this.foods,this.color, {Key? key,}) : super(key: key);
2023-05-29 22:04:44 +02:00
@override
Widget build(BuildContext context) {
2023-06-02 19:21:06 +02:00
return Padding(
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 8),
child: foods.isNotEmpty ?
Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
ListView.builder(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
2023-06-02 20:02:32 +02:00
itemCount: getMapOfDistinctElementsWithCounterAndCalories(
foods)
.keys
.length,
2023-06-02 19:21:06 +02:00
itemBuilder: (context, i) {
2023-06-02 20:02:32 +02:00
Map<String, List<int>> map =
getMapOfDistinctElementsWithCounterAndCalories(
foods);
String foodName = map.keys.elementAt(i);
List<int> values = map.values.elementAt(i);
2023-06-02 19:21:06 +02:00
return Column(
children: [
2023-06-02 20:02:32 +02:00
CardFoodItemComponent(foodName,values),
2023-06-02 19:21:06 +02:00
Divider(
color: Colors.grey.shade300,
thickness: 1.2,
)
],
);
})
],
)
: const Center(
child: Text(
"Füge jetzt neue Gerichte hinzu!",
style: TextStyle(
fontSize: 14,
color: Colors.white
),
)
2023-06-02 19:21:06 +02:00
));
2023-05-29 22:04:44 +02:00
}
}