use linechart widget in views
parent
b23f9ccdc1
commit
54ec18d1fe
|
@ -5,14 +5,11 @@ import 'package:smoke_cess_app/providers/settings_provider.dart';
|
||||||
import 'package:syncfusion_flutter_charts/charts.dart';
|
import 'package:syncfusion_flutter_charts/charts.dart';
|
||||||
|
|
||||||
class LineChart<T> extends StatelessWidget {
|
class LineChart<T> extends StatelessWidget {
|
||||||
final List<T> dataSource;
|
final List<LineSeries<T, DateTime>> series;
|
||||||
final DateTime? Function(T, int) xValueMapper;
|
const LineChart({
|
||||||
final num? Function(T, int) yValueMapper;
|
super.key,
|
||||||
const LineChart(
|
required this.series,
|
||||||
{super.key,
|
});
|
||||||
required this.dataSource,
|
|
||||||
required this.xValueMapper,
|
|
||||||
required this.yValueMapper});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
@ -28,12 +25,7 @@ class LineChart<T> extends StatelessWidget {
|
||||||
),
|
),
|
||||||
primaryYAxis:
|
primaryYAxis:
|
||||||
NumericAxis(isVisible: false, minimum: 0, maximum: 100, interval: 20),
|
NumericAxis(isVisible: false, minimum: 0, maximum: 100, interval: 20),
|
||||||
series: <ChartSeries>[
|
series: series,
|
||||||
LineSeries<T, DateTime>(
|
|
||||||
dataSource: dataSource,
|
|
||||||
xValueMapper: xValueMapper,
|
|
||||||
yValueMapper: yValueMapper),
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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/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';
|
||||||
import 'package:smoke_cess_app/providers/tasks_provider.dart';
|
import 'package:smoke_cess_app/providers/tasks_provider.dart';
|
||||||
|
@ -13,15 +14,12 @@ class MoodView extends StatelessWidget {
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
SfCartesianChart(
|
LineChart(series: [
|
||||||
primaryXAxis: DateTimeAxis(),
|
|
||||||
series: <ChartSeries>[
|
|
||||||
LineSeries<Mood, DateTime>(
|
LineSeries<Mood, DateTime>(
|
||||||
dataSource: tasksModel.moodHistory,
|
dataSource: tasksModel.moodHistory,
|
||||||
xValueMapper: (Mood value, _) => value.date,
|
xValueMapper: (Mood value, _) => value.date,
|
||||||
yValueMapper: (Mood value, _) => value.moodValue)
|
yValueMapper: (Mood value, _) => value.moodValue)
|
||||||
],
|
]),
|
||||||
),
|
|
||||||
Column(
|
Column(
|
||||||
children: tasksModel.moodHistory.map((mood) {
|
children: tasksModel.moodHistory.map((mood) {
|
||||||
return Text('${mood.date}: ${mood.moodValue}');
|
return Text('${mood.date}: ${mood.moodValue}');
|
||||||
|
|
|
@ -1,21 +1,21 @@
|
||||||
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: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:smoke_cess_app/providers/tasks_provider.dart';
|
||||||
|
import 'package:syncfusion_flutter_charts/charts.dart';
|
||||||
|
|
||||||
class SleepView extends StatelessWidget {
|
class SleepView extends StatelessWidget {
|
||||||
const SleepView({super.key});
|
const SleepView({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 Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
SfCartesianChart(
|
LineChart<Sleep>(
|
||||||
primaryXAxis: DateTimeAxis(),
|
series: [
|
||||||
series: <ChartSeries>[
|
|
||||||
LineSeries<Sleep, DateTime>(
|
LineSeries<Sleep, DateTime>(
|
||||||
dataSource: tasksModel.sleepHistory,
|
dataSource: tasksModel.sleepHistory,
|
||||||
xValueMapper: (Sleep value, _) => value.date,
|
xValueMapper: (Sleep value, _) => value.date,
|
||||||
|
|
|
@ -35,7 +35,8 @@ class ViewFormPage extends StatelessWidget {
|
||||||
child: RoundAddButton(
|
child: RoundAddButton(
|
||||||
onPressed: tasksProvider.tasks[page] == true
|
onPressed: tasksProvider.tasks[page] == true
|
||||||
? () => pageProvider.swap()
|
? () => pageProvider.swap()
|
||||||
: () => showTaskDonePopup(context, page),
|
: () => pageProvider.swap(),
|
||||||
|
//: () => showTaskDonePopup(context, page),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
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/workout.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:syncfusion_flutter_charts/charts.dart';
|
||||||
import 'package:smoke_cess_app/providers/tasks_provider.dart';
|
import 'package:smoke_cess_app/providers/tasks_provider.dart';
|
||||||
|
|
||||||
|
@ -9,13 +10,11 @@ class WorkoutView extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var tasksModel = context.watch<TasksProvider>();
|
TasksProvider tasksModel = context.watch<TasksProvider>();
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
SfCartesianChart(
|
LineChart(series: [
|
||||||
primaryXAxis: DateTimeAxis(),
|
|
||||||
series: <ChartSeries>[
|
|
||||||
LineSeries<Workout, DateTime>(
|
LineSeries<Workout, DateTime>(
|
||||||
dataSource: tasksModel.workoutHistory,
|
dataSource: tasksModel.workoutHistory,
|
||||||
xValueMapper: (Workout value, _) => value.date,
|
xValueMapper: (Workout value, _) => value.date,
|
||||||
|
@ -24,8 +23,7 @@ class WorkoutView extends StatelessWidget {
|
||||||
dataSource: tasksModel.workoutHistory,
|
dataSource: tasksModel.workoutHistory,
|
||||||
xValueMapper: (Workout value, _) => value.date,
|
xValueMapper: (Workout value, _) => value.date,
|
||||||
yValueMapper: (Workout value, _) => value.motivationAfter)
|
yValueMapper: (Workout value, _) => value.motivationAfter)
|
||||||
],
|
]),
|
||||||
),
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue