2

With the Flutter update I started noticing that numeric text boxes get an error when they are empty.

I managed to reduce the code to the minimum expression to identify the source of the error and apparently it is at the moment of defining the keyboard. The code that presents the error is the following:

TextField(
        controller: numController, //It's a TextEditingController()
        keyboardType: TextInputType.number
)

When I select the box to enter the number, this is the error that appears on console:

════════ Exception caught by services library ════════

The following _CastError was thrown during method call TextInputClient.performPrivateCommand: Null check operator used on a null value

When the exception was thrown, this was the stack #0 EditableTextState.performPrivateCommand package:flutter/…/widgets/editable_text.dart:2155 #1 TextInput._handleTextInputInvocation package:flutter/…/services/text_input.dart:1821 #2 TextInput._loudlyHandleTextInputInvocation package:flutter/…/services/text_input.dart:1701 #3 MethodChannel._handleAsMethodCall package:flutter/…/services/platform_channel.dart:536 #4 MethodChannel.setMethodCallHandler. package:flutter/…/services/platform_channel.dart:529 #5 _DefaultBinaryMessenger.setMessageHandler. package:flutter/…/services/binding.dart:387 #6 _invoke2 (dart:ui/hooks.dart:186:13) #7 _ChannelCallbackRecord.invoke (dart:ui/channel_buffers.dart:42:5) #8 _Channel.push (dart:ui/channel_buffers.dart:132:31) #9 ChannelBuffers.push (dart:ui/channel_buffers.dart:329:17) #10 PlatformDispatcher._dispatchPlatformMessage (dart:ui/platform_dispatcher.dart:599:22) #11 _dispatchPlatformMessage (dart:ui/hooks.dart:89:31) call: MethodCall(TextInputClient.performPrivateCommand, [13, {data: {}, action: Normal_Mode}]) ═══════════════════════════════════════

If I don't put a numeric keyboard, the error disappears.

The questions are:

1. How to fix the error?

2. How should a numeric keyboard type be properly defined?

UPDATE: The full code is as follows:

import 'package:flutter/material.dart';

class Prueba extends StatefulWidget {
  const Prueba({Key? key}) : super(key: key);

  @override
  State<Prueba> createState() => _PruebaState();
}

class _PruebaState extends State<Prueba> {

  final numController             = TextEditingController();

  @override
  Widget build(BuildContext context) {

    return Scaffold(
      appBar: AppBar(
        title: const Text('Test'),
      ),
      body: TextField(
        controller: numController,
        keyboardType: TextInputType.number
      )
    );
  }
David L
  • 1,134
  • 7
  • 35
  • Check this: https://stackoverflow.com/questions/49577781/how-to-create-number-input-field-in-flutter – Paulo Belo Sep 19 '22 at 17:11
  • Thank you @PauloBelo. It doesn't work right now. I think a Cast Error is appearing in flutter new versions (3.3.1 or later) – David L Sep 19 '22 at 17:20
  • Can you include a sample full widget that will reproduce the same issue – Md. Yeasin Sheikh Sep 19 '22 at 17:51
  • The error appears using an Android Physical Device – David L Sep 19 '22 at 20:00
  • It was good to open an issue for this problem on the flutter channel, another detail that this problem appears on android and samsung devices have an error in 100% of the cases. In version 3.3 there are some very critical problems on the part of flutter, such as the pageview line 455 value being initialized null and causing white screen where there is tabview or pageview. – Chance Sep 19 '22 at 21:31
  • Line 2155 editable_text: `widget.onAppPrivateCommand!(action, data);`. Yet another case of a null statement that fails. Interim fix made in flutter code: `if(widget.onAppPrivateCommand != null)widget.onAppPrivateCommand!(action, data);`. – Chance Sep 19 '22 at 21:33
  • Thanks @Chance. Great to know that an issue was open on the flutter channel. How can I follow it? – David L Sep 19 '22 at 21:55
  • Sorry I expressed myself wrong, there is still no issue for this problem. I said that an issue could be opened for this problem. – Chance Sep 19 '22 at 22:13
  • Issue on the flutter channel... https://github.com/flutter/flutter/issues/111939 – David L Sep 20 '22 at 02:14

0 Answers0