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, ); } }