flutter_application_1/lib/widgets/result_widget.dart

118 lines
4.8 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter_application_1/enums.dart';
import 'package:flutter_application_1/translations.dart';
import 'package:flutter_application_1/widgets/expandable_widget.dart';
import 'package:flutter_application_1/widgets/chart_widget.dart';
Widget buildResultWidget(String compoundInterest, String investedMoney, String time, String monthlySavingsRate, String interestRate, PayoutInterval payoutInterval, List<double> investedMoneyList, List<double> compoundInterestList) {
List<Map<String, dynamic>> milestoneList = [
{'value': 1329, 'image': 'iphone-15-pro-model.png', 'text': 'iPhone 15 Pro Max\nPreis: 1329€', 'size': 20},
{'value': 3071, 'image': 'flyer-gotour6-model.png', 'text': 'Flyer Gotour6 3.40\nPreis: 3071€', 'size': 70},
{'value': 248157, 'image': 'porsche-model.png', 'text': 'Porsche 992 GT3 RS\nPreis: 248157€', 'size': 100},
{'value': 450000, 'image': 'real-estate-model.png', 'text': '150qm Einfamilienhaus\nPreis: ca. 450000€', 'size': 100},
];
return Column(
children: <Widget>[
_buildResultRow('Endkapital:', '$compoundInterest'),
_buildResultRow('Gesamte Einzahlungen:', '$investedMoney'),
_buildResultRow('Erhaltene Zinszahlungen:', '${double.parse(compoundInterest) - double.parse(investedMoney)}'),
const SizedBox(height: 20),
Text(
'Wenn du über einen Zeitraum von $time Jahren ${translateInterval(payoutInterval)} $monthlySavingsRate€ mit einem Zinssatz von $interestRate% investierst, erreichst du am Ende ein Endkapital von $compoundInterest€. Dieses setzt sich aus Einzahlungen von $investedMoney€ und Zinsen bzw. Kapitalerträgen in Höhe von ${double.parse(compoundInterest) - double.parse(investedMoney)}€ zusammen.'
),
const SizedBox(height: 20),
ExpandableBox(
headerText: 'Grafik',
expandedContent: StackedColumnChart(
lowerValues: investedMoneyList,
upperValues: compoundInterestList,
),
),
const SizedBox(height: 5),
ExpandableBox(
headerText: 'Meilensteine',
expandedContent: buildMilestoneTimeline(milestoneList, double.parse(compoundInterest) - double.parse(investedMoney)),
),
],
);
}
Widget _buildResultRow(String label, String value) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 100),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
label,
style: const TextStyle(
fontWeight: FontWeight.bold,
),
),
Text(
value,
style: const TextStyle(
fontWeight: FontWeight.bold,
),
),
],
),
);
}
Widget buildMilestoneTimeline(List<Map<String, dynamic>> milestones, double totalInterest) {
return SizedBox(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: List.generate(milestones.length, (index) {
double milestoneValue = milestones[index]['value'];
String milestoneImage = milestones[index]['image'];
String milestoneText = milestones[index]['text'];
double milestoneSize = milestones[index]['size'];
bool milestoneReached = totalInterest >= milestoneValue;
return Column(
children: [
if (index < milestones.length && index > 0)
Container(
height: 50,
width: 2,
color: milestoneReached ? CupertinoColors.systemGreen : CupertinoColors.black,
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 4.0),
child: Column(
children: [
Image.asset(
'assets/images/$milestoneImage',
width: milestoneSize,
fit: BoxFit.cover,
),
const SizedBox(height: 5), // Abstand zwischen Bild und Text
Text(
milestoneText,
textAlign: TextAlign.center,
style: const TextStyle(
fontWeight: FontWeight.bold,
),
),
],
),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 4.0),
child: Icon(
milestoneReached ? CupertinoIcons.check_mark_circled_solid : CupertinoIcons.circle_fill,
size: 20,
color: milestoneReached ? CupertinoColors.systemGreen : CupertinoColors.black,
),
),
],
);
}),
),
),
);
}