checkIncompatiblePackages function

Future<Map<String, List<String>>> checkIncompatiblePackages(
  1. Map<String, Dependency> dependencies,
  2. List<String> platforms
)

A utility function to check for incompatible packages based on their platform support. It takes a map of dependencies and a list of platforms to check against. Returns a map with platform names as keys and lists of incompatible packages as values.

Implementation

Future<Map<String, List<String>>> checkIncompatiblePackages(
    Map<String, Dependency> dependencies, List<String> platforms) async {
  // Create an empty map to store the incompatible packages for each platform.
  Map<String, List<String>> incompatiblePackages = {};
  for (var platform in platforms) {
    // Initialize an empty list for each platform in the map.
    incompatiblePackages[platform] = [];
  }

  // Iterate through each package in the dependencies map.
  for (var package in dependencies.keys) {
    // Exclude "flutter" and "incompatible_package_checker" packages from the check.
    if (package != "flutter" && package != "incompatible_package_checker") {
      // Check if the package supports each platform in the provided list.
      final response = await packageSupportsPlatform(package);
      for (var platform in platforms) {
        // If the package doesn't support the platform, add it to the incompatiblePackages map.
        if (!response.contains(platform.toUpperCase())) {
          incompatiblePackages[platform]!.add(package);
        }
      }
    }
  }

  // Return the map of incompatible packages for each platform.
  return incompatiblePackages;
}