cancelTimer static method

void cancelTimer(
  1. String widgetName
)

Implementation

static void cancelTimer(String widgetName) async {
  if (listOfScreens.containsKey(widgetName)) {
    listOfScreens.update(widgetName, (value) => value += timeOnScreen);
    var oldElement = listOfScreensModels
        .where((element) => element.name == widgetName)
        .first;
    var index = listOfScreensModels.indexOf(listOfScreensModels
        .where((element) => element.name == widgetName)
        .first);
    listOfScreensModels.removeAt(index);
    listOfScreensModels.insert(index,
        TimeTracingModel(oldElement.name, timeOnScreen += oldElement.time));
  } else {
    listOfScreens.addAll({widgetName: timeOnScreen});

    listOfScreensModels.add(TimeTracingModel(widgetName, timeOnScreen));
  }
  timeOnScreen = 0;
  allTimeInApp = 0;
  for (var element in listOfScreens.values) {
    allTimeInApp += element;
  }

  _timer.cancel();
}