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( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0), borderRadius: BorderRadius.circular(10.0),
), ),
leading: const Icon(Icons.local_airport, color: Colors.white), leading: Icon(icon, color: Colors.white),
title: Row( title: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [ children: [

View File

@ -5,12 +5,25 @@ class HistoryList<T> extends StatelessWidget {
final List<T> history; final List<T> history;
final DateTime Function(T) dateSelector; final DateTime Function(T) dateSelector;
final String Function(T) entryDataSelector; final String Function(T) entryDataSelector;
final IconData Function(T)? iconDataSelector;
final IconData? icon;
const HistoryList( const HistoryList(
{super.key, {super.key,
required this.history, required this.history,
required this.dateSelector, 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -20,10 +33,9 @@ class HistoryList<T> extends StatelessWidget {
child: ListView( child: ListView(
children: history.map((T entry) { children: history.map((T entry) {
return EntryDetail( return EntryDetail(
date: dateSelector(entry), date: dateSelector(entry),
entryData: entryDataSelector(entry), entryData: entryDataSelector(entry),
icon: Icons.bedtime_outlined, icon: _getIcon(entry));
);
}).toList())); }).toList()));
} }
} }

View File

@ -1,5 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.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:smoke_cess_app/widgets/line_chart_widget.dart';
import 'package:syncfusion_flutter_charts/charts.dart'; import 'package:syncfusion_flutter_charts/charts.dart';
import 'package:smoke_cess_app/models/mood.dart'; import 'package:smoke_cess_app/models/mood.dart';
@ -20,10 +21,14 @@ class MoodView extends StatelessWidget {
xValueMapper: (Mood value, _) => value.date, xValueMapper: (Mood value, _) => value.date,
yValueMapper: (Mood value, _) => value.moodValue) yValueMapper: (Mood value, _) => value.moodValue)
]), ]),
Column( HistoryList<Mood>(
children: tasksModel.moodHistory.map((mood) { history: tasksModel.moodHistory,
return Text('${mood.date}: ${mood.moodValue}'); dateSelector: (Mood mood) => mood.date,
}).toList()) 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:flutter/material.dart';
import 'package:provider/provider.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/providers/tasks_provider.dart';
import 'package:smoke_cess_app/widgets/history_list_widget.dart';
class RelapseView extends StatelessWidget { class RelapseView extends StatelessWidget {
const RelapseView({super.key}); const RelapseView({super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var tasksModel = context.watch<TasksProvider>(); TasksProvider tasksModel = context.watch<TasksProvider>();
return Column( return HistoryList<Relapse>(
mainAxisAlignment: MainAxisAlignment.center, history: tasksModel.relapseHistory,
children: tasksModel.relapseHistory.map((relapse) { dateSelector: (Relapse relapse) => relapse.date,
return Text('${relapse.date}: ${relapse.category}'); entryDataSelector: (Relapse relapse) => 'Grund: ${relapse.category}',
}).toList()); icon: Icons.smoke_free_outlined,
);
} }
} }

View File

@ -1,7 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:smoke_cess_app/models/sleep.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/history_list_widget.dart';
import 'package:smoke_cess_app/widgets/line_chart_widget.dart'; import 'package:smoke_cess_app/widgets/line_chart_widget.dart';
import 'package:smoke_cess_app/providers/tasks_provider.dart'; import 'package:smoke_cess_app/providers/tasks_provider.dart';
@ -24,11 +23,13 @@ class SleepView extends StatelessWidget {
yValueMapper: (Sleep value, _) => value.sleepQualitiyValue) yValueMapper: (Sleep value, _) => value.sleepQualitiyValue)
], ],
), ),
HistoryList( HistoryList<Sleep>(
history: tasksModel.sleepHistory, history: tasksModel.sleepHistory,
dateSelector: (Sleep sleep) => sleep.date, dateSelector: (Sleep sleep) => sleep.date,
entryDataSelector: (Sleep sleep) => entryDataSelector: (Sleep sleep) =>
'${sleep.sleepDuration.hour}:${sleep.sleepDuration.minute}') '${sleep.sleepDuration.hour}:${sleep.sleepDuration.minute}',
icon: Icons.bedtime_outlined,
)
], ],
); );
} }