首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >How to debug "Instance of '.. Flutter

How to debug "Instance of '.. Flutter
EN

Stack Overflow用户
提问于 2020-02-29 02:33:51
回答 1查看 489关注 0票数 0

您好,我正在尝试打印从the服务接收到的内容的值,在本例中为Firebase Auth。当我尝试打印值时,它只显示"Instance of 'PlatformUser'“我猜里面有一个对象,我可以去搜索模型,但这需要一些时间,有没有办法在控制台中打印整个对象?

这是我的代码。

代码语言:javascript
复制
 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;
}

}

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2020-02-29 03:14:53

如果您想要检查您正在使用的对象(很可能是dynamic),请使用以下命令:

代码语言:javascript
复制
print('Type: ${user.runtimeType.toString()}')

这样,您现在就可以使用result 作为来自运行时类型的对象的

示例:

代码语言:javascript
复制
val user = result.user as PlatformUser;
// now you can use every benefits from PlatformUser while using user

要覆盖toString(),您需要拥有对该对象的写访问权限,并执行以下操作:

代码语言:javascript
复制
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';
  }
}

打印的内容:

代码语言:javascript
复制
I/flutter ( 7097): Lat: 4.92939 - Long: 74.912829
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60457449

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档