diff --git a/lib/widgets/entry_detail_widget.dart b/lib/widgets/entry_detail_widget.dart new file mode 100644 index 0000000..efa70cd --- /dev/null +++ b/lib/widgets/entry_detail_widget.dart @@ -0,0 +1,41 @@ +import 'package:flutter/material.dart'; +import 'package:intl/intl.dart'; + +class EntryDetail extends StatelessWidget { + final DateTime date; + final String entryData; + final IconData icon; + + const EntryDetail( + {super.key, + required this.date, + required this.entryData, + required this.icon}); + + @override + Widget build(BuildContext context) { + return Card( + child: ListTile( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10.0), + ), + leading: const Icon(Icons.local_airport, 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), + )); + } +} diff --git a/lib/widgets/history_list_widget.dart b/lib/widgets/history_list_widget.dart new file mode 100644 index 0000000..dab25cf --- /dev/null +++ b/lib/widgets/history_list_widget.dart @@ -0,0 +1,29 @@ +import 'package:flutter/material.dart'; +import 'package:smoke_cess_app/widgets/entry_detail_widget.dart'; + +class HistoryList extends StatelessWidget { + final List history; + final DateTime Function(T) dateSelector; + final String Function(T) entryDataSelector; + + const HistoryList( + {super.key, + required this.history, + required this.dateSelector, + required this.entryDataSelector}); + + @override + Widget build(BuildContext context) { + return Container( + height: MediaQuery.of(context).size.height * 0.25, + margin: const EdgeInsets.only(top: 10), + child: ListView( + children: history.map((T entry) { + return EntryDetail( + date: dateSelector(entry), + entryData: entryDataSelector(entry), + icon: Icons.bedtime_outlined, + ); + }).toList())); + } +} diff --git a/lib/widgets/view_form/sleep_view.dart b/lib/widgets/view_form/sleep_view.dart index 877d756..33b610c 100644 --- a/lib/widgets/view_form/sleep_view.dart +++ b/lib/widgets/view_form/sleep_view.dart @@ -1,6 +1,8 @@ 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'; import 'package:syncfusion_flutter_charts/charts.dart'; @@ -22,10 +24,11 @@ class SleepView extends StatelessWidget { yValueMapper: (Sleep value, _) => value.sleepQualitiyValue) ], ), - Column( - children: tasksModel.sleepHistory.map((sleep) { - return Text('${sleep.date}: ${sleep.sleepQualitiyValue}'); - }).toList()) + HistoryList( + history: tasksModel.sleepHistory, + dateSelector: (Sleep sleep) => sleep.date, + entryDataSelector: (Sleep sleep) => + '${sleep.sleepDuration.hour}:${sleep.sleepDuration.minute}') ], ); } diff --git a/lib/widgets/view_form/view_form_page.dart b/lib/widgets/view_form/view_form_page.dart index 778d21d..099ae07 100644 --- a/lib/widgets/view_form/view_form_page.dart +++ b/lib/widgets/view_form/view_form_page.dart @@ -5,7 +5,6 @@ import 'package:smoke_cess_app/widgets/buttons/round_button_widget.dart'; import 'package:smoke_cess_app/providers/input_provider.dart'; import 'package:smoke_cess_app/providers/page_provider.dart'; import 'package:smoke_cess_app/providers/tasks_provider.dart'; -import 'package:smoke_cess_app/widgets/popup/popup_for_task_done.dart'; class ViewFormPage extends StatelessWidget { final Widget form;