flutter_application_1/lib/widgets/interval_widget.dart

114 lines
4.2 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_application_1/enums.dart';
import 'package:flutter_application_1/translations.dart';
class IntervalWidget extends StatefulWidget {
final String selectedInterval;
final Function(String) onChanged;
const IntervalWidget({super.key, required this.selectedInterval, required this.onChanged});
@override
// ignore: library_private_types_in_public_api
_IntervalWidgetState createState() => _IntervalWidgetState();
}
class _IntervalWidgetState extends State<IntervalWidget> {
bool isExpanded = false;
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Row(
children: [
Text(
'Ausschüttungsintervall',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
SizedBox(width: 5),
Tooltip(
message: 'Das Ausschüttungsintervall bezieht sich darauf, wie oft die Erträge aus Ihrer Investition ausgeschüttet werden.',
child: Icon(CupertinoIcons.question_circle_fill, size: 15),
),
]
),
CupertinoTextField(
placeholder: 'Ausschüttungsintervall auswählen',
readOnly: true,
onTap: () {
showModalBottomSheet(
context: context,
backgroundColor: CupertinoColors.white,
builder: (BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: ListTile(
title: Text(
translateInterval(PayoutInterval.yearly),
style: const TextStyle(
fontWeight: FontWeight.bold,
),
),
hoverColor: Colors.transparent,
trailing: widget.selectedInterval == translateInterval(PayoutInterval.yearly) ? const Icon(CupertinoIcons.checkmark_alt) : null,
onTap: () {
widget.onChanged(translateInterval(PayoutInterval.yearly));
Navigator.pop(context);
},
),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: ListTile(
title: Text(
translateInterval(PayoutInterval.monthly),
style: const TextStyle(
fontWeight: FontWeight.bold,
),
),
hoverColor: Colors.transparent,
trailing: widget.selectedInterval == translateInterval(PayoutInterval.monthly) ? const Icon(CupertinoIcons.checkmark_alt) : null,
onTap: () {
widget.onChanged(translateInterval(PayoutInterval.monthly));
Navigator.pop(context);
},
),
),
],
);
},
).then((value) {
setState(() {
isExpanded = false;
});
});
setState(() {
isExpanded = true;
});
},
suffix: Padding(
padding: const EdgeInsets.symmetric(horizontal: 5.0),
child: Icon(isExpanded ? Icons.keyboard_arrow_up : Icons.keyboard_arrow_down),
),
controller: TextEditingController(text: widget.selectedInterval),
decoration: BoxDecoration(
color: CupertinoColors.extraLightBackgroundGray,
borderRadius: BorderRadius.circular(5),
),
cursorColor: CupertinoColors.black,
),
const SizedBox(height: 20),
],
);
}
}