Added bar chart for steps

This commit is contained in:
Benjamin Ramhorst 2022-02-09 17:52:00 +00:00
parent e13a9436f4
commit c810510107
5 changed files with 64 additions and 24 deletions

View file

@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:leg_barkr_app/view/steps_page.dart';
import 'package:leg_barkr_app/view/steps/steps_page.dart';
import 'package:leg_barkr_app/view/data_page.dart';
import 'package:leg_barkr_app/view/map_page.dart';
import 'package:leg_barkr_app/view/settings_page.dart';

View file

@ -1,13 +1,6 @@
import 'package:charts_flutter/flutter.dart' as charts;
class StepSeries {
class StepsSeries {
final DateTime date;
final int steps;
final charts.Color barColor;
StepSeries({
required this.date,
required this.steps,
required this.barColor
});
StepsSeries(this.date, this.steps);
}

View file

@ -0,0 +1,25 @@
import 'package:flutter/material.dart';
import 'package:charts_flutter/flutter.dart' as charts;
import 'package:leg_barkr_app/model/steps_series.dart';
class StepsChart extends StatelessWidget {
final List<StepsSeries> data;
StepsChart(this.data);
@override
Widget build(BuildContext context) {
List<charts.Series<StepsSeries, String>> series = [
charts.Series(
id: "Steps",
data: data,
domainFn: (StepsSeries series, _) => series.date.day.toString() + "/" + series.date.month.toString(),
measureFn: (StepsSeries series, _) => series.steps,
colorFn: (StepsSeries series, _) => charts.ColorUtil.fromDartColor(Colors.green)
)
];
return new charts.BarChart(series, animate: true,);
}
}

View file

@ -0,0 +1,36 @@
import 'package:charts_flutter/flutter.dart' as charts;
import 'package:flutter/material.dart';
import 'package:leg_barkr_app/model/steps_series.dart';
import 'package:leg_barkr_app/view/steps/steps_chart.dart';
class StepsPage extends StatefulWidget {
const StepsPage({ Key? key }) : super(key: key);
@override
_StepsPageState createState() => _StepsPageState();
}
class _StepsPageState extends State<StepsPage> {
// Dummy data
final List<StepsSeries> data = [
StepsSeries(DateTime.utc(2022, 2, 9), 9867),
StepsSeries(DateTime.utc(2022, 2, 8), 8123),
StepsSeries(DateTime.utc(2022, 2, 7), 10234),
StepsSeries(DateTime.utc(2022, 2, 6), 6521),
StepsSeries(DateTime.utc(2022, 2, 5), 1021),
StepsSeries(DateTime.utc(2022, 2, 4), 10567),
StepsSeries(DateTime.utc(2022, 2, 3), 7500)
];
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: StepsChart(data)
),
),
);
}
}

View file

@ -1,14 +0,0 @@
import 'package:flutter/material.dart';
class StepsPage extends StatelessWidget {
const StepsPage({ Key? key }) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Text("Steps Page"),
),
);
}
}