cpd_2022_energy/lib/widgets/InputFieldWidget.dart

45 lines
1.2 KiB
Dart
Raw Permalink Normal View History

2022-11-09 01:47:40 +01:00
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,
),
));
}
}