其实在业务请求接口中是会经常容易范的一个错误,虽然平常写业务组件没感觉有什么问题,但是到了联调接口就报错了,而且吧你总会以为你的布局或是组件写的有问题了。。。
具体报错如下:
1 2 3 4 5 6 7 8 9 |
════════ Exception caught by widgets library ═══════════════════════════════════ The following assertion was thrown building: A non-null String must be provided to a Text widget. 'package:flutter/src/widgets/text.dart': Failed assertion: line 269 pos 10: 'data != null' Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause. In either case, please report this assertion by filing a bug on GitHub: https://github.com/flutter/flutter/issues/new?template=BUG.md |
flutter现在抛出错误比之前友好了很多,但是可能很多新入坑的小伙伴就会查找很久原因了,加上之前老是重复踩此坑就特此总结一下。
写组件页面的时候,不可能实时给你接口的,所以在布局的时候感觉写完成了,但一接入接口就感觉不对劲,有的时候排查甚至怀疑布局写的有问题。
出现此错误看到抛出Failed assertion: line 269 pos 10: 'data != null',大体就知道是你的数据内并没有内容。
另外flutter抛出来了是Text widget.出现这样的情况,所以此错误就很明显了,你引入的组件在调用接口返回过来的数据并没有内容,或没有此字段。
请查看你的接口字段返回是否写对。
特别是你在写一个大的组件的时候可能一下盲写很多代码在调试,或许就有点找不到头了,无法定位。