Flutter TextField input only decimal numbers

input only numbers flutter
flutter phone number input
flutter decimal
how to validate decimal number in flutter
decimal input formatter flutter
flutter decimal keyboard
flutter textfield(inputformatters)
flutter textfield set value

I want to input only decimal number in TextField in Flutter. I tried below code but that's not working. It allows alpha (a-z) and special characters.

      new TextEditingController(text: listDisplay[position].getBlockQty(),
  textAlign: TextAlign.center,
  maxLines: 1,       
  keyboardType: TextInputType.numberWithOptions(
      decimal: true,
      signed: false),       

You can use TextInputFormatter for this case.

Here is an example for the same,

Subclass TextInputFormatter

import 'package:flutter/services.dart';

class RegExInputFormatter implements TextInputFormatter {
  final RegExp _regExp;


  factory RegExInputFormatter.withRegex(String regexString) {
    try {
      final regex = RegExp(regexString);
      return RegExInputFormatter._(regex);
    } catch (e) {
      // Something not right with regex string.
      assert(false, e.toString());
      return null;

  TextEditingValue formatEditUpdate(
      TextEditingValue oldValue, TextEditingValue newValue) {
    final oldValueValid = _isValid(oldValue.text);
    final newValueValid = _isValid(newValue.text);
    if (oldValueValid && !newValueValid) {
      return oldValue;
    return newValue;

  bool _isValid(String value) {
    try {
      final matches = _regExp.allMatches(value);
      for (Match match in matches) {
        if (match.start == 0 && match.end == value.length) {
          return true;
      return false;
    } catch (e) {
      // Invalid regex
      assert(false, e.toString());
      return true;

Use it in with your textfield

final _amountValidator = RegExInputFormatter.withRegex('^\$|^(0|([1-9][0-9]{0,}))(\\.[0-9]{0,})?\$');
  inputFormatters: [_amountValidator],
  keyboardType: TextInputType.numberWithOptions(
    decimal: true,
     signed: false,

Allow only two decimal number in flutter input?, Here you go! Hope it helps :) import 'package:flutter/material.dart'; import ' package:flutter/services.dart'; import 'dart:math' as math; void main() { runApp( new� Flutter Get Only Numeric Number Value From TextField Text Input admin April 16, 2020 April 16, 2020 Flutter Tutorials TextField widget has a property named as keyboardType which support a argument TextInputType.number .

I have used this code in one of my Project and its working fine. I hope it will helps you.

         decoration: InputDecoration(
         border: InputBorder.none,
         hintText: "Amount",
         TextStyle(color: Colors.grey, fontSize: 12.0),
         style: TextStyle(color: Colors.black, fontSize: 12.0),
         controller: _amountController[index],
         textInputAction: TextInputAction.done,
         keyboardType: TextInputType.numberWithOptions(decimal: true),)

Allow only two decimal number in flutter input?, allow only numbers and decimal in textbox javascript regex flutter number format example allow decimal in input type=number javascript flutter round to 2� I want to create a TextField in Flutter. The TextField is for decimal numbers. So i set keyboardType: TextInputType.numberWithOptions(decimal: true).Now I get a number keyboard on iOS, but this number keyboard has a period (.) instead of a comma (,).

I am using this code and it's giving different results , on some phones it shows only numbers and on others it shows dashes and other chars , so it depends on the launcher or something like that i guess, in iPhone i guess it will show the correct keyboard ( i have tried on iPhone 7s plus).

the inputFormatters will allow only numbers so you will get what you want.

     textAlign: TextAlign.start,
     keyboardType: TextInputType.numberWithOptions(decimal: true),
     inputFormatters: <TextInputFormatter>[

keyboardType: TextInputType.number shows decimal � Issue , TextInputType.number default fix flutter/engine#7281 iOS doesn't show Number-only keyboard #19894 TextField 'keyboardType: TextInputType. number' doesn't bring the number keyboard on iOS12 & some Android devices ( web) # Numbers with decimal input not working on iOS 13 [web] #60426. Solved: Digits Only Input Keyboard in Flutter – Only Numbers on Text Field By yourowncodes on 12th June 2020 Is it possible to create a Numeric input TextField or TextFormField on Flutter?

What is the best way to handle numeric input (with decimal) in a , numberWithOptions(decimal: true) to your textfield widget? level 2 What I want it *numeric only* input, with two decimals and ability to modify and delete the value of the text field. Merging the r/Flutter & r/FlutterDev communities on Reddit. Flutter TextField input only decimal numbers. 0. take decimal numbers only in dart / flutter. 5. Flutter : how Allow content to overlap SliverAppBar? 0.

decimal property - TextInputType class - services , The number is decimal, allowing a decimal point to provide fractional. This flag is only used for the number input type, otherwise null . Use const TextInputType. TextField 'keyboardType: TextInputType.number' doesn't bring the number keyboard on iOS12 & some Android devices (web) #58510 Open Numbers with decimal input not working on iOS 13 [web] #60426

pattern_formatter, A Flutter package provides some implementations of TextInputFormatter that format input with pre-defined patterns. Integer number: TextField( keyboardType: TextInputType.number, inputFormatters: Decimal number:. In this Google flutter code example we are going to learn how to create number input textfield in flutter. The code is based on flutter version 1.0.0 Main.dart (App entry point)

  • For me this is working. What does you mean by alpha works.
  • Alpha (A-Z) and also allows special characters like, +,-
  • What do you mean it allows alpha words? it is showing them but they are not clickable.
  • @CopsOnRoad, in my case it inputs alpha (a-z) and special characters.
  • @CopsOnRoad, I am entering data from hardware keyboard. So that is problem??
  • for restrict: RegExInputFormatter.withRegex('^[0-9]{0,6}(\\.[0-9]{0,2})?\$')
  • Does this work for locale's with commas instead of periods for the decimal character?
  • I haven't tried that. But I believe you need to update the regex for that.
  • TextInputType.numberWithOptions not working. I already mentioned in question.
  • @SagarZala I have added the screen. You can see its working.
  • on Huawei that is not working at all, Mate 20 pro, I can see the chars too with the numbers