Added Expansiontile for comments

main
Kai Mannweiler 2023-03-06 14:55:56 +01:00
parent ad6e890f57
commit 5177d38b36
6 changed files with 90 additions and 33 deletions

View File

@ -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),
)
],
);
}
}

View File

@ -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) {
return Card(
child: ListTile(
shape: RoundedRectangleBorder(
final Icon icon = Icon(iconData, color: Colors.white);
final ShapeBorder shape = RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
leading: Icon(icon, color: Colors.white),
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
);
final Color color = Theme.of(context).colorScheme.primary.withOpacity(0.8);
final Widget title = EntryDetailTitle(date: date, entryData: entryData);
return Card(
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(
DateFormat.MMMd('de').format(date),
style: const TextStyle(
color: Colors.white, fontWeight: FontWeight.bold),
),
Text(
entryData,
entryComment ?? '',
style: const TextStyle(
color: Colors.white, fontWeight: FontWeight.bold),
)
],
),
tileColor: Theme.of(context).colorScheme.primary.withOpacity(0.8),
]
: [],
)
: ListTile(
shape: shape,
leading: icon,
title: title,
tileColor: color,
));
}
}

View File

@ -6,6 +6,7 @@ class HistoryList<T> 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<T> 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<T> 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<T> extends StatelessWidget {
return EntryDetail(
date: dateSelector(entry),
entryData: entryDataSelector(entry),
icon: _getIcon(entry));
entryComment: _getComment(entry),
iconData: _getIcon(entry));
}).toList()));
}
}

View File

@ -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,

View File

@ -10,11 +10,15 @@ class RelapseView extends StatelessWidget {
@override
Widget build(BuildContext context) {
TasksProvider tasksModel = context.watch<TasksProvider>();
return HistoryList<Relapse>(
return Column(children: [
HistoryList<Relapse>(
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,
);
)
]);
}
}

View File

@ -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,
)
],