getAccountList method
Implementation
@override
Future<List<AccountGroupModel>> getAccountList() async {
// ignore: deprecated_member_use
PermissionStatus result = await Permission.calendar.request();
List<AccountGroupModel> accounts = [];
if (result.isGranted) {
String? accountList =
await methodChannel.invokeMethod<String?>('getAccountList');
Map accountMap = json.decode(accountList ?? "");
if (accountMap["accounts"] is List<Object?>) {
for (var account in accountMap["accounts"]) {
if (account is Map) {
if (accounts
.any((element) => element.groupName == account["groupName"])) {
AccountModel accountModel = AccountModel(
accountName: account["accountName"],
isChecked: account["isChecked"],
accountId: account["accountId"]);
accounts
.where((element) => element.groupName == account["groupName"])
.first
.accountModels!
.add(accountModel);
} else {
AccountGroupModel accountGroupModel = AccountGroupModel(
groupName: account["groupName"], accountModels: []);
AccountModel accountModel = AccountModel(
accountName: account["accountName"],
isChecked: account["isChecked"],
accountId: account["accountId"]);
accountGroupModel.accountModels!.add(accountModel);
accounts.add(accountGroupModel);
}
}
}
}
}
return accounts;
}