-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_flutter_version.dart
More file actions
56 lines (47 loc) · 1.91 KB
/
check_flutter_version.dart
File metadata and controls
56 lines (47 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import 'dart:io';
Future<String> getFlutterVersion() async {
// Specify the full path to the flutter executable
final flutterPath = 'D:/Setup/Flutter/flutter_windows_3.19.5-stable/flutter/bin/flutter.bat'; // Ensure the path includes 'flutter.bat'
final process = await Process.start(flutterPath, ['--version']);
final output = await process.stdout.transform(SystemEncoding().decoder).join();
final errorOutput = await process.stderr.transform(SystemEncoding().decoder).join();
final exitCode = await process.exitCode;
if (exitCode != 0) {
throw Exception('Failed to get Flutter version: $errorOutput');
}
final versionLine = output.split('\n').firstWhere((line) => line.contains('Flutter'));
final version = versionLine.split(' ')[1];
return version;
}
Future<String> choosePackageVersion(String packageName, String flutterVersion) async {
if (packageName == 'console_color') {
// Example logic for choosing a version based on Flutter version
if (flutterVersion.startsWith('2.')) {
return '1.0.0';
} else if (flutterVersion.startsWith('3.')) {
return '2.0.0';
}
}
// Default to a valid version constraint
return '^1.0.0';
}
void main() async {
try {
final flutterVersion = await getFlutterVersion();
print('Current Flutter version: $flutterVersion');
final packageFile = File('./packages.txt'); // Updated to look in the current directory
if (!packageFile.existsSync()) {
print('packages.txt not found.');
return;
}
final packageContent = await packageFile.readAsString();
final packageLines = packageContent.split('\n').where((line) => line.trim().isNotEmpty);
for (var line in packageLines) {
final packageName = line.trim();
final packageVersion = await choosePackageVersion(packageName, flutterVersion);
print('Chosen version for $packageName: $packageVersion');
}
} catch (e) {
print('Error: $e');
}
}