cpd_2022_energy/lib/widgets/ExpandedNumberInputWidget.dart

42 lines
1.2 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class ExpandedNumberInputWidget extends StatelessWidget {
String _labelDisplayText = "";
String _hintText = "";
void Function(double) _setValue = (x) => {};
ExpandedNumberInputWidget(String labelDisplayText, String hintText, void Function(double) setValue, {super.key}) {
_labelDisplayText = labelDisplayText;
_hintText = hintText;
_setValue = setValue;
}
@override
Widget build(BuildContext context) {
return Expanded(
child: TextFormField(
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 eine gültige Zahl eingeben')),
);
}else{
2022-11-08 22:12:35 +01:00
ScaffoldMessenger.of(context).clearSnackBars();
_setValue(number);
}
},
decoration: InputDecoration(
labelText: _labelDisplayText,
hintText: _hintText,
),
)
);
}
}