Skip to content

getInstalledApps() blocks the UI #18

@sfabio01

Description

@sfabio01

As per the title, while appCheck.getInstalledApps() is being executed, the entire UI is completely blocked.

Code snippet:

void initState() {
    super.initState();
    _loadApps();
}

Future<void> _loadApps() async {
    AppCheck appCheck = AppCheck();
    List<AppInfo>? apps = await appCheck.getInstalledApps();
	setState(() {
        _allApps = apps!;
    });
}

I also tried running getInstalledApps in a different Isolate, but it blocks the UI anyway:

static Future<void> _getAppsInIsolate(Map<String, dynamic> args) async {
    SendPort sendPort = args['sendPort'];
    RootIsolateToken rootIsolateToken = args['rootIsolateToken'];
    BackgroundIsolateBinaryMessenger.ensureInitialized(rootIsolateToken);
    List<AppInfo>? apps = await AppCheck().getInstalledApps();
    sendPort.send(apps);
  } 

Future<void> _loadApps() async {
      // Create a ReceivePort to get results from the isolate
      ReceivePort receivePort = ReceivePort();
      RootIsolateToken rootIsolateToken = RootIsolateToken.instance!;
      // Spawn the isolate
      Isolate isolate = await Isolate.spawn(_getAppsInIsolate, {
        "rootIsolateToken": rootIsolateToken,
        "sendPort": receivePort.sendPort,
      });

      // Listen for the result
      final result = await receivePort.first;

	  _allApps = result as List<AppInfo>;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions