Commit 8a4575db authored by Leon Tappe's avatar Leon Tappe 🔥
Browse files

load bills on bill report page

parent aae2bb76
...@@ -10,6 +10,8 @@ class BarChartState extends State<BarGraph> { ...@@ -10,6 +10,8 @@ class BarChartState extends State<BarGraph> {
int touchedIndex = -1; int touchedIndex = -1;
List<BarChartGroupData> _groups = [];
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return AspectRatio( return AspectRatio(
...@@ -46,7 +48,60 @@ class BarChartState extends State<BarGraph> { ...@@ -46,7 +48,60 @@ class BarChartState extends State<BarGraph> {
child: Padding( child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0), padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: BarChart( child: BarChart(
mainBarData(), BarChartData(
barTouchData: BarTouchData(
touchTooltipData: BarTouchTooltipData(
tooltipBgColor: Colors.blueGrey,
getTooltipItem: (group, groupIndex, rod, rodIndex) => BarTooltipItem(
widget.data.keys.toList()[group.x.toInt()] + '\n',
TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 18,
),
children: <TextSpan>[
TextSpan(
text: rod.y.toString(),
style: TextStyle(
color: Colors.yellow,
fontSize: 16,
fontWeight: FontWeight.w500,
),
),
],
),
),
touchCallback: (barTouchResponse) {
setState(() {
if (barTouchResponse.spot != null &&
barTouchResponse.touchInput is! PointerUpEvent &&
barTouchResponse.touchInput is! PointerExitEvent) {
touchedIndex = barTouchResponse.spot.touchedBarGroupIndex;
} else {
touchedIndex = -1;
}
});
},
),
titlesData: FlTitlesData(
show: true,
bottomTitles: SideTitles(
showTitles: true,
getTextStyles: (value) => const TextStyle(
color: Colors.white, fontWeight: FontWeight.bold, fontSize: 14),
margin: 16,
getTitles: (double value) =>
widget.data.keys.toList()[value.toInt()][0],
),
leftTitles: SideTitles(
showTitles: false,
),
),
borderData: FlBorderData(
show: false,
),
barGroups: _groups,
),
swapAnimationDuration: animDuration, swapAnimationDuration: animDuration,
), ),
), ),
...@@ -63,138 +118,16 @@ class BarChartState extends State<BarGraph> { ...@@ -63,138 +118,16 @@ class BarChartState extends State<BarGraph> {
); );
} }
String getCurrentMonthName({int offset = 0}) { @override
final monthNum = DateTime.now().month - offset; void didChangeDependencies() {
switch (monthNum) { super.didChangeDependencies();
case 1: _groups = [];
return 'Januar'; for (var key in widget.data.keys) {
case 2: final index = widget.data.keys.toList().indexOf(key);
return 'Februar'; _groups.add(makeGroupData(index, widget.data[key], isTouched: index == touchedIndex));
case 3:
return 'März';
case 4:
return 'April';
case 5:
return 'Mai';
case 6:
return 'Juni';
case 7:
return 'Juli';
case 8:
return 'August';
case 9:
return 'September';
case 10:
return 'Oktober';
case 11:
return 'November';
case 12:
return 'Dezember';
default:
return '???';
} }
}
BarChartData mainBarData() { setState(() {});
return BarChartData(
barTouchData: BarTouchData(
touchTooltipData: BarTouchTooltipData(
tooltipBgColor: Colors.blueGrey,
getTooltipItem: (group, groupIndex, rod, rodIndex) {
String weekDay;
switch (group.x.toInt()) {
case 0:
weekDay = 'Monday';
break;
case 1:
weekDay = 'Tuesday';
break;
case 2:
weekDay = 'Wednesday';
break;
case 3:
weekDay = 'Thursday';
break;
case 4:
weekDay = 'Friday';
break;
case 5:
weekDay = 'Saturday';
break;
case 6:
weekDay = 'Sunday';
break;
default:
throw Error();
}
return BarTooltipItem(
weekDay + '\n',
TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 18,
),
children: <TextSpan>[
TextSpan(
text: (rod.y - 1).toString(),
style: TextStyle(
color: Colors.yellow,
fontSize: 16,
fontWeight: FontWeight.w500,
),
),
],
);
}),
touchCallback: (barTouchResponse) {
setState(() {
if (barTouchResponse.spot != null &&
barTouchResponse.touchInput is! PointerUpEvent &&
barTouchResponse.touchInput is! PointerExitEvent) {
touchedIndex = barTouchResponse.spot.touchedBarGroupIndex;
} else {
touchedIndex = -1;
}
});
},
),
titlesData: FlTitlesData(
show: true,
bottomTitles: SideTitles(
showTitles: true,
getTextStyles: (value) =>
const TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 14),
margin: 16,
getTitles: (double value) {
switch (value.toInt()) {
case 0:
return 'M';
case 1:
return 'T';
case 2:
return 'W';
case 3:
return 'T';
case 4:
return 'F';
case 5:
return 'S';
case 6:
return 'S';
default:
return '';
}
},
),
leftTitles: SideTitles(
showTitles: false,
),
),
borderData: FlBorderData(
show: false,
),
barGroups: showingGroups(),
);
} }
BarChartGroupData makeGroupData( BarChartGroupData makeGroupData(
...@@ -227,27 +160,6 @@ class BarChartState extends State<BarGraph> { ...@@ -227,27 +160,6 @@ class BarChartState extends State<BarGraph> {
setState(() {}); setState(() {});
await Future<dynamic>.delayed(animDuration + const Duration(milliseconds: 50)); await Future<dynamic>.delayed(animDuration + const Duration(milliseconds: 50));
} }
List<BarChartGroupData> showingGroups() => List.generate(7, (i) {
switch (i) {
case 0:
return makeGroupData(0, 5, isTouched: i == touchedIndex);
case 1:
return makeGroupData(1, 6.5, isTouched: i == touchedIndex);
case 2:
return makeGroupData(2, 5, isTouched: i == touchedIndex);
case 3:
return makeGroupData(3, 7.5, isTouched: i == touchedIndex);
case 4:
return makeGroupData(4, 9, isTouched: i == touchedIndex);
case 5:
return makeGroupData(5, 11.5, isTouched: i == touchedIndex);
case 6:
return makeGroupData(6, 6.5, isTouched: i == touchedIndex);
default:
return throw Error();
}
});
} }
class BarGraph extends StatefulWidget { class BarGraph extends StatefulWidget {
...@@ -263,9 +175,9 @@ class BarGraph extends StatefulWidget { ...@@ -263,9 +175,9 @@ class BarGraph extends StatefulWidget {
final String title; final String title;
final String subtitle; final String subtitle;
final Map<String, int> data; final Map<String, double> data;
BarGraph({this.title, this.subtitle, this.data}); BarGraph({@required this.title, @required this.subtitle, @required this.data});
@override @override
State<StatefulWidget> createState() => BarChartState(); State<StatefulWidget> createState() => BarChartState();
......
import 'package:bitter/src/providers/inherited_database.dart';
import 'package:bitter/src/repositories/bill_repository.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'bar_graph.dart'; import 'bar_graph.dart';
...@@ -10,6 +12,12 @@ class BillsReportPage extends StatefulWidget { ...@@ -10,6 +12,12 @@ class BillsReportPage extends StatefulWidget {
} }
class _BillsReportPageState extends State<BillsReportPage> { class _BillsReportPageState extends State<BillsReportPage> {
BillRepository _billRepo;
bool busy;
List<Bill> _bills;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
...@@ -19,9 +27,45 @@ class _BillsReportPageState extends State<BillsReportPage> { ...@@ -19,9 +27,45 @@ class _BillsReportPageState extends State<BillsReportPage> {
body: GridView.count( body: GridView.count(
crossAxisCount: MediaQuery.of(context).size.width > 768.0 ? 2 : 1, crossAxisCount: MediaQuery.of(context).size.width > 768.0 ? 2 : 1,
children: <Widget>[ children: <Widget>[
BarGraph(title: 'Einnahmen', subtitle: 'Monatlich'), BarGraph(
title: 'Einnahmen',
subtitle: 'Monatlich',
data: {'Juni': 300},
),
], ],
), ),
); );
} }
@override
void didChangeDependencies() {
super.didChangeDependencies();
}
Map<String, double> generateMonthlyReport({int length = 6}) {
Map<String, double> report = {};
final currentMonth = DateTime.now().month;
/*for (int month = currentMonth; i > currentMonth - length; i--) {
_bills.where((Bill e) => e.created.month == month);
report.addAll({});
}*/
}
@override
void initState() {
super.initState();
_initDb();
}
Future<void> _initDb() async {
if (mounted) setState(() => busy = true);
_billRepo = BillRepository(InheritedDatabase.of(context));
await _billRepo.setUp();
_bills = await _billRepo.select();
if (mounted) setState(() => busy = false);
}
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment