checkAndActivateWebdev function

Future<void> checkAndActivateWebdev({
  1. bool? verbose,
})

Check if webdev is activated.

Implementation

Future<void> checkAndActivateWebdev({bool? verbose}) async {
  var webdev = 'webdev';
  verbose ??= false;
  await checkAndActivatePackage(webdev, verbose: verbose);

  var needUpdate = false;
  try {
    var lines =
        (await run('dart pub global run $webdev --version', verbose: verbose))
            .outLines
            .toList();
    var webdevVersion = extractWebdevVersionFromOutLines(lines);
    if (webdevVersion == null) {
      // ignore: avoid_print
      print('failed to get webdev version');
      needUpdate = true;
    } else
    // Handle flutter dart 2.19
    if (dartVersion >= Version(2, 19, 0, pre: '0') &&
        (webdevVersion <= Version(2, 7, 11))) {
      needUpdate = true;
    }
  } catch (e) {
    // ignore: avoid_print
    print('failed to get webdev version $e');
    needUpdate = true;
  }

  if (needUpdate) {
    await _pubGlobalActivate(webdev);
  }
}