hide method

void hide({
  1. Object? id,
})

If id is provided closes loader with given id If not closes latest shown loader

Implementation

void hide({Object? id}) {
  if (_routes.isNull) {
    Logger.logMsg(
      msg: 'There is no loader to hide',
      color: LogColors.red,
    );
    return;
  }
  assert(
    id.isNull || _routes!.where((element) => element.id == id).toList().isNotEmpty,
    'Tried to close loader with id: $id which does not exist',
  );
  assert(_key.currentState.isNotNull, 'Tried to hide dialog but navigatorState was null. Key was :$_key');
  final navigatorState = _key.currentState!;
  if (id.isNull) {
    navigatorState.removeRoute(_routes!.removeLast());
    if (_routes!.isEmpty) {
      _routes = null;
    }
  } else {
    final routeIndex = _routes!.indexWhere((element) => element.id == id);
    navigatorState.removeRoute(_routes!.removeAt(routeIndex));
    if (_routes!.isEmpty) {
      _routes = null;
    }
  }
}