标签:isa cti onchange fun super import pre time listen
import 'dart:async';
Function debounce(Function fn, [int t = 30]) {
Timer _debounce;
return () {
// 还在时间之内,抛弃上一次
if (_debounce?.isActive ?? false) _debounce.cancel();
_debounce = Timer(Duration(milliseconds: t), () {
fn();
});
};
}
RaisedButton(
onPressed: debounce(() {
print(1);
}, 3000),
child: Text('Test'),
)
import 'package:rxdart/rxdart.dart';
final _counterSubject = BehaviorSubject<int>();
@override
void initState() {
super.initState();
_counterSubject.debounceTime(Duration(seconds: 2)).listen((int i) {
print(i);
});
}
RaisedButton(
onPressed: () {
_counterSubject.add(1);
},
child: Text('Test'),
)
标签:isa cti onchange fun super import pre time listen
原文地址:https://www.cnblogs.com/ajanuw/p/11148708.html