WidgetsBinding
//Schedule a callback for the end of this frame
addPostFrameCallback(FrameCallback callback) → void
這個方法的意思是此幀結(jié)束時的蜂奸,應(yīng)該不局限于開始的第一幀(觸發(fā)待研究),如果我們在initState里面加入此監(jiān)聽舌稀,那就美妙了,等Build結(jié)束建车,你的回調(diào)就會執(zhí)行
@override
void initState() {
super.initState();
widgetsBinding=WidgetsBinding.instance;
widgetsBinding.addPostFrameCallback((callback){
print("addPostFrameCallback be invoke");
});
}
監(jiān)聽每一幀結(jié)束
addPersistentFrameCallback
@override
void initState() {
super.initState();
widgetsBinding=WidgetsBinding.instance;
widgetsBinding.addPostFrameCallback((callback){
widgetsBinding.addPersistentFrameCallback((callback){
print("addPersistentFrameCallback be invoke");
//觸發(fā)一幀的繪制
widgetsBinding.scheduleFrame();
});
});
}