use linechart widget in views

main
Julian Gegner 2023-03-05 20:54:08 +01:00
parent b23f9ccdc1
commit 54ec18d1fe
5 changed files with 32 additions and 43 deletions

View File

@ -5,14 +5,11 @@ import 'package:smoke_cess_app/providers/settings_provider.dart';
import 'package:syncfusion_flutter_charts/charts.dart';
class LineChart<T> extends StatelessWidget {
final List<T> dataSource;
final DateTime? Function(T, int) xValueMapper;
final num? Function(T, int) yValueMapper;
const LineChart(
{super.key,
required this.dataSource,
required this.xValueMapper,
required this.yValueMapper});
final List<LineSeries<T, DateTime>> series;
const LineChart({
super.key,
required this.series,
});
@override
Widget build(BuildContext context) {
@ -28,12 +25,7 @@ class LineChart<T> extends StatelessWidget {
),
primaryYAxis:
NumericAxis(isVisible: false, minimum: 0, maximum: 100, interval: 20),
series: <ChartSeries>[
LineSeries<T, DateTime>(
dataSource: dataSource,
xValueMapper: xValueMapper,
yValueMapper: yValueMapper),
],
series: series,
);
}
}

View File

@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.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';
import 'package:smoke_cess_app/providers/tasks_provider.dart';
@ -13,15 +14,12 @@ class MoodView extends StatelessWidget {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SfCartesianChart(
primaryXAxis: DateTimeAxis(),
series: <ChartSeries>[
LineChart(series: [
LineSeries<Mood, DateTime>(
dataSource: tasksModel.moodHistory,
xValueMapper: (Mood value, _) => value.date,
yValueMapper: (Mood value, _) => value.moodValue)
],
),
]),
Column(
children: tasksModel.moodHistory.map((mood) {
return Text('${mood.date}: ${mood.moodValue}');

View File

@ -1,21 +1,21 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:smoke_cess_app/models/sleep.dart';
import 'package:syncfusion_flutter_charts/charts.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';
class SleepView extends StatelessWidget {
const SleepView({super.key});
@override
Widget build(BuildContext context) {
var tasksModel = context.watch<TasksProvider>();
TasksProvider tasksModel = context.watch<TasksProvider>();
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SfCartesianChart(
primaryXAxis: DateTimeAxis(),
series: <ChartSeries>[
LineChart<Sleep>(
series: [
LineSeries<Sleep, DateTime>(
dataSource: tasksModel.sleepHistory,
xValueMapper: (Sleep value, _) => value.date,

View File

@ -35,7 +35,8 @@ class ViewFormPage extends StatelessWidget {
child: RoundAddButton(
onPressed: tasksProvider.tasks[page] == true
? () => pageProvider.swap()
: () => showTaskDonePopup(context, page),
: () => pageProvider.swap(),
//: () => showTaskDonePopup(context, page),
),
)
]);

View File

@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:smoke_cess_app/models/workout.dart';
import 'package:smoke_cess_app/widgets/line_chart_widget.dart';
import 'package:syncfusion_flutter_charts/charts.dart';
import 'package:smoke_cess_app/providers/tasks_provider.dart';
@ -9,13 +10,11 @@ class WorkoutView extends StatelessWidget {
@override
Widget build(BuildContext context) {
var tasksModel = context.watch<TasksProvider>();
TasksProvider tasksModel = context.watch<TasksProvider>();
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SfCartesianChart(
primaryXAxis: DateTimeAxis(),
series: <ChartSeries>[
LineChart(series: [
LineSeries<Workout, DateTime>(
dataSource: tasksModel.workoutHistory,
xValueMapper: (Workout value, _) => value.date,
@ -24,8 +23,7 @@ class WorkoutView extends StatelessWidget {
dataSource: tasksModel.workoutHistory,
xValueMapper: (Workout value, _) => value.date,
yValueMapper: (Workout value, _) => value.motivationAfter)
],
),
]),
],
);
}