feat: sort meals

main
98spag 2023-06-16 12:17:23 +02:00
parent 98b45aabca
commit 2e22914cc2
2 changed files with 5 additions and 3 deletions

View File

@ -14,14 +14,15 @@ class FoodComponent extends StatelessWidget {
return ValueListenableBuilder( return ValueListenableBuilder(
valueListenable: box.listenable(), valueListenable: box.listenable(),
builder: (context, box, widget) { builder: (context, box, widget) {
final mealTypes = ['FRÜHSTÜCK','MITTAGESSEN','ABENDESSEN']; // Specify the desired orde
return ListView.builder( return ListView.builder(
primary: false, primary: false,
shrinkWrap: true, shrinkWrap: true,
itemCount: box.keys.length, itemCount: box.keys.length,
itemBuilder: (context, i) { itemBuilder: (context, i) {
return CardComponent( return CardComponent(
eatingMealName: box.keyAt(i).toString(), eatingMealName: mealTypes[i],
selectedMeal: castDynamicToListFood(box.getAt(i)), selectedMeal: castDynamicToListFood(box.get(mealTypes[i])),
addButtonVisible: box.name != StatisticsService.instance.todayStatisticsBoxName.toLowerCase(), addButtonVisible: box.name != StatisticsService.instance.todayStatisticsBoxName.toLowerCase(),
); );
} }

View File

@ -16,12 +16,13 @@ class MealsComponent extends StatelessWidget {
return ValueListenableBuilder( return ValueListenableBuilder(
valueListenable: Hive.box(dotenv.env['MEALPLAN_BOX'] ?? 'MEALPLAN').listenable(), valueListenable: Hive.box(dotenv.env['MEALPLAN_BOX'] ?? 'MEALPLAN').listenable(),
builder: (context, box, widget) { builder: (context, box, widget) {
final mealTypes = ['FRÜHSTÜCK','MITTAGESSEN','ABENDESSEN']; // Specify the desired order of meal types
return ListView.builder( return ListView.builder(
primary: false, primary: false,
shrinkWrap: true, shrinkWrap: true,
itemCount: box.keys.length, itemCount: box.keys.length,
itemBuilder: (context, i) { itemBuilder: (context, i) {
String mealTypeAsString = box.keyAt(i).toString(); String mealTypeAsString = mealTypes[i];
return CardComponent( return CardComponent(
mealTypeAsString, mealTypeAsString,
StatisticsService.instance.getMealsOfTodayByMealtype(mealTypeAsString), StatisticsService.instance.getMealsOfTodayByMealtype(mealTypeAsString),