I need to call all APIs and store a local database before login. I used the sqflite plugin. can't add background running, that's why I used await.

1st running storeRegister() after process completed then running storeEquipmentReg likewise.

button onPressed():

await HelperDatabase1().storeRegister(_url, tokens);
await HelperDatabase1().storeEquipmentReg(_url, tokens);
await HelperDatabase1().storeGetUserPreference(_url, tokens);
await HelperDatabase1().storeDefRegisterCat(_url, tokens);
await HelperDatabase1().storeDefCatMaster(_url, tokens);
await HelperDatabase1().storeDefCatRelation(_url, tokens);
await HelperDatabase1().storeWoDescription(_url, tokens);
await HelperDatabase1().storeAssetAssembly(_url, tokens);
await HelperDatabase1().storeCategoryDefect(_url, tokens);
await HelperDatabase1().storeWorkSource(_url, tokens);
await HelperDatabase1().storeWorkTypes(_url, tokens);
await HelperDatabase1().storePriorities(_url, tokens);
await HelperDatabase1().storeSignIn(1);
await HelperSync().insert(_url, tokens);
await Helper().insert(token);
Navigator.pop(context);
Navigator.of(context).pushNamedAndRemoveUntil('/listView', (Route<dynamic> route) => false);

example storeCategoryDefect method:(All other code same)

   storeCategoryDefect(String url, String token) async {
    var db = await db1;
    Batch batch = db.batch();
    final response = await http.get(
      '$url/nativeapi/v1.0/CategoryDefect',
      headers: {'Authorization': 'Bearer $token'},
    );
    final jsonResponse = json.decode(response.body);
    CategoryDefect model = CategoryDefect.fromJson(jsonResponse);
    int length = model.data.length;

    for (int i = 0; i < length; i++) {
      var data = DataCategoryDefect(
        i: model.data[i].i,
        d: model.data[i].d,
      );
      batch.insert(
        'CategoryDefectTable',
        data.toMap(),
      );
    }
    await batch.commit();
  }


Solution 1: Esen Mehmet

If you don't need to execute them in a specific order, you can execute them simultaneously like:

await Future.wait([
  HelperDatabase1().storeRegister(_url, tokens),
  HelperDatabase1().storeEquipmentReg(_url, tokens),
  HelperDatabase1().storeGetUserPreference(_url, tokens),
  HelperDatabase1().storeDefRegisterCat(_url, tokens),
  HelperDatabase1().storeDefCatMaster(_url, tokens),
  HelperDatabase1().storeDefCatRelation(_url, tokens),
  HelperDatabase1().storeWoDescription(_url, tokens),
  HelperDatabase1().storeAssetAssembly(_url, tokens),
  HelperDatabase1().storeCategoryDefect(_url, tokens),
  HelperDatabase1().storeWorkSource(_url, tokens),
  HelperDatabase1().storeWorkTypes(_url, tokens),
  HelperDatabase1().storePriorities(_url, tokens),
  HelperDatabase1().storeSignIn(1),
  HelperSync().insert(_url, tokens),
  Helper().insert(token),
]);

If you need to order them, then create await Future.wait batch instead like your example. For example, first priorities inside the first Future.wait, seconds are after first Future.wait bla bla...