ana*_*shi 3 android dart flutter
我有一个通过侦听值通知程序提供的整数值,我想在整数达到某个值后删除侦听器。
我曾尝试使用 'listener.removelisteners' 但我无法实现我想要的
void checktrials() {
trialsonline.addListener((){
print('started listener');
if(trialsonline.value==1){
print('out of trials');
trialsonline.value=0;
//here i want to remove the listener
}
});
}
Run Code Online (Sandbox Code Playgroud)
小智 6
var f;
f = () {
print('started listener');
if (trialsonline.value == 1) {
print('out of trials');
trialsonline.value = 0;
trialsonline.removeListener(f);
}
};
Run Code Online (Sandbox Code Playgroud)
并添加如下:
trialsonline.addListener(f);
Run Code Online (Sandbox Code Playgroud)