45 lines
1.2 KiB
Dart
45 lines
1.2 KiB
Dart
|
import 'package:flutter/material.dart';
|
||
|
import 'package:flutter/services.dart';
|
||
|
|
||
|
class InputFieldWidget extends StatelessWidget {
|
||
|
String _labelDisplayText = "";
|
||
|
String _hintText = "";
|
||
|
void Function(double) _setValue = (x) => {};
|
||
|
|
||
|
InputFieldWidget(
|
||
|
String labelDisplayText, String hintText, void Function(double) setValue,
|
||
|
{super.key}) {
|
||
|
_labelDisplayText = labelDisplayText;
|
||
|
_hintText = hintText;
|
||
|
_setValue = setValue;
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return Expanded(
|
||
|
child:
|
||
|
|
||
|
TextField(
|
||
|
keyboardType: TextInputType.number,
|
||
|
inputFormatters: [FilteringTextInputFormatter.allow(RegExp('[0-9.]'))],
|
||
|
onChanged: (value) {
|
||
|
double? number = double.tryParse(value);
|
||
|
if (number == null) {
|
||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||
|
const SnackBar(
|
||
|
content: Text('Bitte geben Sie eine Zal zwischen 0-9 ein')),
|
||
|
);
|
||
|
} else {
|
||
|
ScaffoldMessenger.of(context).clearSnackBars();
|
||
|
_setValue(number);
|
||
|
}
|
||
|
},
|
||
|
decoration: InputDecoration(
|
||
|
border: const OutlineInputBorder(),
|
||
|
labelText: _labelDisplayText,
|
||
|
hintText: _hintText,
|
||
|
),
|
||
|
));
|
||
|
}
|
||
|
}
|