mirror of
https://github.com/supleed2/ELEC60013-ES-CW1.git
synced 2024-12-22 21:45:48 +00:00
Added bar chart for steps
This commit is contained in:
parent
e13a9436f4
commit
c810510107
|
@ -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';
|
||||
|
|
|
@ -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);
|
||||
}
|
25
lib/view/steps/steps_chart.dart
Normal file
25
lib/view/steps/steps_chart.dart
Normal 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,);
|
||||
}
|
||||
|
||||
}
|
36
lib/view/steps/steps_page.dart
Normal file
36
lib/view/steps/steps_page.dart
Normal 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)
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -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"),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue