diff --git a/lib/widgets/entry_detail_widget.dart b/lib/widgets/entry_detail_widget.dart index efa70cd..10afacc 100644 --- a/lib/widgets/entry_detail_widget.dart +++ b/lib/widgets/entry_detail_widget.dart @@ -19,7 +19,7 @@ class EntryDetail extends StatelessWidget { shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10.0), ), - leading: const Icon(Icons.local_airport, color: Colors.white), + leading: Icon(icon, color: Colors.white), title: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ diff --git a/lib/widgets/history_list_widget.dart b/lib/widgets/history_list_widget.dart index dab25cf..6996f6a 100644 --- a/lib/widgets/history_list_widget.dart +++ b/lib/widgets/history_list_widget.dart @@ -5,12 +5,25 @@ class HistoryList extends StatelessWidget { final List history; final DateTime Function(T) dateSelector; final String Function(T) entryDataSelector; + final IconData Function(T)? iconDataSelector; + final IconData? icon; const HistoryList( {super.key, required this.history, required this.dateSelector, - required this.entryDataSelector}); + required this.entryDataSelector, + this.iconDataSelector, + this.icon}); + + IconData _getIcon(T entry) { + if (icon != null) { + return icon!; + } else if (iconDataSelector != null) { + return iconDataSelector!(entry); + } + return Icons.circle; + } @override Widget build(BuildContext context) { @@ -20,10 +33,9 @@ class HistoryList extends StatelessWidget { child: ListView( children: history.map((T entry) { return EntryDetail( - date: dateSelector(entry), - entryData: entryDataSelector(entry), - icon: Icons.bedtime_outlined, - ); + date: dateSelector(entry), + entryData: entryDataSelector(entry), + icon: _getIcon(entry)); }).toList())); } } diff --git a/lib/widgets/view_form/mood_view.dart b/lib/widgets/view_form/mood_view.dart index 02cb557..92017f0 100644 --- a/lib/widgets/view_form/mood_view.dart +++ b/lib/widgets/view_form/mood_view.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import 'package:smoke_cess_app/widgets/history_list_widget.dart'; import 'package:smoke_cess_app/widgets/line_chart_widget.dart'; import 'package:syncfusion_flutter_charts/charts.dart'; import 'package:smoke_cess_app/models/mood.dart'; @@ -20,10 +21,14 @@ class MoodView extends StatelessWidget { xValueMapper: (Mood value, _) => value.date, yValueMapper: (Mood value, _) => value.moodValue) ]), - Column( - children: tasksModel.moodHistory.map((mood) { - return Text('${mood.date}: ${mood.moodValue}'); - }).toList()) + HistoryList( + history: tasksModel.moodHistory, + dateSelector: (Mood mood) => mood.date, + entryDataSelector: (Mood mood) => 'Stimmung: ${mood.moodValue}', + 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 2480640..92072f4 100644 --- a/lib/widgets/view_form/relapse_view.dart +++ b/lib/widgets/view_form/relapse_view.dart @@ -1,17 +1,20 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import 'package:smoke_cess_app/models/relapse.dart'; import 'package:smoke_cess_app/providers/tasks_provider.dart'; +import 'package:smoke_cess_app/widgets/history_list_widget.dart'; class RelapseView extends StatelessWidget { const RelapseView({super.key}); @override Widget build(BuildContext context) { - var tasksModel = context.watch(); - return Column( - mainAxisAlignment: MainAxisAlignment.center, - children: tasksModel.relapseHistory.map((relapse) { - return Text('${relapse.date}: ${relapse.category}'); - }).toList()); + 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, + ); } } diff --git a/lib/widgets/view_form/sleep_view.dart b/lib/widgets/view_form/sleep_view.dart index 33b610c..4e1e90d 100644 --- a/lib/widgets/view_form/sleep_view.dart +++ b/lib/widgets/view_form/sleep_view.dart @@ -1,7 +1,6 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:smoke_cess_app/models/sleep.dart'; -import 'package:smoke_cess_app/widgets/entry_detail_widget.dart'; import 'package:smoke_cess_app/widgets/history_list_widget.dart'; import 'package:smoke_cess_app/widgets/line_chart_widget.dart'; import 'package:smoke_cess_app/providers/tasks_provider.dart'; @@ -24,11 +23,13 @@ class SleepView extends StatelessWidget { yValueMapper: (Sleep value, _) => value.sleepQualitiyValue) ], ), - HistoryList( - history: tasksModel.sleepHistory, - dateSelector: (Sleep sleep) => sleep.date, - entryDataSelector: (Sleep sleep) => - '${sleep.sleepDuration.hour}:${sleep.sleepDuration.minute}') + HistoryList( + history: tasksModel.sleepHistory, + dateSelector: (Sleep sleep) => sleep.date, + entryDataSelector: (Sleep sleep) => + '${sleep.sleepDuration.hour}:${sleep.sleepDuration.minute}', + icon: Icons.bedtime_outlined, + ) ], ); }