findFlutterVersion method

Future<String?> findFlutterVersion(
  1. String username,
  2. InternetAddress ip,
  3. String flutterRunnerPath, {
  4. bool addHostToKnownHosts = true,
})

Implementation

Future<String?> findFlutterVersion(
  String username,
  InternetAddress ip,
  String flutterRunnerPath, {
  bool addHostToKnownHosts = true,
}) async {
  final spinner = interaction.spinner(
    inProgressMessage: 'Search for flutter version on remote device.',
    doneMessage: 'Search for flutter version completed',
    failedMessage: 'Search for flutter version failed',
  );

  final output = await processRunner.runCommand(
    hostPlatform.sshCommand(
      ipv6: ip.isIpv6,
      sshTarget: ip.sshTarget(username),
      command: '$flutterRunnerPath --version --machine',
      addHostToKnownHosts: addHostToKnownHosts,
    ),
    throwOnError: false,
    parseResult: (runResult) {
      final output = runResult.stdout.trim();

      if (runResult.exitCode != 0 && output.isEmpty) {
        logger.spaces();

        return null;
      }

      final jsonOutput = jsonDecode(output);

      logger.detail('Find Flutter Version jsonOutput: $jsonOutput');

      logger.detail(
          'Find Flutter Version jsonOutput[flutterVersion]: ${jsonOutput['flutterVersion']}');

      return jsonOutput['flutterVersion'] as String;
    },
    parseFail: (e, s) {
      logger.detail(
        'Something went wrong while trying to find flutter version. \n $e \n $s',
      );

      logger.spaces();

      return null;
    },
    spinner: spinner,
    label: 'Find Flutter Version',
    logger: logger,
  );

  logger.detail('Find Flutter Version output: $output');

  logger.spaces();

  return output;
}