Fix(bugs):

Can't logout
ui display when user doesn't has device
This commit is contained in:
anhtunz
2025-05-26 11:58:19 +07:00
parent f80e234b1d
commit 01ae020374
10 changed files with 417 additions and 278 deletions

View File

@@ -38,33 +38,48 @@ class InterFamilyBloc extends BlocBase {
void getAllGroup(String role) async {
List<Group> groups = [];
sinkCurrentGroups.add(groups);
final body = await apiServices.getAllGroups();
if (body.isNotEmpty) {
final data = jsonDecode(body);
List<dynamic> items = data["items"];
groups = Group.fromJsonDynamicList(items);
groups = sortGroupByName(groups);
try {
final data = jsonDecode(body);
List<Group> currentGroups = groups.where(
(group) {
bool isPublic = group.visibility == "PUBLIC";
// Kiểm tra nếu data là một Map và có chứa key "items"
if (data is Map && data.containsKey("items") && data["items"] is List) {
List<dynamic> items = data["items"];
groups = Group.fromJsonDynamicList(items);
groups = sortGroupByName(groups);
if (role == ApplicationConstants.OWNER_GROUP) {
return group.isOwner == true && isPublic;
}
List<Group> currentGroups = groups.where(
(group) {
bool isPublic = group.visibility == "PUBLIC";
if (role == ApplicationConstants.PARTICIPANT_GROUP) {
return group.isOwner == null && isPublic;
}
if (role == ApplicationConstants.OWNER_GROUP) {
return group.isOwner == true && isPublic;
}
return false;
},
).toList();
if (role == ApplicationConstants.PARTICIPANT_GROUP) {
return group.isOwner == null && isPublic;
}
sinkCurrentGroups.add(currentGroups);
return false;
},
).toList();
sinkCurrentGroups.add(currentGroups);
} else {
log("No items found in API response or empty JSON object");
sinkCurrentGroups.add([]);
}
} catch (e) {
// Xử lý lỗi khi jsonDecode thất bại
log("Error decoding JSON: $e");
sinkCurrentGroups.add([]);
}
} else {
log("Get groups from API failed");
log("Get groups from API failed: Empty response");
sinkCurrentGroups.add([]);
}
log("Inter Family Role: $role");
}