您好,我正在尝试打印从the服务接收到的内容的值,在本例中为Firebase Auth。当我尝试打印值时,它只显示"Instance of 'PlatformUser'“我猜里面有一个对象,我可以去搜索模型,但这需要一些时间,有没有办法在控制台中打印整个对象?
这是我的代码。
Future signInWithEmail(String email, String password) async {
try{
AuthResult result = await _auth.signInWithEmailAndPassword(email: email, password: password);
FirebaseUser user = result.user;
return user;
}catch(e){
print(e);
return null;
}}
谢谢。
发布于 2020-02-29 03:14:53
如果您想要检查您正在使用的对象(很可能是dynamic),请使用以下命令:
print('Type: ${user.runtimeType.toString()}')这样,您现在就可以使用result 作为来自运行时类型的对象的。
示例:
val user = result.user as PlatformUser;
// now you can use every benefits from PlatformUser while using user要覆盖toString(),您需要拥有对该对象的写访问权限,并执行以下操作:
final _latLong = LatLong(4.92939, 74.912829);
print(_latLong.toString());
class LatLong {
double lat;
double long;
LatLong(this.lat, this.long);
@override
String toString() {
return 'Lat: $lat - Long: $long';
}
}打印的内容:
I/flutter ( 7097): Lat: 4.92939 - Long: 74.912829https://stackoverflow.com/questions/60457449
复制相似问题