You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
439 B
Dart

import 'package:flutter/services.dart';
class NumFormat extends TextInputFormatter {
@override
TextEditingValue formatEditUpdate(TextEditingValue o, TextEditingValue n) {
TextSelection ns = n.selection;
String truncated = n.text;
final double v = double.tryParse(n.text)!;
if (v < -5.0 || v > 5.0) {
truncated = "0.0";
}
return TextEditingValue(
text: truncated,
selection: ns,
);
}
}