skip to Main Content

I am trying to get list of installed apps and able to get it using mentioned code. How to make this forEach information into Json list to save it to server as json

  Future<void> getinstalledAppList() async{
    List<Application> apps = await DeviceApps.getInstalledApplications();

    apps.forEach((app) {
      var jsonList = app.appName;
      print(jsonList);
    });

  }

Output of print is like below :

I/flutter ( 5465): WooCommerce
I/flutter ( 5465): Amazon
I/flutter ( 5465): Weather
I/flutter ( 5465): OfficeSuite

I need output like:

{'WooCommerce', 'Amazon', 'Weather' , 'OfficeSuite'}

2

Answers


  1. You can define a global app name list. And push items into this list. After that, you can easily send it to the server. It will look like this:

    
      List<String> appNameList = List<String>();
    
      Future<void> getinstalledAppList() async {
        List<Application> apps = await DeviceApps.getInstalledApplications();
    
        apps.forEach((app) {
          var jsonList = app.appName;
    
          appNameList.add(app.appName); // Here we add them to a string list.
          print(jsonList);
        });
      }
    
    
      Future<void> callThisFunction(List<String> appNameList) async {
        // Here we can send the list to server
        await saveAppNameListToServer(appNameList);
      }
    
    
    Login or Signup to reply.
  2. You can use the following code which will extract appName from the application and make a list of it. You can directly write that list If you want JSON array in string format then you can make use of jsonEncode()

    var appNamesList = apps.map((app)=>app.appName).toList();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search