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
)
);
}