display correct icons in historyview, mood icon dependant on moodvalue

main
Julian Gegner 2023-03-06 00:34:45 +01:00
parent 43723f4ef2
commit e91caaa5ba
5 changed files with 43 additions and 22 deletions

View File

@ -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: [

View File

@ -5,12 +5,25 @@ class HistoryList<T> extends StatelessWidget {
final List<T> 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<T> 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()));
}
}

View File

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

View File

@ -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<TasksProvider>();
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: tasksModel.relapseHistory.map((relapse) {
return Text('${relapse.date}: ${relapse.category}');
}).toList());
TasksProvider tasksModel = context.watch<TasksProvider>();
return HistoryList<Relapse>(
history: tasksModel.relapseHistory,
dateSelector: (Relapse relapse) => relapse.date,
entryDataSelector: (Relapse relapse) => 'Grund: ${relapse.category}',
icon: Icons.smoke_free_outlined,
);
}
}

View File

@ -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<Sleep>(
history: tasksModel.sleepHistory,
dateSelector: (Sleep sleep) => sleep.date,
entryDataSelector: (Sleep sleep) =>
'${sleep.sleepDuration.hour}:${sleep.sleepDuration.minute}',
icon: Icons.bedtime_outlined,
)
],
);
}