The argument type 'String' can't be assigned to the parameter type 'num' in Flutter's onChange method

78 Views Asked by At

I'm encountering an error in my Flutter app when trying to log the Change object in the onChange method of my Cubit. The error message is as follows:

Error: The argument type 'String' can't be assigned to the parameter type 'num'

This error is pointing to the line where I'm logging the Change object using log(change.toString());. I understand that this error occurs because I'm trying to log a String as a num, which is not allowed in Dart.

I want to understand how to correctly log the Change object as a `String without encountering this error.

Here's the relevant code snippet: '''

@override
void onChange(Change<PaymentState> change) {
  log(change.toString()); // Error occurs on this line
  super.onChange(change);
}

I would appreciate any insights or suggestions on how to resolve this error and correctly log the Change object as a `String in Flutter.

1

There are 1 best solutions below

0
Cabdirashiid On

Use debugPrint() like debugPrnt(change.toString())

Prints a message to the console, which you can access using the "flutter" tool's "logs" command ("flutter logs").


Edit debugPrint(String?, {int? wrapWidth}) is a function of package:flutter/src/foundation/print.dart.

For dart use print(Object? object)

Prints a string representation of the object to the console.