fix method
Fix the issues in the Flutter project
Implementation
Future<List<String>> fix({bool applyAll = false}) async {
final fixedIssues = <String>[];
if (issues.isEmpty) {
await check();
}
for (final issue in issues) {
bool shouldFix = applyAll;
if (!applyAll) {
// Interactive mode - ask for confirmation for each issue
Logger.info('\n${issue.toString()}');
stdout.write('Do you want to fix this issue? (y/n): ');
final response = stdin.readLineSync()?.toLowerCase();
shouldFix = response == 'y' || response == 'yes';
}
if (shouldFix) {
bool fixed = false;
// Try Gradle fixer first
fixed = await GradleFixer.fixIssue(
issue,
dryRun: dryRun,
backup: backup,
);
// If not fixed, try Kotlin fixer
if (!fixed) {
fixed = await KotlinFixer.fixIssue(
issue,
dryRun: dryRun,
backup: backup,
);
}
if (fixed) {
final message =
dryRun
? 'Would fix: ${issue.description}'
: 'Fixed: ${issue.description}';
fixedIssues.add(message);
Logger.success(message);
} else {
Logger.error('Could not automatically fix: ${issue.description}');
}
}
}
return fixedIssues;
}