Passing custom object through method channel flutter

you can use invokeMapMethod which is an implementation of invokeMethod that can return typed maps. like this :

final result = await platform.invokeMapMethod('loginUser', ...);

or you can pass json object as string like that :

in android

platform.success(
    "{\"CREDITS\":\"${user.credits}\",\"EMAIL\":\"${user.email}\",\"LAST_ACTIVE\":\"${user.lastActiveAt}\"}"
)

in flutter

var result = await methodChannel.invokeMethod('loginUser' , '');
var json = json.decode(result);

var credit = json['CREDITS'];
var email = json['EMAIL'];
var lastActive = json['LAST_ACTIVE'];

You can pass data in hash map.

In Android:

result.success(hashMapOf(
    "CREDITS" to user.credits,
    "EMAIL" to user.email,
    ...
))

In iOS:

let data: [String: Any] = [...]
result(data)

In Flutter:

final result = await platform.invokeMethod<Map<String, dynamic>>('loginUser', ...);
final credits = result['CREDITS'] as String;
final email = result['EMAIL'] as String;
...