isLocalVersion method

bool isLocalVersion({
  1. required String current,
  2. required String latest,
})

Returns true if the local version is larger than the latest version

0.0.1 (local) > 0.0.0 (latest)

Implementation

bool isLocalVersion({
  required String current,
  required String latest,
}) {
  final latestPlus =
      latest.contains('+') ? latest.replaceAll(RegExp(r'.*(?=\+)'), '') : '';
  final currentPlus = current.contains('+')
      ? current.replaceAll(RegExp(r'.*(?=\+)'), '')
      : '';

  final latestSplit = latest.replaceAll(latestPlus, '').split('.');
  final currentSplit = current.replaceAll(currentPlus, '').split('.');

  for (var i = 0; i < latestSplit.length; i++) {
    final latest = int.tryParse(latestSplit[i]) ?? 0;
    final current = int.tryParse(currentSplit[i]) ?? 0;

    if (current > latest) {
      return true;
    }
  }

  if (latestPlus != currentPlus) {
    final latest = int.tryParse(latestPlus) ?? 0;
    final current = int.tryParse(currentPlus) ?? 0;

    if (current > latest) {
      return true;
    }
  }

  return false;
}