runFlutsim function

Future<void> runFlutsim()

Entrypoint for flutsim run command.

Implementation

Future<void> runFlutsim() async {
  print('πŸš€ Starting FlutSim...');

  // Check if Flutter is installed
  if (!await isFlutterInstalled()) {
    print('❌ Flutter is not installed or not found in PATH.');

    // Try to find Flutter installation
    final flutterPath = getFlutterPath();
    if (flutterPath != null) {
      print('βœ… Found Flutter at: $flutterPath');
      print('πŸ’‘ You can add this to your PATH or use the full path.');
    } else {
      print('πŸ’‘ To install Flutter:');
      print(
          '   1. Download from: https://docs.flutter.dev/get-started/install/windows');
      print('   2. Extract to C:\\flutter');
      print('   3. Add C:\\flutter\\bin to your PATH');
    }
    exit(1);
  }

  // Check if we're in a Flutter project directory
  if (!File('pubspec.yaml').existsSync()) {
    // Check if there's a testapp directory nearby
    final testappDir = Directory('testapp');
    if (testappDir.existsSync()) {
      print('πŸ“ Found testapp directory, navigating to it...');
      Directory.current = testappDir;
    } else {
      print('❌ No Flutter project found in current directory.');
      print('πŸ’‘ Available options:');
      print('   1. Navigate to a Flutter project directory');
      print('   2. Create a new project: flutsim create <project-name>');
      print('   3. Run from a directory with a testapp folder');
      exit(1);
    }
  }

  // Check if pubspec.yaml contains Flutter dependency
  final pubspecContent = File('pubspec.yaml').readAsStringSync();
  if (!pubspecContent.contains('flutter:') &&
      !pubspecContent.contains('sdk: flutter')) {
    print('❌ This does not appear to be a Flutter project.');
    print('πŸ’‘ Make sure pubspec.yaml contains Flutter dependencies.');
    exit(1);
  }

  print('βœ… Flutter project detected!');
  print('πŸš€ Starting web preview...');

  try {
    await runFlutsimPreview();
  } catch (e) {
    print('❌ Error running Flutter preview: $e');
    print('πŸ’‘ Make sure Flutter is properly installed and in your PATH.');
  }
}