use historylist to display entries

main
Julian Gegner 2023-03-06 00:05:11 +01:00
parent e7dc40a4de
commit 43723f4ef2
4 changed files with 77 additions and 5 deletions

View File

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

View File

@ -0,0 +1,29 @@
import 'package:flutter/material.dart';
import 'package:smoke_cess_app/widgets/entry_detail_widget.dart';
class HistoryList<T> extends StatelessWidget {
final List<T> 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()));
}
}

View File

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

View File

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