2024-05-06 17:28:10 +02:00
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_application_1/enums.dart';
|
2024-06-03 12:46:40 +02:00
|
|
|
import 'package:flutter_application_1/utils.dart';
|
2024-05-06 17:28:10 +02:00
|
|
|
|
2024-06-12 12:48:30 +02:00
|
|
|
// Widget zur Auswahl des Ausschüttungsintervalls
|
2024-05-06 17:28:10 +02:00
|
|
|
class IntervalWidget extends StatefulWidget {
|
2024-06-12 12:48:30 +02:00
|
|
|
final String selectedInterval; // Das aktuell ausgewählte Intervall
|
|
|
|
final Function(String) onChanged; // Funktion, die aufgerufen wird, wenn das Intervall geändert wird
|
2024-05-06 17:28:10 +02:00
|
|
|
|
2024-05-24 14:04:26 +02:00
|
|
|
const IntervalWidget({
|
|
|
|
super.key,
|
|
|
|
required this.selectedInterval,
|
|
|
|
required this.onChanged
|
|
|
|
});
|
2024-05-06 17:28:10 +02:00
|
|
|
|
|
|
|
@override
|
2024-05-24 14:04:26 +02:00
|
|
|
IntervalWidgetState createState() => IntervalWidgetState();
|
2024-05-06 17:28:10 +02:00
|
|
|
}
|
|
|
|
|
2024-05-24 14:04:26 +02:00
|
|
|
class IntervalWidgetState extends State<IntervalWidget> {
|
|
|
|
bool isExpanded = false; // Zustand, ob das Intervall-Auswahlfenster erweitert ist
|
2024-06-13 09:54:57 +02:00
|
|
|
final LayerLink _layerLink = LayerLink(); // LayerLink für den Overlay
|
|
|
|
|
|
|
|
OverlayEntry? _overlayEntry;
|
|
|
|
|
|
|
|
void _toggleDropdown() {
|
|
|
|
if (isExpanded) {
|
|
|
|
_overlayEntry?.remove();
|
|
|
|
_overlayEntry = null;
|
|
|
|
setState(() {
|
|
|
|
isExpanded = false;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
_overlayEntry = _createOverlayEntry();
|
|
|
|
Overlay.of(context).insert(_overlayEntry!);
|
|
|
|
setState(() {
|
|
|
|
isExpanded = true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OverlayEntry _createOverlayEntry() {
|
|
|
|
return OverlayEntry(
|
|
|
|
builder: (context) => Positioned(
|
|
|
|
width: 160,
|
|
|
|
child: CompositedTransformFollower(
|
|
|
|
link: _layerLink,
|
|
|
|
showWhenUnlinked: false,
|
|
|
|
offset: const Offset(0.0, 60),
|
|
|
|
child: Material(
|
|
|
|
color: CupertinoColors.extraLightBackgroundGray,
|
|
|
|
borderRadius: BorderRadius.circular(5),
|
|
|
|
elevation: 4.0,
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
// ListTile für jährliches Ausschüttungsintervall
|
|
|
|
ListTile(
|
|
|
|
title: Text(
|
|
|
|
translateInterval(PayoutInterval.yearly),
|
|
|
|
style: const TextStyle(
|
|
|
|
color: CupertinoColors.black,
|
|
|
|
fontSize: 14,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
trailing: widget.selectedInterval == translateInterval(PayoutInterval.yearly)
|
|
|
|
? const Icon(CupertinoIcons.checkmark_alt, color: CupertinoColors.black)
|
|
|
|
: null,
|
|
|
|
onTap: () {
|
|
|
|
widget.onChanged(translateInterval(PayoutInterval.yearly));
|
|
|
|
_toggleDropdown();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
// ListTile für monatliches Ausschüttungsintervall
|
|
|
|
ListTile(
|
|
|
|
title: Text(
|
|
|
|
translateInterval(PayoutInterval.monthly),
|
|
|
|
style: const TextStyle(
|
|
|
|
color: CupertinoColors.black,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
trailing: widget.selectedInterval == translateInterval(PayoutInterval.monthly)
|
|
|
|
? const Icon(CupertinoIcons.checkmark_alt, color: CupertinoColors.black)
|
|
|
|
: null,
|
|
|
|
onTap: () {
|
|
|
|
widget.onChanged(translateInterval(PayoutInterval.monthly));
|
|
|
|
_toggleDropdown();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2024-05-06 17:28:10 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-06-13 09:54:57 +02:00
|
|
|
return CompositedTransformTarget(
|
|
|
|
link: _layerLink,
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
const Row(
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
'Ausschüttungsintervall',
|
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
fontSize: 16,
|
|
|
|
),
|
2024-05-20 16:34:31 +02:00
|
|
|
),
|
2024-06-13 09:54:57 +02:00
|
|
|
SizedBox(width: 5),
|
|
|
|
// Tooltip mit Erklärung zum Ausschüttungsintervall
|
|
|
|
Tooltip(
|
|
|
|
message: 'Das Ausschüttungsintervall bezieht sich darauf, wie oft die Erträge aus Ihrer Investition ausgeschüttet werden.',
|
|
|
|
triggerMode: TooltipTriggerMode.tap,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: CupertinoColors.black,
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(5))
|
|
|
|
),
|
|
|
|
textStyle: TextStyle(
|
|
|
|
color: CupertinoColors.white,
|
|
|
|
),
|
|
|
|
margin: EdgeInsets.all(20),
|
|
|
|
child: Icon(CupertinoIcons.question_circle_fill, size: 15),
|
2024-05-20 16:34:31 +02:00
|
|
|
),
|
2024-06-13 09:54:57 +02:00
|
|
|
]
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
alignment: Alignment.centerLeft,
|
|
|
|
width: 160,
|
|
|
|
child: ElevatedButton(
|
|
|
|
onPressed: _toggleDropdown,
|
|
|
|
style: ButtonStyle(
|
|
|
|
backgroundColor: MaterialStateProperty.all<Color>(CupertinoColors.extraLightBackgroundGray),
|
|
|
|
foregroundColor: MaterialStateProperty.all<Color>(CupertinoColors.black),
|
|
|
|
overlayColor: MaterialStateProperty.all<Color>(CupertinoColors.extraLightBackgroundGray),
|
|
|
|
surfaceTintColor: MaterialStateProperty.all<Color>(CupertinoColors.extraLightBackgroundGray),
|
|
|
|
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
|
|
|
|
RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(5),
|
|
|
|
),
|
2024-06-12 12:48:30 +02:00
|
|
|
),
|
|
|
|
),
|
2024-06-13 09:54:57 +02:00
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
2024-06-12 12:48:30 +02:00
|
|
|
child: Text(
|
2024-06-13 09:54:57 +02:00
|
|
|
widget.selectedInterval, // Text des ausgewählten Intervalls
|
|
|
|
),
|
2024-06-12 12:48:30 +02:00
|
|
|
),
|
2024-06-13 09:54:57 +02:00
|
|
|
Icon(isExpanded ? Icons.keyboard_arrow_up : Icons.keyboard_arrow_down),
|
|
|
|
],
|
|
|
|
),
|
2024-06-12 12:48:30 +02:00
|
|
|
),
|
2024-05-06 17:28:10 +02:00
|
|
|
),
|
2024-06-13 09:54:57 +02:00
|
|
|
const SizedBox(height: 20),
|
|
|
|
],
|
|
|
|
),
|
2024-05-06 17:28:10 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|