runFlutsim function
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.');
}
}