From 09ed4dc402c5e06dcb67c3e92b9e68b9d070838c Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Mon, 17 May 2021 18:22:37 +0200 Subject: [PATCH] Refactor calendar on dashboard The scrollable list view is now removed. There can't be that many different types of events for a single day anyway. --- lib/screens/dashboard.dart | 5 +-- lib/widgets/dashboard/calendar.dart | 50 +++++++++++++---------------- 2 files changed, 23 insertions(+), 32 deletions(-) diff --git a/lib/screens/dashboard.dart b/lib/screens/dashboard.dart index edefd740..03e42ddc 100644 --- a/lib/screens/dashboard.dart +++ b/lib/screens/dashboard.dart @@ -124,10 +124,7 @@ class _DashboardScreenState extends State { DashboardWorkoutWidget(), DashboardNutritionWidget(), DashboardWeightWidget(), - Container( - height: 650, // TODO: refactor calendar so we can get rid of size - child: DashboardCalendarWidget(), - ), + DashboardCalendarWidget(), ], ), ), diff --git a/lib/widgets/dashboard/calendar.dart b/lib/widgets/dashboard/calendar.dart index ac9eb94b..1e72a0b1 100644 --- a/lib/widgets/dashboard/calendar.dart +++ b/lib/widgets/dashboard/calendar.dart @@ -226,36 +226,30 @@ class _DashboardCalendarWidgetState extends State }, ), const SizedBox(height: 8.0), - Expanded( - child: ValueListenableBuilder>( - valueListenable: _selectedEvents, - builder: (context, value, _) { - return ListView.builder( - itemCount: value.length, - itemBuilder: (context, index) { - return Container( - width: double.infinity, - child: ListTile( - title: Text((() { - switch (value[index].type) { - case EventType.caloriesDiary: - return AppLocalizations.of(context)!.nutritionalDiary; + ValueListenableBuilder>( + valueListenable: _selectedEvents, + builder: (context, value, _) => Column( + children: [ + ...value + .map((event) => ListTile( + title: Text((() { + switch (event.type) { + case EventType.caloriesDiary: + return AppLocalizations.of(context)!.nutritionalDiary; - case EventType.session: - return AppLocalizations.of(context)!.workoutSession; + case EventType.session: + return AppLocalizations.of(context)!.workoutSession; - case EventType.weight: - return AppLocalizations.of(context)!.weight; - } - return value[index].description.toString(); - })()), - subtitle: Text(value[index].description.toString()), - onTap: () => print('${value[index]} tapped!'), - ), - ); - }, - ); - }, + case EventType.weight: + return AppLocalizations.of(context)!.weight; + } + return event.description.toString(); + })()), + subtitle: Text(event.description.toString()), + //onTap: () => print('$event tapped!'), + )) + .toList() + ], ), ), ],