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
      )
    );
  }
9
  • Check this: stackoverflow.com/questions/49577781/… Commented Sep 19, 2022 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) Commented Sep 19, 2022 at 17:20
  • Can you include a sample full widget that will reproduce the same issue Commented Sep 19, 2022 at 17:51
  • The error appears using an Android Physical Device Commented Sep 19, 2022 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. Commented Sep 19, 2022 at 21:31

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.