removeToken method

Future<void> removeToken(
  1. String tokenKey
)

Removes a non-locked token.

Locked tokens cannot be removed.

Implementation

Future<void> removeToken(String tokenKey) async {
  final token = _config.tokenDefs
      .where((item) => item.key == tokenKey)
      .firstOrNull;

  if (token == null || token.locked) {
    return;
  }

  final tokens = _config.tokenDefs
      .where((item) => item.key != tokenKey)
      .toList();

  final light = Map<String, int>.from(_config.light)..remove(tokenKey);

  final dark = Map<String, int>.from(_config.dark)..remove(tokenKey);

  _config = _copyConfig(_config, tokenDefs: tokens, light: light, dark: dark);

  await _storage.save(_config);
  notifyListeners();
}