42 lines
1.2 KiB
Dart
42 lines
1.2 KiB
Dart
|
|
||
|
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{
|
||
|
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
||
|
_setValue(number);
|
||
|
}
|
||
|
},
|
||
|
decoration: InputDecoration(
|
||
|
labelText: _labelDisplayText,
|
||
|
hintText: _hintText,
|
||
|
),
|
||
|
)
|
||
|
);
|
||
|
}
|
||
|
|
||
|
}
|