From 5177d38b36eceb0f355d5e2b68f364b42dcafd63 Mon Sep 17 00:00:00 2001 From: "k.mannweiler" <2012491@stud.hs-mannheim.de> Date: Mon, 6 Mar 2023 14:55:56 +0100 Subject: [PATCH] Added Expansiontile for comments --- lib/widgets/entry_detail_title.dart | 29 ++++++++++++ lib/widgets/entry_detail_widget.dart | 62 +++++++++++++++---------- lib/widgets/history_list_widget.dart | 14 +++++- lib/widgets/view_form/mood_view.dart | 1 + lib/widgets/view_form/relapse_view.dart | 16 ++++--- lib/widgets/view_form/sleep_view.dart | 1 + 6 files changed, 90 insertions(+), 33 deletions(-) create mode 100644 lib/widgets/entry_detail_title.dart diff --git a/lib/widgets/entry_detail_title.dart b/lib/widgets/entry_detail_title.dart new file mode 100644 index 0000000..4bdff97 --- /dev/null +++ b/lib/widgets/entry_detail_title.dart @@ -0,0 +1,29 @@ +import 'package:flutter/material.dart'; +import 'package:intl/intl.dart'; + +class EntryDetailTitle extends StatelessWidget { + final DateTime date; + final String entryData; + + const EntryDetailTitle( + {super.key, required this.date, required this.entryData}); + + @override + Widget build(BuildContext context) { + return Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + Text( + DateFormat.MMMd('de').format(date), + style: + const TextStyle(color: Colors.white, fontWeight: FontWeight.bold), + ), + Text( + entryData, + style: + const TextStyle(color: Colors.white, fontWeight: FontWeight.bold), + ) + ], + ); + } +} diff --git a/lib/widgets/entry_detail_widget.dart b/lib/widgets/entry_detail_widget.dart index 10afacc..c1585f7 100644 --- a/lib/widgets/entry_detail_widget.dart +++ b/lib/widgets/entry_detail_widget.dart @@ -1,41 +1,53 @@ import 'package:flutter/material.dart'; -import 'package:intl/intl.dart'; +import 'package:smoke_cess_app/widgets/entry_detail_title.dart'; class EntryDetail extends StatelessWidget { final DateTime date; final String entryData; - final IconData icon; + final String? entryComment; + final IconData iconData; const EntryDetail( {super.key, required this.date, required this.entryData, - required this.icon}); + required this.iconData, + required this.entryComment}); @override Widget build(BuildContext context) { + final Icon icon = Icon(iconData, color: Colors.white); + final ShapeBorder shape = RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10.0), + ); + final Color color = Theme.of(context).colorScheme.primary.withOpacity(0.8); + final Widget title = EntryDetailTitle(date: date, entryData: entryData); return Card( - child: ListTile( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(10.0), - ), - leading: Icon(icon, color: Colors.white), - title: Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - Text( - DateFormat.MMMd('de').format(date), - style: const TextStyle( - color: Colors.white, fontWeight: FontWeight.bold), - ), - Text( - entryData, - style: const TextStyle( - color: Colors.white, fontWeight: FontWeight.bold), - ) - ], - ), - tileColor: Theme.of(context).colorScheme.primary.withOpacity(0.8), - )); + child: entryComment != null + ? ExpansionTile( + iconColor: color, + collapsedShape: shape, + shape: shape, + leading: icon, + title: title, + collapsedBackgroundColor: color, + backgroundColor: + Theme.of(context).colorScheme.secondary.withOpacity(0.8), + children: entryComment != null + ? [ + Text( + entryComment ?? '', + style: const TextStyle( + color: Colors.white, fontWeight: FontWeight.bold), + ) + ] + : [], + ) + : ListTile( + shape: shape, + leading: icon, + title: title, + tileColor: color, + )); } } diff --git a/lib/widgets/history_list_widget.dart b/lib/widgets/history_list_widget.dart index ff63e49..8a32963 100644 --- a/lib/widgets/history_list_widget.dart +++ b/lib/widgets/history_list_widget.dart @@ -6,6 +6,7 @@ class HistoryList extends StatelessWidget { final DateTime Function(T) dateSelector; final String Function(T) entryDataSelector; final IconData Function(T)? iconDataSelector; + final String Function(T)? entryCommentSelector; final IconData? icon; const HistoryList( @@ -14,7 +15,8 @@ class HistoryList extends StatelessWidget { required this.dateSelector, required this.entryDataSelector, this.iconDataSelector, - this.icon}); + this.icon, + this.entryCommentSelector}); IconData _getIcon(T entry) { if (icon != null) { @@ -25,6 +27,13 @@ class HistoryList extends StatelessWidget { return Icons.circle; } + String? _getComment(T entry) { + if (entryCommentSelector != null) { + return entryCommentSelector!(entry); + } + return null; + } + @override Widget build(BuildContext context) { return Expanded( @@ -33,7 +42,8 @@ class HistoryList extends StatelessWidget { return EntryDetail( date: dateSelector(entry), entryData: entryDataSelector(entry), - icon: _getIcon(entry)); + entryComment: _getComment(entry), + iconData: _getIcon(entry)); }).toList())); } } diff --git a/lib/widgets/view_form/mood_view.dart b/lib/widgets/view_form/mood_view.dart index 92017f0..3438f59 100644 --- a/lib/widgets/view_form/mood_view.dart +++ b/lib/widgets/view_form/mood_view.dart @@ -25,6 +25,7 @@ class MoodView extends StatelessWidget { history: tasksModel.moodHistory, dateSelector: (Mood mood) => mood.date, entryDataSelector: (Mood mood) => 'Stimmung: ${mood.moodValue}', + entryCommentSelector: (Mood mood) => 'Kommentar: ${mood.comment}', iconDataSelector: (Mood mood) => mood.moodValue >= 50 ? Icons.mood_outlined : Icons.mood_bad_outlined, diff --git a/lib/widgets/view_form/relapse_view.dart b/lib/widgets/view_form/relapse_view.dart index 92072f4..ab70de8 100644 --- a/lib/widgets/view_form/relapse_view.dart +++ b/lib/widgets/view_form/relapse_view.dart @@ -10,11 +10,15 @@ class RelapseView extends StatelessWidget { @override Widget build(BuildContext context) { TasksProvider tasksModel = context.watch(); - return HistoryList( - history: tasksModel.relapseHistory, - dateSelector: (Relapse relapse) => relapse.date, - entryDataSelector: (Relapse relapse) => 'Grund: ${relapse.category}', - icon: Icons.smoke_free_outlined, - ); + return Column(children: [ + HistoryList( + history: tasksModel.relapseHistory, + dateSelector: (Relapse relapse) => relapse.date, + entryDataSelector: (Relapse relapse) => 'Grund: ${relapse.category}', + entryCommentSelector: (Relapse relapse) => + 'Kommentar: ${relapse.comment}', + icon: Icons.smoke_free_outlined, + ) + ]); } } diff --git a/lib/widgets/view_form/sleep_view.dart b/lib/widgets/view_form/sleep_view.dart index 4e1e90d..e53837c 100644 --- a/lib/widgets/view_form/sleep_view.dart +++ b/lib/widgets/view_form/sleep_view.dart @@ -28,6 +28,7 @@ class SleepView extends StatelessWidget { dateSelector: (Sleep sleep) => sleep.date, entryDataSelector: (Sleep sleep) => '${sleep.sleepDuration.hour}:${sleep.sleepDuration.minute}', + entryCommentSelector: (Sleep sleep) => 'Kommentar: ${sleep.comment}', icon: Icons.bedtime_outlined, ) ],