LCOV - code coverage report
Current view: top level - lib/_classes/controller - delayed_call.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 9 12 75.0 %
Date: 2024-10-04 11:12:13 Functions: 0 0 -

          Line data    Source code
       1             : // Copyright 2023 The terCAD team. All rights reserved.
       2             : // Use of this source code is governed by a CC BY-NC-ND 4.0 license that can be found in the LICENSE file.
       3             : 
       4             : import 'dart:async';
       5             : import 'package:flutter/material.dart';
       6             : 
       7             : class DelayedCall {
       8             :   final int delay;
       9             :   Timer? _timer;
      10             :   VoidCallback? _action;
      11             :   bool preserveFirst;
      12             : 
      13           1 :   DelayedCall(this.delay, {this.preserveFirst = false});
      14             : 
      15           1 :   void run(VoidCallback action) {
      16           2 :     _timer?.cancel();
      17           1 :     if (!preserveFirst || _action == null) {
      18           1 :       _action = action;
      19             :     }
      20           5 :     _timer = Timer(Duration(milliseconds: delay), () {
      21           1 :       final v = _action;
      22           1 :       _action = null;
      23           1 :       v?.call();
      24             :     });
      25             :   }
      26             : 
      27           0 :   void cancel() {
      28           0 :     _action?.call();
      29           0 :     _timer?.cancel();
      30             :   }
      31             : }

Generated by: LCOV version 1.14