vishesh005 / app_utils

Application utility plugin for Android and iOS
MIT License
1 stars 1 forks source link

Null exception when querying for app version #3

Closed ashwin-dailype closed 1 year ago

ashwin-dailype commented 1 year ago

Summary

When using getInstalledApps() method to get the installed apps on my device, I'm getting a null exception inside the models.dart file where fromJson method looks for the version key in this line. https://github.com/vishesh005/app_utils/blob/c6c24d4c60a23965b53fd1c3db49c4578529759c/lib/models.dart#L15

Logs

I/flutter (17561): type 'Null' is not a subtype of type 'String'
I/flutter (17561): #0      BundleInfo.fromJson                                                            models.dart:15
I/flutter (17561): #1      AppUtils.getInstalledApps.<anonymous closure>                                        app_utils.dart:49
I/flutter (17561): #2      MappedListIterable.elementAt (dart:_internal/iterable.dart:415:31)
I/flutter (17561): #3      ListIterator.moveNext (dart:_internal/iterable.dart:344:26)
I/flutter (17561): #4      new _List._ofEfficientLengthIterable (dart:core-patch/array.dart:162:27)
I/flutter (17561): #5      new _List.of (dart:core-patch/array.dart:127:20)
I/flutter (17561): #6      new List.of (dart:core-patch/array_patch.dart:49:20)
I/flutter (17561): #7      ListIterable.toList (dart:_internal/iterable.dart:214:7)
I/flutter (17561): #8      AppUtils.getInstalledApps                                        app_utils.dart:50
I/flutter (17561): <asynchronous suspension>
I/flutter (17561): #9      getInstalledApps                                        apps_service.dart:65
I/flutter (17561): <asynchronous suspension>

Code

This is the code I wrote using the package

  List<BundleInfo> apps = await AppUtils.getInstalledApps();
  List<Map<String, String>> finalList = [];
  for (var element in apps) {
    finalList.add({
      'name': element.appName,
      'package': element.appIdentifier,
      'version': element.version,
    });
  }
vishesh005 commented 1 year ago

I will keep this open until the fix is applied to pub.dev.