Flutter 颤振方法在完成之前跳跃
在调试模式下,我发现我的方法Flutter 颤振方法在完成之前跳跃,flutter,Flutter,在调试模式下,我发现我的方法 DatabaseProvider.db.insert(newShift).then((storedShift){…} 在完成所有步骤之前跳到下一个步骤,然后返回以完成这些步骤 我阅读了文档,其中说明如果.then未来已经完成,则不会立即调用内部回调,而是在稍后的微任务中进行调度 如何管理它,以便在方法中找到的回调立即完成 以下是完整的代码: onPressed: () { _formKey.currentState.save
DatabaseProvider.db.insert(newShift).then((storedShift){…}
在完成所有步骤之前跳到下一个步骤,然后返回以完成这些步骤
我阅读了文档,其中说明如果.then未来已经完成,则不会立即调用内部回调,而是在稍后的微任务中进行调度
如何管理它,以便在方法中找到的回调立即完成
以下是完整的代码:
onPressed: () {
_formKey.currentState.save();
// for the Database
Shift newShift = new Shift(
dateOfShift: _dateOfShift,
dateOfShiftString: _dateformat.format(_dateOfShift),
// dateOfShiftString: new DateFormat.yMd(_dateOfShift),
startOfShiftTime: _startOfShiftTime,
endOfShiftTime: _endOfShiftTime,
designation: _designation,
employee: _employee,
// when creating a new shift there is no index. Thus it takes the value -1
indexForWidget: _indexForWidget);
DatabaseProvider.db.insert(newShift).then((storedShift) {
// get the id of the db
print(newShift);
// insert to database
BlocProvider.of<ShiftBloc>(context).add(
AddShift(storedShift),
);
// get the id of the db
print(newShift);
});
// insert to the static Map
if (customEvents[_dateOfShift] != null) {
// in case this is the first shift for this date
customEvents[_dateOfShift]
.add(_buildShiftContainer(shift: newShift));
} else {
// in case there are already registered shifts
customEvents[_dateOfShift] = [
_buildShiftContainer(shift: newShift)
];
}
// giving back an object
Navigator.pop(context, newShift);
}
onPressed:(){
_formKey.currentState.save();
//对于数据库
班次新闻班次=新班次(
换班日期:_换班日期,
dateOfShift字符串:_dateformat.format(_dateOfShift),
//dateOfShift字符串:新的DateFormat.yMd(_dateOfShift),
startOfShiftTime:\u startOfShiftTime,
endOfShiftTime:\u endOfShiftTime,
名称:_名称,
雇员:_雇员,
//当创建一个新的班次时,没有索引。因此它的值为-1
indexForWidget:_indexForWidget);
DatabaseProvider.db.insert(newShift).然后((storedShift){
//获取数据库的id
印刷品(新闻班);
//插入到数据库
BlocProvider.of(上下文)。添加(
添加移位(存储移位),
);
//获取数据库的id
印刷品(新闻班);
});
//插入到静态映射中
如果(customEvents[\u dateOfShift]!=null){
//如果这是该日期的第一班
customEvents[\u dateOfShift]
.add(_buildShiftContainer(shift:newShift));
}否则{
//如果已经登记了班次
customEvents[\u dateOfShift]=[
_buildShiftContainer(班次:newShift)
];
}
//归还物品
pop(上下文,newShift);
}