skip to Main Content

I’m facing a problem with Flutter where the "." (decimal point) character is missing from the keyboard when using TextInputType.number on iOS devices. I have set up the input formatters correctly to allow only digits and the "." character, but still, the "." character is not visible on the keyboard. Here’s my code snippet:

Container(
                                              width: 65.w,
                                              height: 6.w,
                                              child: TextFormField(
                                                // The validator receives the text that the user has entered.
                                                controller:
                                                    _currentWeightController,
                                                textAlign: TextAlign.left,
                                                keyboardType: TextInputType.number,
                                                inputFormatters: [
                                                  FilteringTextInputFormatter
                                                      .allow(RegExp('[0-9.]')),
                                                ],
                                                style: TextStyle(
                                                    fontSize: 20,
                                                    color: Colors.black),

                                                // decoration: InputDecoration(
                                                //   hintText:
                                                //       '${num.parse(measurementRes[targetWeight] ?? "0").ceil().toString()}',
                                                // ),
                                              ),
                                            ),

The code works perfectly on Android, showing both digits and the "." character on the keyboard. However, on iOS devices, the "." character is not visible on the keyboard. Any help would be much appreciated.

2

Answers


  1. I faced this before 🙂 Instead of using keyboardType: TextInputType.number, use:

    const TextInputType.numberWithOptions(
      {bool? signed = true/false,
      bool? decimal = true/false}
    )
    

    Reference: Official document: https://api.flutter.dev/flutter/services/TextInputType/TextInputType.numberWithOptions.html

    Edit 1: I found a problem in Samsung phone bases on this post: TextInputType.numberWithOptions doesn't show comma or dot. The answer & GitHub issue is under answers, you should notice that.

    Edit 2: Oh I just realize, in my Vietnam, we use "," for decimal point. But your formatter using "." for decimal point, therefore my keyboard is showing up "," button but cannot be pressed. Is this your problem?

    Login or Signup to reply.
  2. The problem is that in your code, you are using: TextInputType.number

    … Optimize for unsigned numerical information without a decimal point.

    ...
    keyboardType: TextInputType.number,
    

    You should instead use:

    keyboardType: const TextInputType.numberWithOptions(decimal: true),
    

    
    Container(
          width: 65.w,
          height: 6.w,
          child: TextFormField(
            // The validator receives the text that the user has entered.
            controller: _currentWeightController,
            textAlign: TextAlign.left,
            keyboardType: const TextInputType.numberWithOptions(decimal: true),
            inputFormatters: [
              FilteringTextInputFormatter.allow(RegExp('[0-9.]')),
            ],
            style: TextStyle(fontSize: 20, color: Colors.black),
    
            // decoration: InputDecoration(
            //   hintText:
            //       '${num.parse(measurementRes[targetWeight] ?? "0").ceil().toString()}',
            // ),
          ),
        )
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search