Fix(bugs):
Can't logout ui display when user doesn't has device
This commit is contained in:
@@ -22,6 +22,10 @@ class HomeBloc extends BlocBase {
|
||||
StreamSink<int> get sinkCountNotification => countNotification.sink;
|
||||
Stream<int> get streamCountNotification => countNotification.stream;
|
||||
|
||||
final hasJoinedDevice = StreamController<bool?>.broadcast();
|
||||
StreamSink<bool?> get sinkHasJoinedDevice => hasJoinedDevice.sink;
|
||||
Stream<bool?> get streamHasJoinedDevice => hasJoinedDevice.stream;
|
||||
|
||||
final ownerDevicesStatus =
|
||||
StreamController<Map<String, List<DeviceWithAlias>>>.broadcast();
|
||||
StreamSink<Map<String, List<DeviceWithAlias>>>
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user