flutter_application_1/lib/widgets/result_widget.dart

125 lines
4.4 KiB
Dart
Raw Normal View History

2024-05-06 17:28:10 +02:00
import 'package:flutter/cupertino.dart';
2024-05-24 14:04:26 +02:00
import 'package:flutter/material.dart';
2024-05-06 17:28:10 +02:00
import 'package:flutter_application_1/enums.dart';
2024-06-12 12:48:30 +02:00
import 'package:flutter_application_1/pages/chart_page.dart';
import 'package:flutter_application_1/pages/milestone_page.dart';
import 'package:flutter_application_1/utils.dart';
2024-05-24 14:04:26 +02:00
import 'package:flutter_application_1/widgets/custom_image_button_widget.dart';
2024-05-06 17:28:10 +02:00
2024-06-12 12:48:30 +02:00
// Widget zur Anzeige der Ergebnisse der Berechnungen und zur Navigation zu anderen Seiten
class ResultWidget extends StatelessWidget {
final String compoundInterest;
final String investedMoney;
final String time;
final String monthlySavingsRate;
final String interestRate;
final PayoutInterval payoutInterval;
final List<double> investedMoneyList;
final List<double> compoundInterestList;
const ResultWidget({
super.key,
required this.compoundInterest,
required this.investedMoney,
required this.time,
required this.monthlySavingsRate,
required this.interestRate,
required this.payoutInterval,
required this.investedMoneyList,
required this.compoundInterestList,
});
@override
Widget build(BuildContext context) {
List<Map<String, dynamic>> milestoneList = [
{'value': 700.0, 'emoji': '📱', 'text': 'Smartphone\nPreis: 700€'},
{'value': 3250.0, 'emoji': '🚲', 'text': 'eBike\nPreis: 3250€'},
{'value': 20000.0, 'emoji': '🌎', 'text': 'Weltreise\nPreis: 20000€'},
{'value': 100000.0, 'emoji': '🏎️', 'text': 'Sportwagen\nPreis: 100000€'},
{'value': 350000.0, 'emoji': '🏡', 'text': '150qm Einfamilienhaus\nPreis: 350000€'},
];
return Column(
children: <Widget>[
_buildResultRow('Endkapital:', '$compoundInterest'),
_buildResultRow('Einzahlungen:', '$investedMoney'),
_buildResultRow('Erhaltene Zinsen:', '${double.parse(compoundInterest) + double.parse(investedMoney)}'),
const SizedBox(height: 10),
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.'
2024-05-24 14:04:26 +02:00
),
2024-06-12 12:48:30 +02:00
const SizedBox(height: 20),
CustomImageButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ChartPage(
investedMoneyList: investedMoneyList,
compoundInterestList: compoundInterestList,
),
),
);
},
backgroundImage: 'assets/images/button_bg1.jpg',
child: const Text(
'Grafik',
style: TextStyle(color: CupertinoColors.white, fontSize: 20),
),
2024-05-24 14:04:26 +02:00
),
2024-06-12 12:48:30 +02:00
const SizedBox(height: 20),
CustomImageButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => MilestonePage(
compoundInterest: compoundInterest,
investedMoney: investedMoney,
milestoneList: milestoneList
),
),
);
},
backgroundImage: 'assets/images/button_bg2.jpg',
child: const Text(
'Meilensteine',
style: TextStyle(color: CupertinoColors.white, fontSize: 20),
),
),
],
);
}
2024-05-06 17:28:10 +02:00
2024-06-12 12:48:30 +02:00
// Widget zum Aufbau einer Ergebniszeile
Widget _buildResultRow(String label, String value) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Text(
label,
textAlign: TextAlign.start,
style: const TextStyle(
fontWeight: FontWeight.bold,
),
),
2024-05-06 17:28:10 +02:00
),
2024-06-12 12:48:30 +02:00
const SizedBox(width: 20),
Flexible(
child: Text(
value,
textAlign: TextAlign.end,
style: const TextStyle(
fontWeight: FontWeight.bold,
),
),
2024-05-06 17:28:10 +02:00
),
2024-06-12 12:48:30 +02:00
],
),
);
}
2024-05-06 17:28:10 +02:00
}