From 8c582153f8f3e1f678655e1e7c1c00d8ca86abff Mon Sep 17 00:00:00 2001 From: abdorizak Date: Sun, 30 Apr 2023 22:14:03 +0300 Subject: [PATCH] Fixed _CastError thrown while calling onChanged with null value #52 --- lib/otp_field.dart | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/otp_field.dart b/lib/otp_field.dart index 279571d..f16ca88 100644 --- a/lib/otp_field.dart +++ b/lib/otp_field.dart @@ -241,8 +241,11 @@ class _OTPTextFieldState extends State { widget.onCompleted?.call(currentPin); } - // Call the `onChanged` callback function - widget.onChanged!(currentPin); + // Call the `onChanged` callback function -- deprecated + // widget.onChanged!(currentPin); this will cause _CastError which means onChanged is null + + // Call the `onChanged` callback function if it exists + widget.onChanged?.call(currentPin); }, ), );