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> {
int touchedIndex = -1;
List<BarChartGroupData> _groups = [];
@override
Widget build(BuildContext context) {
return AspectRatio(
......@@ -46,7 +48,60 @@ class BarChartState extends State<BarGraph> {
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
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,
),
),
......@@ -63,138 +118,16 @@ class BarChartState extends State<BarGraph> {
);
}
String getCurrentMonthName({int offset = 0}) {
final monthNum = DateTime.now().month - offset;
switch (monthNum) {
case 1:
return 'Januar';
case 2:
return 'Februar';
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 '???';
@override
void didChangeDependencies() {
super.didChangeDependencies();
_groups = [];
for (var key in widget.data.keys) {
final index = widget.data.keys.toList().indexOf(key);
_groups.add(makeGroupData(index, widget.data[key], isTouched: index == touchedIndex));
}
}
BarChartData mainBarData() {
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(),
);
setState(() {});
}
BarChartGroupData makeGroupData(
......@@ -227,27 +160,6 @@ class BarChartState extends State<BarGraph> {
setState(() {});
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 {
......@@ -263,9 +175,9 @@ class BarGraph extends StatefulWidget {
final String title;
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
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 'bar_graph.dart';
......@@ -10,6 +12,12 @@ class BillsReportPage extends StatefulWidget {
}
class _BillsReportPageState extends State<BillsReportPage> {
BillRepository _billRepo;
bool busy;
List<Bill> _bills;
@override
Widget build(BuildContext context) {
return Scaffold(
......@@ -19,9 +27,45 @@ class _BillsReportPageState extends State<BillsReportPage> {
body: GridView.count(
crossAxisCount: MediaQuery.of(context).size.width > 768.0 ? 2 : 1,
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