Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter : Keyboard without decimal point

I need a numberInputKeyboard which only has numbers (without decimal symbol). I have tried with keyboardType: TextInputType.numberWithOptions(decimal: false) but still this dosen't help me

like image 408
Santhosh Avatar asked Aug 21 '19 09:08

Santhosh


2 Answers

One answer recommends using a BlacklistingTextInputFormatter which certainly works in your case with English locale. This however might not work with other locales which use a , instead of a . as decimal seperator.

So I'd recommend using a WhitelistingTextInputFormatter:

import "package:flutter/services.dart";
TextFormField(
  keyboardType: TextInputType.number,
  inputFormatters: [WhitelistingTextInputFormatter.digitsOnly],
)

This will only allows the digits [0-9].

UPDATE:

The WhitelistingTextInputFormatter as been renamed! The following is the up-to date version and no longer deprecated by FilteringTextInputFormatter.allow and provides a shortcut for the digits as well:

import "package:flutter/services.dart";
TextFormField(
  keyboardType: TextInputType.number,
  inputFormatters: [FilteringTextInputFormatter.digitsOnly],
)
like image 177
ChrisG Avatar answered Oct 13 '22 08:10

ChrisG


First Approach :-

As per this stackoverflow answer you must have to create your custom keyboard for it.

Android - is it possible to hide certain characters from the soft keyboard?

Second Approach :-

You can do black list that stuff with RegExp, in this case you can't input dot(.).

For more you can refer this : https://api.flutter.dev/flutter/services/TextInputFormatter-class.html

        body: Center(
            child: TextFormField(
            decoration: InputDecoration(
                labelText: "Title",
                suffixIcon: GestureDetector(
                onTap: () {
                    setState(() {

                    });
                },
                child: Icon(Icons.clear),
                )),
            inputFormatters: [
               BlacklistingTextInputFormatter(RegExp("[.]"))
            ],
        )));
like image 2
Amit Prajapati Avatar answered Oct 13 '22 10:10

Amit Prajapati