provideEmbedderPath method

  1. @override
Future<String> provideEmbedderPath()
override

Implementation

@override
Future<String> provideEmbedderPath() async {
  if (context.targetIp == null || context.username == null) {
    throwToolExit(
        'Target IP and username are required to provide the embedder path.');
  }

  final username = context.username!;
  final targetIp = context.targetIp!;

  logger.info('Searching for flutter-pi on the remote machine...');
  logger.spaces();

  final possibleFlutterPath = await remoteControllerService.findToolPath(
      username: username,
      ip: targetIp,
      toolName: 'flutter-pi',
      preferredPaths: [
        '/usr/local/bin',
      ]);

  if (possibleFlutterPath?.isNotEmpty == true) {
    logger.detail('flutter-pi found path: $possibleFlutterPath');

    logger.success('flutter-pi found on the remote machine.');
    logger.spaces();

    return possibleFlutterPath!;
  }

  logger.info('''
Could not find flutter-pi in the remote machine automatically.
We need the exact path of your flutter-pi command line tools on the remote device.
Now you have two options:
1. You can enter the path to flutter manually.
2 We can install flutter-pi on the remote machine for you.
''');

  logger.spaces();

  final provideFlutterPiPathOption = interaction.selectIndex(
    'Please select one of the options:',
    options: [
      'Install flutter-pi on the remote machine',
      'Enter flutter-pi path manually',
    ],
  );

  logger.spaces();

  if (provideFlutterPiPathOption == 0) {
    return _installFlutterPiOnRemote(username, targetIp);
  }

  return interaction.readToolManualPath(
    toolName: 'flutter-pi',
    examplePath: '/usr/local/bin/flutter-pi',
  );
}