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

@@ -22,6 +22,10 @@ class HomeBloc extends BlocBase {
StreamSink<int> get sinkCountNotification => countNotification.sink; StreamSink<int> get sinkCountNotification => countNotification.sink;
Stream<int> get streamCountNotification => countNotification.stream; 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 = final ownerDevicesStatus =
StreamController<Map<String, List<DeviceWithAlias>>>.broadcast(); StreamController<Map<String, List<DeviceWithAlias>>>.broadcast();
StreamSink<Map<String, List<DeviceWithAlias>>> StreamSink<Map<String, List<DeviceWithAlias>>>

View File

@@ -38,10 +38,15 @@ class InterFamilyBloc extends BlocBase {
void getAllGroup(String role) async { void getAllGroup(String role) async {
List<Group> groups = []; List<Group> groups = [];
sinkCurrentGroups.add(groups); sinkCurrentGroups.add(groups);
final body = await apiServices.getAllGroups(); final body = await apiServices.getAllGroups();
if (body.isNotEmpty) { if (body.isNotEmpty) {
try {
final data = jsonDecode(body); 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"]; List<dynamic> items = data["items"];
groups = Group.fromJsonDynamicList(items); groups = Group.fromJsonDynamicList(items);
groups = sortGroupByName(groups); groups = sortGroupByName(groups);
@@ -64,7 +69,17 @@ class InterFamilyBloc extends BlocBase {
sinkCurrentGroups.add(currentGroups); sinkCurrentGroups.add(currentGroups);
} else { } else {
log("Get groups from API failed"); 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: Empty response");
sinkCurrentGroups.add([]);
} }
log("Inter Family Role: $role"); log("Inter Family Role: $role");
} }

View File

@@ -63,7 +63,7 @@ class _DeviceLogsScreenState extends State<DeviceLogsScreen> {
body: StreamBuilder<List<Device>>( body: StreamBuilder<List<Device>>(
stream: deviceLogsBloc.streamAllDevices, stream: deviceLogsBloc.streamAllDevices,
builder: (context, allDevicesSnapshot) { builder: (context, allDevicesSnapshot) {
if (allDevicesSnapshot.data?[0].thingId == null) { if (allDevicesSnapshot.data == null) {
deviceLogsBloc.getAllDevices(); deviceLogsBloc.getAllDevices();
return const Center( return const Center(
child: CircularProgressIndicator(), child: CircularProgressIndicator(),

View File

@@ -1,6 +1,7 @@
// ignore_for_file: use_build_context_synchronously // ignore_for_file: use_build_context_synchronously
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:sfm_app/bloc/devices_manager_bloc.dart';
import 'package:sfm_app/product/shared/shared_snack_bar.dart'; import 'package:sfm_app/product/shared/shared_snack_bar.dart';
import '../../product/utils/response_status_utils.dart'; import '../../product/utils/response_status_utils.dart';
import '../../product/constant/enums/role_enums.dart'; import '../../product/constant/enums/role_enums.dart';
@@ -10,7 +11,7 @@ import '../../product/constant/icon/icon_constants.dart';
import '../../product/extension/context_extension.dart'; import '../../product/extension/context_extension.dart';
import '../../product/services/language_services.dart'; import '../../product/services/language_services.dart';
addNewDevice(BuildContext context, String role) async { addNewDevice(BuildContext context, String role, DevicesManagerBloc deviceManagerBloc) async {
TextEditingController extIDController = TextEditingController(text: ""); TextEditingController extIDController = TextEditingController(text: "");
TextEditingController deviceNameController = TextEditingController(text: ""); TextEditingController deviceNameController = TextEditingController(text: "");
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
@@ -76,7 +77,7 @@ addNewDevice(BuildContext context, String role) async {
Colors.white); Colors.white);
ScaffoldMessenger.of(context).hideCurrentSnackBar(); ScaffoldMessenger.of(context).hideCurrentSnackBar();
} else { } else {
addDevices(context, role, extID, deviceName); addDevices(context, role, extID, deviceName, deviceManagerBloc);
ScaffoldMessenger.of(context).hideCurrentSnackBar(); ScaffoldMessenger.of(context).hideCurrentSnackBar();
} }
}, },
@@ -90,7 +91,7 @@ addNewDevice(BuildContext context, String role) async {
} }
void addDevices( void addDevices(
BuildContext context, String role, String extID, String deviceName) async { BuildContext context, String role, String extID, String deviceName, DevicesManagerBloc deviceManagerBloc) async {
APIServices apiServices = APIServices(); APIServices apiServices = APIServices();
Map<String, dynamic> body = {}; Map<String, dynamic> body = {};
if (role == RoleEnums.ADMIN.name) { if (role == RoleEnums.ADMIN.name) {
@@ -101,6 +102,7 @@ void addDevices(
statusCode, statusCode,
appLocalization(context).notification_create_device_success, appLocalization(context).notification_create_device_success,
appLocalization(context).notification_create_device_failed); appLocalization(context).notification_create_device_failed);
deviceManagerBloc.getDeviceByState(-2);
} else { } else {
body = {"ext_id": extID}; body = {"ext_id": extID};
int statusCode = await apiServices.registerDevice(body); int statusCode = await apiServices.registerDevice(body);
@@ -109,5 +111,7 @@ void addDevices(
statusCode, statusCode,
appLocalization(context).notification_add_device_success, appLocalization(context).notification_add_device_success,
appLocalization(context).notification_device_not_exist); appLocalization(context).notification_device_not_exist);
deviceManagerBloc.getDeviceByState(-2);
} }
} }

View File

@@ -29,7 +29,7 @@ class _DevicesManagerScreenState extends State<DevicesManagerScreen> {
late DevicesManagerBloc devicesManagerBloc; late DevicesManagerBloc devicesManagerBloc;
String role = "Undefine"; String role = "Undefine";
APIServices apiServices = APIServices(); APIServices apiServices = APIServices();
List<Device> devices = []; // List<Device> devices = [];
Timer? getAllDevicesTimer; Timer? getAllDevicesTimer;
List<Widget> tags = []; List<Widget> tags = [];
int tagIndex = -2; int tagIndex = -2;
@@ -58,15 +58,43 @@ class _DevicesManagerScreenState extends State<DevicesManagerScreen> {
body: StreamBuilder<List<int>>( body: StreamBuilder<List<int>>(
stream: devicesManagerBloc.streamTagStates, stream: devicesManagerBloc.streamTagStates,
builder: (context, tagSnapshot) { builder: (context, tagSnapshot) {
return StreamBuilder<String>(
stream: devicesManagerBloc.streamUserRole,
initialData: role,
builder: (context, roleSnapshot) {
return SafeArea( return SafeArea(
child: StreamBuilder<List<Device>>( child: StreamBuilder<List<Device>>(
stream: devicesManagerBloc.streamAllDevices, stream: devicesManagerBloc.streamAllDevices,
initialData: devices,
builder: (context, allDeviceSnapshot) { builder: (context, allDeviceSnapshot) {
if (allDeviceSnapshot.data?.isEmpty ?? devices.isEmpty) { if(allDeviceSnapshot.data == null){
devicesManagerBloc devicesManagerBloc
.getDeviceByState(tagSnapshot.data?[0] ?? -2); .getDeviceByState(tagSnapshot.data?[0] ?? -2);
return const Center(child: CircularProgressIndicator()); return const Center(child: CircularProgressIndicator());
}
if (allDeviceSnapshot.data!.isEmpty) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
width: 100,
height: 100,
decoration: BoxDecoration(
border: Border.all(color: Theme.of(context).colorScheme.primary),
borderRadius: BorderRadius.circular(50)
),
child: IconButton(onPressed: (){
ScaffoldMessenger.of(context)
.clearSnackBars();
addNewDevice(context,
roleSnapshot.data ?? role, devicesManagerBloc);
}, iconSize: 50, icon: const Icon(Icons.add),),),
SizedBox(height: context.mediumValue,),
Text(appLocalization(context).dont_have_device, style: context.responsiveBodyMediumWithBold,)
],
),
);
} else { } else {
if (tagSnapshot.data!.isNotEmpty) { if (tagSnapshot.data!.isNotEmpty) {
tagIndex = tagSnapshot.data![0]; tagIndex = tagSnapshot.data![0];
@@ -83,11 +111,7 @@ class _DevicesManagerScreenState extends State<DevicesManagerScreen> {
devicesManagerBloc: devicesManagerBloc, devicesManagerBloc: devicesManagerBloc,
), ),
SizedBox(height: context.lowValue), SizedBox(height: context.lowValue),
StreamBuilder<String>( SizedBox(
stream: devicesManagerBloc.streamUserRole,
initialData: role,
builder: (context, roleSnapshot) {
return SizedBox(
height: getTableHeight(allDeviceSnapshot.data?.length ?? 1), height: getTableHeight(allDeviceSnapshot.data?.length ?? 1),
child: PaginatedDataTable2( child: PaginatedDataTable2(
wrapInCard: false, wrapInCard: false,
@@ -173,20 +197,18 @@ class _DevicesManagerScreenState extends State<DevicesManagerScreen> {
ScaffoldMessenger.of(context) ScaffoldMessenger.of(context)
.clearSnackBars(); .clearSnackBars();
addNewDevice(context, addNewDevice(context,
roleSnapshot.data ?? role); roleSnapshot.data ?? role, devicesManagerBloc);
}, },
icon: IconConstants.instance icon: IconConstants.instance
.getMaterialIcon(Icons.add)) .getMaterialIcon(Icons.add))
], ],
source: DeviceSource( source: DeviceSource(
devices: allDeviceSnapshot.data ?? devices, devices: allDeviceSnapshot.data ?? [],
context: context, context: context,
devicesBloc: devicesManagerBloc, devicesBloc: devicesManagerBloc,
role: role, role: role,
), ),
), ),
);
},
), ),
SizedBox(height: context.lowValue), SizedBox(height: context.lowValue),
Text( Text(
@@ -217,6 +239,8 @@ class _DevicesManagerScreenState extends State<DevicesManagerScreen> {
}, },
), ),
); );
}
);
}), }),
); );
} }

View File

@@ -40,7 +40,8 @@ class _HomeScreenState extends State<HomeScreen> {
homeBloc = BlocProvider.of(context); homeBloc = BlocProvider.of(context);
getOwnerAndJoinedDevices(); getOwnerAndJoinedDevices();
const duration = Duration(seconds: 10); const duration = Duration(seconds: 10);
getAllDevicesTimer = Timer.periodic(duration, (Timer t) => getOwnerAndJoinedDevices()); getAllDevicesTimer =
Timer.periodic(duration, (Timer t) => getOwnerAndJoinedDevices());
} }
@override @override
@@ -81,9 +82,32 @@ class _HomeScreenState extends State<HomeScreen> {
child: StreamBuilder<Map<String, List<DeviceWithAlias>>>( child: StreamBuilder<Map<String, List<DeviceWithAlias>>>(
stream: homeBloc.streamOwnerDevicesStatus, stream: homeBloc.streamOwnerDevicesStatus,
builder: (context, snapshot) { builder: (context, snapshot) {
if (snapshot.data?['state'] != null || snapshot.data?['battery'] != null) { return AnimatedSwitcher(
return ConstrainedBox( duration: context.lowDuration,
constraints: BoxConstraints(minWidth: MediaQuery.of(context).size.width), transitionBuilder:
(Widget child, Animation<double> animation) {
final offsetAnimation = Tween<Offset>(
begin: const Offset(0.0, 0.2),
end: Offset.zero,
).animate(CurvedAnimation(
parent: animation,
curve: Curves.easeInOut,
));
return FadeTransition(
opacity: animation,
child: SlideTransition(
position: offsetAnimation,
child: child,
),
);
},
child: snapshot.data?['state'] != null ||
snapshot.data?['battery'] != null
? ConstrainedBox(
key: const ValueKey('data'),
constraints: BoxConstraints(
minWidth:
MediaQuery.of(context).size.width),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
children: [ children: [
@@ -93,12 +117,17 @@ class _HomeScreenState extends State<HomeScreen> {
(item) => SizedBox( (item) => SizedBox(
width: context.dynamicWidth(0.95), width: context.dynamicWidth(0.95),
child: FutureBuilder<Widget>( child: FutureBuilder<Widget>(
future: warningCard(context, apiServices, item), future: warningCard(
builder: (context, warningCardSnapshot) { context, apiServices, item),
if (warningCardSnapshot.hasData) { builder: (context,
return warningCardSnapshot.data!; warningCardSnapshot) {
if (warningCardSnapshot
.hasData) {
return warningCardSnapshot
.data!;
} else { } else {
return const SizedBox.shrink(); return const SizedBox
.shrink();
} }
}, },
), ),
@@ -112,12 +141,21 @@ class _HomeScreenState extends State<HomeScreen> {
width: context.dynamicWidth(0.95), width: context.dynamicWidth(0.95),
child: FutureBuilder<Widget>( child: FutureBuilder<Widget>(
future: notificationCard( future: notificationCard(
context, "lowBattery", appLocalization(context).low_battery_message, batteryItem), context,
builder: (context, warningCardSnapshot) { "lowBattery",
if (warningCardSnapshot.hasData) { appLocalization(context)
return warningCardSnapshot.data!; .low_battery_message,
batteryItem,
),
builder: (context,
warningCardSnapshot) {
if (warningCardSnapshot
.hasData) {
return warningCardSnapshot
.data!;
} else { } else {
return const SizedBox.shrink(); return const SizedBox
.shrink();
} }
}, },
), ),
@@ -126,9 +164,9 @@ class _HomeScreenState extends State<HomeScreen> {
.toList(), .toList(),
], ],
), ),
); )
} else { : Padding(
return Padding( key: const ValueKey('no_data'),
padding: context.paddingMedium, padding: context.paddingMedium,
child: Center( child: Center(
child: Row( child: Row(
@@ -141,7 +179,8 @@ class _HomeScreenState extends State<HomeScreen> {
), ),
SizedBox(width: context.lowValue), SizedBox(width: context.lowValue),
Text( Text(
appLocalization(context).notification_description, appLocalization(context)
.notification_description,
maxLines: 2, maxLines: 2,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
softWrap: true, softWrap: true,
@@ -150,25 +189,35 @@ class _HomeScreenState extends State<HomeScreen> {
], ],
), ),
), ),
),
); );
}
}, },
), ),
), ),
), ),
StreamBuilder<bool?>(
stream: homeBloc.streamHasJoinedDevice,
initialData: null,
builder: (context, hasJoinedDeviceSnapshot) {
return StreamBuilder<Map<String, List<DeviceWithAlias>>>(
StreamBuilder<Map<String, List<DeviceWithAlias>>>(
stream: homeBloc.streamAllDevicesAliasMap, stream: homeBloc.streamAllDevicesAliasMap,
builder: (context, allDevicesAliasMapSnapshot) { builder: (context, allDevicesAliasMapSnapshot) {
return StreamBuilder<Map<String, List<DeviceWithAlias>>>(
stream: homeBloc.streamAllDevicesAliasJoinedMap,
builder: (context, allDevicesAliasJoinedMapSnapshot) {
if (hasJoinedDeviceSnapshot.data == null) {
return const CircularProgressIndicator();
} else {
final data = allDevicesAliasMapSnapshot.data!;
final dataJoined =
allDevicesAliasJoinedMapSnapshot.data!;
if (hasJoinedDeviceSnapshot.data == false) {
if (!allDevicesAliasMapSnapshot.hasData || if (!allDevicesAliasMapSnapshot.hasData ||
allDevicesAliasMapSnapshot.data == null) { allDevicesAliasMapSnapshot.data == null) {
return const Center(child: CircularProgressIndicator()); return const Center(
child: CircularProgressIndicator());
} }
final data = allDevicesAliasMapSnapshot.data!;
return OverviewCard( return OverviewCard(
isOwner: true, isOwner: true,
total: data['all']?.length ?? 0, total: data['all']?.length ?? 0,
@@ -176,32 +225,56 @@ class _HomeScreenState extends State<HomeScreen> {
inactive: data['offline']?.length ?? 0, inactive: data['offline']?.length ?? 0,
warning: data['warn']?.length ?? 0, warning: data['warn']?.length ?? 0,
unused: data['not-use']?.length ?? 0); unused: data['not-use']?.length ?? 0);
}), } else {
SizedBox(height: context.lowValue), return DefaultTabController(
StreamBuilder<Map<String, List<DeviceWithAlias>>>( length: 2,
stream: homeBloc.streamAllDevicesAliasJoinedMap, child: Column(
builder: (context, allDevicesAliasJoinedMapSnapshot) { children: [
if (!allDevicesAliasJoinedMapSnapshot.hasData || const TabBar(
allDevicesAliasJoinedMapSnapshot.data == null) { tabs: [
return const Center(child: CircularProgressIndicator()); Tab(text: 'Owner Devices'),
} Tab(text: 'Joined Devices'),
final data = allDevicesAliasJoinedMapSnapshot.data!; ],
final total = data['all']?.length ?? 0; labelColor: Colors.blue,
final active = data['online']?.length ?? 0; unselectedLabelColor: Colors.grey,
final inactive = data['offline']?.length ?? 0; indicatorColor: Colors.blue,
final warning = data['warn']?.length ?? 0; ),
final unused = data['not-use']?.length ?? 0; TabBarView(
children: [
if (total == 0 && active == 0 && inactive == 0 && warning == 0 && unused == 0) { OverviewCard(
return const SizedBox.shrink(); isOwner: true,
} total: data['all']?.length ?? 0,
return OverviewCard( active: data['online']?.length ?? 0,
inactive:
data['offline']?.length ?? 0,
warning: data['warn']?.length ?? 0,
unused:
data['not-use']?.length ?? 0),
OverviewCard(
isOwner: false, isOwner: false,
total: total, total:
active: active, dataJoined['all']?.length ?? 0,
inactive: inactive, active:
warning: warning, dataJoined['online']?.length ??
unused: unused, 0,
inactive:
dataJoined['offline']?.length ??
0,
warning:
dataJoined['warn']?.length ?? 0,
unused:
dataJoined['not-use']?.length ??
0),
],
),
],
),
);
}
}
},
);
},
); );
}, },
), ),
@@ -217,9 +290,15 @@ class _HomeScreenState extends State<HomeScreen> {
final data = jsonDecode(response); final data = jsonDecode(response);
List<dynamic> result = data["items"]; List<dynamic> result = data["items"];
devices = DeviceWithAlias.fromJsonDynamicList(result); devices = DeviceWithAlias.fromJsonDynamicList(result);
getOwnerDeviceState(devices); List<DeviceWithAlias> publicDevices = [];
checkSettingDevice(devices); for (var device in devices) {
getDeviceStatusAliasMap(devices); if (device.visibility == "PUBLIC") {
publicDevices.add(device);
}
}
getOwnerDeviceState(publicDevices);
checkSettingDevice(publicDevices);
getDeviceStatusAliasMap(publicDevices);
} }
void getOwnerDeviceState(List<DeviceWithAlias> allDevices) async { void getOwnerDeviceState(List<DeviceWithAlias> allDevices) async {
@@ -229,21 +308,23 @@ class _HomeScreenState extends State<HomeScreen> {
ownerDevices.add(device); ownerDevices.add(device);
} }
} }
if (ownerDevicesState.isEmpty || ownerDevicesState.length < devices.length) { if (ownerDevicesState.isEmpty ||
ownerDevicesState.length < devices.length) {
ownerDevicesState.clear(); ownerDevicesState.clear();
ownerDevicesStatus.clear(); ownerDevicesStatus.clear();
homeBloc.sinkOwnerDevicesStatus.add(ownerDevicesStatus); homeBloc.sinkOwnerDevicesStatus.add(ownerDevicesStatus);
int count = 0; int count = 0;
for (var device in ownerDevices) { for (var device in ownerDevices) {
Map<String, dynamic> sensorMap = Map<String, dynamic> sensorMap = DeviceUtils.instance
DeviceUtils.instance.getDeviceSensors(context, device.status?.sensors ?? []); .getDeviceSensors(context, device.status?.sensors ?? []);
if (device.state == 1 || device.state == 3) { if (device.state == 1 || device.state == 3) {
ownerDevicesStatus["state"] ??= []; ownerDevicesStatus["state"] ??= [];
ownerDevicesStatus["state"]!.add(device); ownerDevicesStatus["state"]!.add(device);
homeBloc.sinkOwnerDevicesStatus.add(ownerDevicesStatus); homeBloc.sinkOwnerDevicesStatus.add(ownerDevicesStatus);
count++; count++;
} }
if (sensorMap['sensorBattery'] != appLocalization(context).no_data_message) { if (sensorMap['sensorBattery'] !=
appLocalization(context).no_data_message) {
if (double.parse(sensorMap['sensorBattery']) <= 20) { if (double.parse(sensorMap['sensorBattery']) <= 20) {
ownerDevicesStatus['battery'] ??= []; ownerDevicesStatus['battery'] ??= [];
ownerDevicesStatus['battery']!.add(device); ownerDevicesStatus['battery']!.add(device);
@@ -260,7 +341,7 @@ class _HomeScreenState extends State<HomeScreen> {
void getDeviceStatusAliasMap(List<DeviceWithAlias> devices) { void getDeviceStatusAliasMap(List<DeviceWithAlias> devices) {
allDevicesAliasMap.clear(); allDevicesAliasMap.clear();
allDevicesAliasJoinedMap.clear(); allDevicesAliasJoinedMap.clear();
bool check = false;
for (var key in ['all', 'online', 'offline', 'warning', 'not-use']) { for (var key in ['all', 'online', 'offline', 'warning', 'not-use']) {
allDevicesAliasMap[key] = []; allDevicesAliasMap[key] = [];
allDevicesAliasJoinedMap[key] = []; allDevicesAliasJoinedMap[key] = [];
@@ -282,6 +363,7 @@ class _HomeScreenState extends State<HomeScreen> {
allDevicesAliasMap['not-use']!.add(device); allDevicesAliasMap['not-use']!.add(device);
} }
} else { } else {
check = true;
allDevicesAliasJoinedMap['all']!.add(device); allDevicesAliasJoinedMap['all']!.add(device);
if (device.state == 0 || device.state == 1) { if (device.state == 0 || device.state == 1) {
allDevicesAliasJoinedMap['online']!.add(device); allDevicesAliasJoinedMap['online']!.add(device);
@@ -297,7 +379,7 @@ class _HomeScreenState extends State<HomeScreen> {
} }
} }
} }
homeBloc.sinkHasJoinedDevice.add(check);
homeBloc.sinkAllDevicesAliasMap.add(allDevicesAliasMap); homeBloc.sinkAllDevicesAliasMap.add(allDevicesAliasMap);
homeBloc.sinkAllDevicesAliasJoinedMap.add(allDevicesAliasJoinedMap); homeBloc.sinkAllDevicesAliasJoinedMap.add(allDevicesAliasJoinedMap);
} }
@@ -306,7 +388,8 @@ class _HomeScreenState extends State<HomeScreen> {
if (isFunctionCall) { if (isFunctionCall) {
log("Ham check setting da duoc goi"); log("Ham check setting da duoc goi");
} else { } else {
String? response = await apiServices.getAllSettingsNotificationOfDevices(); String? response =
await apiServices.getAllSettingsNotificationOfDevices();
if (response != "") { if (response != "") {
final data = jsonDecode(response); final data = jsonDecode(response);
final result = data['data']; final result = data['data'];
@@ -314,11 +397,13 @@ class _HomeScreenState extends State<HomeScreen> {
List<DeviceNotificationSettings> list = List<DeviceNotificationSettings> list =
DeviceNotificationSettings.mapFromJson(result).values.toList(); DeviceNotificationSettings.mapFromJson(result).values.toList();
// log("List: $list"); // log("List: $list");
Set<String> thingIdsInList = list.map((device) => device.thingId!).toSet(); Set<String> thingIdsInList =
list.map((device) => device.thingId!).toSet();
for (var device in devices) { for (var device in devices) {
if (!thingIdsInList.contains(device.thingId)) { if (!thingIdsInList.contains(device.thingId)) {
log("Device with Thing ID ${device.thingId} is not in the notification settings list."); log("Device with Thing ID ${device.thingId} is not in the notification settings list.");
await apiServices.setupDeviceNotification(device.thingId!, device.name!); await apiServices.setupDeviceNotification(
device.thingId!, device.name!);
} else { } else {
log("All devices are in the notification settings list."); log("All devices are in the notification settings list.");
} }

View File

@@ -44,16 +44,22 @@ class _GroupsScreenState extends State<GroupsScreen> {
@override @override
void dispose() { void dispose() {
getAllGroupsTimer?.cancel(); getAllGroupsTimer?.cancel();
super.dispose();
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (widget.role == ApplicationConstants.OWNER_GROUP || if (widget.role == ApplicationConstants.OWNER_GROUP ||
widget.role == ApplicationConstants.PARTICIPANT_GROUP) { widget.role == ApplicationConstants.PARTICIPANT_GROUP) {
interFamilyBloc.getAllGroup(widget.role);
return StreamBuilder<List<Group>>( return StreamBuilder<List<Group>>(
stream: interFamilyBloc.streamCurrentGroups, stream: interFamilyBloc.streamCurrentGroups,
builder: (context, groupsSnapshot) { builder: (context, groupsSnapshot) {
if(groupsSnapshot.data == null){
interFamilyBloc.getAllGroup(widget.role);
return const Center(child: CircularProgressIndicator(),);
}else if(groupsSnapshot.data!.isEmpty){
return Center(child: Text(appLocalization(context).dont_have_group),);
}else {
return Scaffold( return Scaffold(
body: groupsSnapshot.data?.isEmpty ?? true body: groupsSnapshot.data?.isEmpty ?? true
? const Center( ? const Center(
@@ -107,6 +113,7 @@ class _GroupsScreenState extends State<GroupsScreen> {
}, },
), ),
); );
}
}, },
); );
} else { } else {

View File

@@ -385,7 +385,7 @@ class _MainScreenState extends State<MainScreen> with WidgetsBindingObserver {
items: _navBarsItems(), items: _navBarsItems(),
handleAndroidBackButtonPress: true, handleAndroidBackButtonPress: true,
resizeToAvoidBottomInset: true, resizeToAvoidBottomInset: true,
stateManagement: true, stateManagement: false,
backgroundColor: backgroundColor:
themeModeSnapshot.data! ? Colors.white : Colors.black, themeModeSnapshot.data! ? Colors.white : Colors.black,
decoration: NavBarDecoration( decoration: NavBarDecoration(

View File

@@ -1,4 +1,4 @@
import 'dart:developer'; import 'dart:developer';
import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:firebase_messaging/firebase_messaging.dart';

View File

@@ -69,7 +69,7 @@ class APIServices {
actions: [ actions: [
TextButton( TextButton(
onPressed: () async { onPressed: () async {
var url = Uri.http(ApplicationConstants.DOMAIN, var url = Uri.https(ApplicationConstants.DOMAIN,
APIPathConstants.LOGOUT_PATH); APIPathConstants.LOGOUT_PATH);
final headers = await NetworkManager.instance!.getHeaders(); final headers = await NetworkManager.instance!.getHeaders();
final response = await http.post(url, headers: headers); final response = await http.post(url, headers: headers);