chore(HomeScreen): fix context unmounted
This commit is contained in:
@@ -45,7 +45,6 @@ class InterFamilyBloc extends BlocBase {
|
||||
try {
|
||||
final data = jsonDecode(body);
|
||||
|
||||
// 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);
|
||||
|
||||
@@ -69,6 +69,7 @@ class _DetailDeviceScreenState extends State<DetailDeviceScreen> {
|
||||
@override
|
||||
void dispose() {
|
||||
getDeviceDetailTimer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
BoxDecoration boxDecoration = BoxDecoration(
|
||||
|
||||
@@ -230,16 +230,18 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
length: 2,
|
||||
child: Column(
|
||||
children: [
|
||||
const TabBar(
|
||||
TabBar(
|
||||
tabs: [
|
||||
Tab(text: 'Owner Devices'),
|
||||
Tab(text: 'Joined Devices'),
|
||||
Tab(text: appLocalization(context).over_view_owner_devices),
|
||||
Tab(text: appLocalization(context).over_view_joined_devices),
|
||||
],
|
||||
labelColor: Colors.blue,
|
||||
unselectedLabelColor: Colors.grey,
|
||||
indicatorColor: Colors.blue,
|
||||
),
|
||||
TabBarView(
|
||||
SizedBox(
|
||||
height: context.dynamicHeight(0.6),
|
||||
child: TabBarView(
|
||||
children: [
|
||||
OverviewCard(
|
||||
isOwner: true,
|
||||
@@ -264,9 +266,10 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
dataJoined['warn']?.length ?? 0,
|
||||
unused:
|
||||
dataJoined['not-use']?.length ??
|
||||
0),
|
||||
0,),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -302,41 +305,44 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
}
|
||||
|
||||
void getOwnerDeviceState(List<DeviceWithAlias> allDevices) async {
|
||||
List<DeviceWithAlias> ownerDevices = [];
|
||||
for (var device in allDevices) {
|
||||
if (device.isOwner!) {
|
||||
ownerDevices.add(device);
|
||||
}
|
||||
}
|
||||
if (ownerDevicesState.isEmpty ||
|
||||
ownerDevicesState.length < devices.length) {
|
||||
ownerDevicesState.clear();
|
||||
ownerDevicesStatus.clear();
|
||||
|
||||
if (!mounted) return;
|
||||
homeBloc.sinkOwnerDevicesStatus.add(ownerDevicesStatus);
|
||||
|
||||
int count = 0;
|
||||
for (var device in ownerDevices) {
|
||||
for (var device in allDevices) {
|
||||
if (device.isOwner != true) continue;
|
||||
|
||||
if (!mounted) return;
|
||||
Map<String, dynamic> sensorMap = DeviceUtils.instance
|
||||
.getDeviceSensors(context, device.status?.sensors ?? []);
|
||||
|
||||
if (device.state == 1 || device.state == 3) {
|
||||
ownerDevicesStatus["state"] ??= [];
|
||||
ownerDevicesStatus["state"]!.add(device);
|
||||
if (!mounted) return;
|
||||
homeBloc.sinkOwnerDevicesStatus.add(ownerDevicesStatus);
|
||||
count++;
|
||||
}
|
||||
if (sensorMap['sensorBattery'] !=
|
||||
appLocalization(context).no_data_message) {
|
||||
|
||||
final noDataMessage = appLocalization(context).no_data_message;
|
||||
if (sensorMap['sensorBattery'] != noDataMessage) {
|
||||
if (double.parse(sensorMap['sensorBattery']) <= 20) {
|
||||
ownerDevicesStatus['battery'] ??= [];
|
||||
ownerDevicesStatus['battery']!.add(device);
|
||||
if (!mounted) return;
|
||||
homeBloc.sinkOwnerDevicesStatus.add(ownerDevicesStatus);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
notificationCount = count;
|
||||
if (!mounted) return;
|
||||
homeBloc.sinkCountNotification.add(notificationCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void getDeviceStatusAliasMap(List<DeviceWithAlias> devices) {
|
||||
allDevicesAliasMap.clear();
|
||||
|
||||
@@ -34,7 +34,7 @@ class _GroupsScreenState extends State<GroupsScreen> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
interFamilyBloc = BlocProvider.of(context);
|
||||
const duration = Duration(seconds: 10);
|
||||
const duration = Duration(seconds: 5);
|
||||
getAllGroupsTimer = Timer.periodic(
|
||||
duration,
|
||||
(Timer t) => interFamilyBloc.getAllGroup(widget.role),
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
"let_PCCC_handle_message": "Let the Fire Prevention and Fighting Team handle it!",
|
||||
"overview_message": "Overview",
|
||||
"total_nof_devices_message": "Total number of devices",
|
||||
"over_view_owner_devices":"Owner Devices",
|
||||
"over_view_joined_devices":"Joined Devices",
|
||||
"active_devices_message": "Active",
|
||||
"inactive_devices_message": "Inactive",
|
||||
"warning_devices_message": "Warning",
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
"confirm_fake_fire_sure_message": "Tôi chắc chắn",
|
||||
"let_PCCC_handle_message": "Hãy để Đội PCCC xử lý!",
|
||||
"overview_message": "Tổng quan",
|
||||
"over_view_owner_devices":"Thiết bị sở hữu",
|
||||
"over_view_joined_devices":"Thiết bị tham gia",
|
||||
"total_nof_devices_message": "Tổng số",
|
||||
"active_devices_message": "Bình thường",
|
||||
"inactive_devices_message": "Đang tắt",
|
||||
|
||||
Reference in New Issue
Block a user