mirror of
				https://github.com/AppFlowy-IO/AppFlowy.git
				synced 2025-11-04 12:03:28 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			25 lines
		
	
	
		
			380 B
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			25 lines
		
	
	
		
			380 B
		
	
	
	
		
			Dart
		
	
	
	
	
	
import 'dart:async';
 | 
						|
 | 
						|
import 'package:flutter/material.dart';
 | 
						|
 | 
						|
class Debounce {
 | 
						|
  final Duration duration;
 | 
						|
  Timer? _timer;
 | 
						|
 | 
						|
  Debounce({
 | 
						|
    this.duration = const Duration(milliseconds: 1000),
 | 
						|
  });
 | 
						|
 | 
						|
  void call(VoidCallback action) {
 | 
						|
    dispose();
 | 
						|
    _timer = Timer(duration, () {
 | 
						|
      action();
 | 
						|
    });
 | 
						|
  }
 | 
						|
 | 
						|
  void dispose() {
 | 
						|
    _timer?.cancel();
 | 
						|
    _timer = null;
 | 
						|
  }
 | 
						|
}
 |