flutter_application_1/lib/widgets/input_widget.dart

104 lines
3.4 KiB
Dart
Raw Normal View History

2024-05-06 17:28:10 +02:00
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
2024-06-12 12:48:30 +02:00
// Widget zur Eingabe mit einem Label, einem Texteingabefeld, einer Validierungsanzeige und einem Tooltip
class InputWidget extends StatefulWidget {
final String label; // Beschriftung des Eingabefelds
final TextEditingController controller; // Controller für die Texteingabe
final FocusNode focusNode; // FocusNode für die Eingabe
final bool isValid; // Validierungsstatus
final String suffixText; // Suffix-Text für das Eingabefeld
final String tooltipText; // Erklärungstext im Tooltip
const InputWidget({
super.key,
required this.label,
required this.controller,
required this.focusNode,
required this.isValid,
required this.suffixText,
required this.tooltipText,
});
@override
InputWidgetState createState() => InputWidgetState();
}
class InputWidgetState extends State<InputWidget> {
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Text(
widget.label,
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
2024-05-06 17:28:10 +02:00
),
2024-06-12 12:48:30 +02:00
),
const SizedBox(width: 5),
// Tooltip mit Erklärungstext
Tooltip(
message: widget.tooltipText,
triggerMode: TooltipTriggerMode.tap,
decoration: const BoxDecoration(
color: CupertinoColors.black,
borderRadius: BorderRadius.all(Radius.circular(5)),
2024-05-06 17:28:10 +02:00
),
2024-06-12 12:48:30 +02:00
textStyle: const TextStyle(
color: CupertinoColors.white,
),
margin: const EdgeInsets.all(20),
child: const Icon(
CupertinoIcons.question_circle_fill,
size: 15,
),
),
],
),
// Icon zur Anzeige der Validierung
widget.isValid
? const Icon(
CupertinoIcons.check_mark_circled_solid,
color: CupertinoColors.systemGreen,
size: 15,
)
: const Icon(
CupertinoIcons.clear_circled_solid,
color: CupertinoColors.systemRed,
size: 15,
),
],
),
const SizedBox(height: 5),
CupertinoTextField(
controller: widget.controller,
focusNode: widget.focusNode,
keyboardType: TextInputType.number,
suffix: Padding(
padding: const EdgeInsets.symmetric(horizontal: 5.0),
child: Text(
widget.suffixText,
style: const TextStyle(
fontWeight: FontWeight.bold,
2024-05-06 17:28:10 +02:00
),
),
),
2024-06-12 12:48:30 +02:00
decoration: BoxDecoration(
color: CupertinoColors.extraLightBackgroundGray,
borderRadius: BorderRadius.circular(5),
),
cursorColor: CupertinoColors.black,
2024-05-06 17:28:10 +02:00
),
2024-06-12 12:48:30 +02:00
const SizedBox(height: 20),
],
);
}
2024-05-06 17:28:10 +02:00
}