正文
-
initState() 是一个无返回值的函数,如果要在这里请求数据,不能在这个函数中添加async/await。重新定义一个async函数,在其中调用即可。
-
在两个文件中定义两个写法完全相同的类,这两个类的实例在相互赋值时报错,说明类不同。
-
不是说无状态的widget里面不能定义属性,而是无状态中的属性不能随着页面操作变化。
-
Column 的宽度,取子组件中宽度最大值
-
如果导入没有
null safe
的package,则flutter2.x报错。需要找到支持null safe
的版本 -
Try catch 中间可以增加on关键字,后面跟着Error类型,表示捕获特定错误。可以有多个,on拦截后不再往后走。
-
组件的宽/高占满容器:
width: double.infinity
-
Flutter web调试出现跨域问题(修改flutter的sdk)
-
Provider 中的 read和context.of方法有何区别?
- 后者是在widget中使用的,后者在其外
-
dio post中data和queryParameters不同
-
if(!obj){ print('这个对象是空的'); } //上述代码错误,下面代码正确 if(obj == null){ print('这个对象是空的'); }
-
/* The following assertion was thrown while finalizing the widget tree: Looking up a deactivated widget's ancestor is unsafe. At this point the state of the widget's element tree is no longer stable. To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor by calling dependOnInheritedWidgetOfExactType() in the widget's didChangeDependencies() method. When the exception was thrown, this was the stack: */ //出现在页面跳转时 Navigator.pushNamed(context, ''); //不报错 Navigator.popAndPushNamed(context, ''); //报错
不要把context夸页面传递
-
跳转至二级页面或者从二级页面返回,都不会触发一级的生命周期函数,但会触发二级页面的生命周期函数
-
EventBus (event_bus )(破玩意,连个单事件关闭监听都没有?)的
destroy()
就直接把车关闭了,也不能再添加监听,那多次用到车还要创建多个车吗?或者只用一个车,然后每个页面的监听都一直开着,无非是多声明几个事件类型?- 事件车关闭后,所有事件都会默认关闭吗?
是的,也许是这个插件不好用,也许是我不会用。
- 事件车关闭后,所有事件都会默认关闭吗?
总结
- 上周有点怠惰,这周加油。