update
feat(api_service): Update try-catch funtion and handle exception update(loading_animation): Update loading animation using Lottie
This commit is contained in:
@@ -3,6 +3,9 @@ import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../product/shared/shared_component_loading_animation.dart';
|
||||
import '../../product/shared/shared_loading_animation.dart';
|
||||
import '../../product/shared/shared_snack_bar.dart';
|
||||
import 'shared/alert_card.dart';
|
||||
import 'shared/warning_card.dart';
|
||||
import '../../product/utils/device_utils.dart';
|
||||
@@ -206,7 +209,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
stream: homeBloc.streamAllDevicesAliasJoinedMap,
|
||||
builder: (context, allDevicesAliasJoinedMapSnapshot) {
|
||||
if (hasJoinedDeviceSnapshot.data == null) {
|
||||
return const CircularProgressIndicator();
|
||||
return const SharedComponentLoadingAnimation();
|
||||
} else {
|
||||
final data = allDevicesAliasMapSnapshot.data!;
|
||||
final dataJoined =
|
||||
@@ -219,54 +222,71 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
}
|
||||
|
||||
return OverviewCard(
|
||||
isOwner: true,
|
||||
total: data['all']?.length ?? 0,
|
||||
active: data['online']?.length ?? 0,
|
||||
inactive: data['offline']?.length ?? 0,
|
||||
warning: data['warn']?.length ?? 0,
|
||||
unused: data['not-use']?.length ?? 0);
|
||||
isOwner: true,
|
||||
total: data['all']?.length ?? 0,
|
||||
active: data['online']?.length ?? 0,
|
||||
inactive: data['offline']?.length ?? 0,
|
||||
warning: data['warn']?.length ?? 0,
|
||||
unused: data['not-use']?.length ?? 0,
|
||||
showUnused: false,
|
||||
);
|
||||
} else {
|
||||
return DefaultTabController(
|
||||
length: 2,
|
||||
child: Column(
|
||||
// mainAxisSize: MainAxisSize.min,
|
||||
// crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
TabBar(
|
||||
tabs: [
|
||||
Tab(text: appLocalization(context).over_view_owner_devices),
|
||||
Tab(text: appLocalization(context).over_view_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,
|
||||
),
|
||||
SizedBox(
|
||||
height: context.dynamicHeight(0.6),
|
||||
ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxHeight: context.dynamicHeight(0.5),
|
||||
minHeight: context.dynamicHeight(0.3),
|
||||
),
|
||||
child: TabBarView(
|
||||
children: [
|
||||
OverviewCard(
|
||||
isOwner: true,
|
||||
total: data['all']?.length ?? 0,
|
||||
active: data['online']?.length ?? 0,
|
||||
inactive:
|
||||
data['offline']?.length ?? 0,
|
||||
warning: data['warn']?.length ?? 0,
|
||||
unused:
|
||||
data['not-use']?.length ?? 0),
|
||||
isOwner: true,
|
||||
total: data['all']?.length ?? 0,
|
||||
active: data['online']?.length ?? 0,
|
||||
inactive:
|
||||
data['offline']?.length ?? 0,
|
||||
warning: data['warn']?.length ?? 0,
|
||||
unused:
|
||||
data['not-use']?.length ?? 0,
|
||||
showUnused: false,
|
||||
),
|
||||
OverviewCard(
|
||||
isOwner: false,
|
||||
total:
|
||||
dataJoined['all']?.length ?? 0,
|
||||
active:
|
||||
dataJoined['online']?.length ??
|
||||
0,
|
||||
inactive:
|
||||
dataJoined['offline']?.length ??
|
||||
0,
|
||||
warning:
|
||||
dataJoined['warn']?.length ?? 0,
|
||||
unused:
|
||||
dataJoined['not-use']?.length ??
|
||||
0,),
|
||||
isOwner: false,
|
||||
total:
|
||||
dataJoined['all']?.length ?? 0,
|
||||
active:
|
||||
dataJoined['online']?.length ??
|
||||
0,
|
||||
inactive:
|
||||
dataJoined['offline']?.length ??
|
||||
0,
|
||||
warning:
|
||||
dataJoined['warn']?.length ?? 0,
|
||||
unused:
|
||||
dataJoined['not-use']?.length ??
|
||||
0,
|
||||
showUnused: false,
|
||||
showActive: false,
|
||||
showInactive: false,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -289,19 +309,21 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
}
|
||||
|
||||
void getOwnerAndJoinedDevices() async {
|
||||
String response = await apiServices.getDashBoardDevices();
|
||||
final data = jsonDecode(response);
|
||||
List<dynamic> result = data["items"];
|
||||
devices = DeviceWithAlias.fromJsonDynamicList(result);
|
||||
List<DeviceWithAlias> publicDevices = [];
|
||||
for (var device in devices) {
|
||||
if (device.visibility == "PUBLIC") {
|
||||
publicDevices.add(device);
|
||||
try {
|
||||
devices = await apiServices.getDashBoardDevices();
|
||||
List<DeviceWithAlias> publicDevices = [];
|
||||
for (var device in devices) {
|
||||
if (device.visibility == "PUBLIC") {
|
||||
publicDevices.add(device);
|
||||
}
|
||||
}
|
||||
getOwnerDeviceState(publicDevices);
|
||||
checkSettingDevice(publicDevices);
|
||||
getDeviceStatusAliasMap(publicDevices);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
showErrorTopSnackBarCustom(context, e.toString());
|
||||
}
|
||||
getOwnerDeviceState(publicDevices);
|
||||
checkSettingDevice(publicDevices);
|
||||
getDeviceStatusAliasMap(publicDevices);
|
||||
}
|
||||
|
||||
void getOwnerDeviceState(List<DeviceWithAlias> allDevices) async {
|
||||
@@ -391,33 +413,36 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
}
|
||||
|
||||
void checkSettingDevice(List<DeviceWithAlias> devices) async {
|
||||
if (isFunctionCall) {
|
||||
log("Ham check setting da duoc goi");
|
||||
} else {
|
||||
String? response =
|
||||
await apiServices.getAllSettingsNotificationOfDevices();
|
||||
if (response != "") {
|
||||
final data = jsonDecode(response);
|
||||
final result = data['data'];
|
||||
// log("Data ${DeviceNotificationSettings.mapFromJson(jsonDecode(data)).values.toList()}");
|
||||
try {
|
||||
if (isFunctionCall) {
|
||||
log("Ham check setting da duoc goi");
|
||||
} else {
|
||||
List<DeviceNotificationSettings> list =
|
||||
DeviceNotificationSettings.mapFromJson(result).values.toList();
|
||||
await apiServices.getAllSettingsNotificationOfDevices();
|
||||
// log("List: $list");
|
||||
Set<String> thingIdsInList =
|
||||
list.map((device) => device.thingId!).toSet();
|
||||
for (var device in devices) {
|
||||
if (!thingIdsInList.contains(device.thingId)) {
|
||||
log("Device with Thing ID ${device.thingId} is not in the notification settings list.");
|
||||
await apiServices.setupDeviceNotification(
|
||||
device.thingId!, device.name!);
|
||||
try {
|
||||
await apiServices.setupDeviceNotification(
|
||||
device.thingId!, device.name!);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
showErrorTopSnackBarCustom(
|
||||
context, e.toString());
|
||||
}
|
||||
|
||||
} else {
|
||||
log("All devices are in the notification settings list.");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log("apiServices: getAllSettingsNotificationofDevices error!");
|
||||
}
|
||||
isFunctionCall = true;
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
showErrorTopSnackBarCustom(context, e.toString());
|
||||
}
|
||||
isFunctionCall = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ Future<Widget> notificationCard(BuildContext context, String notiticationType,
|
||||
String location = "";
|
||||
if (device.areaPath != "") {
|
||||
location = await DeviceUtils.instance
|
||||
.getFullDeviceLocation(context, device.areaPath!);
|
||||
.getFullDeviceLocation(context, device.areaPath!,"");
|
||||
}
|
||||
String path = "";
|
||||
// DateTime time = DateTime.now();
|
||||
|
||||
@@ -3,69 +3,97 @@ import 'status_card.dart';
|
||||
import '../../../product/extension/context_extension.dart';
|
||||
import '../../../product/services/language_services.dart';
|
||||
|
||||
class OverviewCard extends StatelessWidget {
|
||||
class OverviewCard extends StatefulWidget {
|
||||
final bool isOwner;
|
||||
final int total;
|
||||
final int active;
|
||||
final int inactive;
|
||||
final int warning;
|
||||
final int unused;
|
||||
final bool showTotal;
|
||||
final bool showActive;
|
||||
final bool showInactive;
|
||||
final bool showWarning;
|
||||
final bool showUnused;
|
||||
|
||||
const OverviewCard(
|
||||
{super.key,
|
||||
required this.isOwner,
|
||||
required this.total,
|
||||
required this.active,
|
||||
required this.inactive,
|
||||
required this.warning,
|
||||
required this.unused});
|
||||
const OverviewCard({
|
||||
super.key,
|
||||
required this.isOwner,
|
||||
required this.total,
|
||||
required this.active,
|
||||
required this.inactive,
|
||||
required this.warning,
|
||||
required this.unused,
|
||||
this.showTotal = true,
|
||||
this.showActive = true,
|
||||
this.showInactive = true,
|
||||
this.showWarning = true,
|
||||
this.showUnused = true,
|
||||
});
|
||||
|
||||
@override
|
||||
State<OverviewCard> createState() => _OverviewCardState();
|
||||
}
|
||||
|
||||
class _OverviewCardState extends State<OverviewCard> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Card(
|
||||
elevation: 8,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
|
||||
child: Padding(
|
||||
padding: context.paddingNormal,
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
isOwner
|
||||
? appLocalization(context).overview_message
|
||||
: appLocalization(context).interfamily_page_name,
|
||||
style: context.h2,
|
||||
),
|
||||
SizedBox(height: context.normalValue),
|
||||
Column(
|
||||
return FittedBox(
|
||||
alignment: Alignment.topCenter,
|
||||
child: SizedBox(
|
||||
width: context.width,
|
||||
child: Card(
|
||||
// elevation: 8,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
|
||||
child: Padding(
|
||||
padding: context.paddingNormal,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
StatusCard(
|
||||
label: appLocalization(context).total_nof_devices_message,
|
||||
count: total,
|
||||
color: Colors.blue,
|
||||
Text(
|
||||
widget.isOwner
|
||||
? appLocalization(context).overview_message
|
||||
: appLocalization(context).interfamily_page_name,
|
||||
style: context.h2,
|
||||
),
|
||||
StatusCard(
|
||||
label: appLocalization(context).active_devices_message,
|
||||
count: active,
|
||||
color: Colors.green,
|
||||
),
|
||||
StatusCard(
|
||||
label: appLocalization(context).inactive_devices_message,
|
||||
count: inactive,
|
||||
color: Colors.grey,
|
||||
),
|
||||
StatusCard(
|
||||
label: appLocalization(context).warning_devices_message,
|
||||
count: warning,
|
||||
color: Colors.orange,
|
||||
),
|
||||
StatusCard(
|
||||
label: appLocalization(context).unused_devices_message,
|
||||
count: unused,
|
||||
color: Colors.yellow,
|
||||
SizedBox(height: context.normalValue),
|
||||
Column(
|
||||
children: [
|
||||
if (widget.showTotal)
|
||||
StatusCard(
|
||||
label: appLocalization(context).total_nof_devices_message,
|
||||
count: widget.total,
|
||||
color: Colors.blue,
|
||||
),
|
||||
if (widget.showActive)
|
||||
StatusCard(
|
||||
label: appLocalization(context).active_devices_message,
|
||||
count: widget.active,
|
||||
color: Colors.green,
|
||||
),
|
||||
if (widget.showInactive)
|
||||
StatusCard(
|
||||
label: appLocalization(context).inactive_devices_message,
|
||||
count: widget.inactive,
|
||||
color: Colors.grey,
|
||||
),
|
||||
if (widget.showWarning)
|
||||
StatusCard(
|
||||
label: appLocalization(context).warning_devices_message,
|
||||
count: widget.warning,
|
||||
color: Colors.orange,
|
||||
),
|
||||
if (widget.showUnused)
|
||||
StatusCard(
|
||||
label: appLocalization(context).unused_devices_message,
|
||||
count: widget.unused,
|
||||
color: Colors.yellow,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -21,7 +21,7 @@ Future<Widget> warningCard(BuildContext context, APIServices apiServices,
|
||||
String fullLocation = "";
|
||||
if (device.areaPath != "") {
|
||||
fullLocation = await DeviceUtils.instance
|
||||
.getFullDeviceLocation(context, device.areaPath!);
|
||||
.getFullDeviceLocation(context, device.areaPath!,"");
|
||||
}
|
||||
String time = "";
|
||||
for (var sensor in device.status!.sensors!) {
|
||||
@@ -209,22 +209,28 @@ Future<Widget> warningCard(BuildContext context, APIServices apiServices,
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
int statusCode = await apiServices
|
||||
.confirmFakeFireByUser(device.thingId!);
|
||||
if (statusCode == 200) {
|
||||
showNoIconTopSnackBar(
|
||||
context,
|
||||
appLocalization(context)
|
||||
.notification_confirm_fake_fire_success,
|
||||
Colors.green,
|
||||
Colors.white);
|
||||
} else {
|
||||
showNoIconTopSnackBar(
|
||||
context,
|
||||
appLocalization(context)
|
||||
.notification_confirm_fake_fire_failed,
|
||||
Colors.red,
|
||||
Colors.red);
|
||||
try {
|
||||
int statusCode = await apiServices
|
||||
.confirmFakeFireByUser(device.thingId!);
|
||||
if (statusCode == 200) {
|
||||
showNoIconTopSnackBar(
|
||||
context,
|
||||
appLocalization(context)
|
||||
.notification_confirm_fake_fire_success,
|
||||
Colors.green,
|
||||
Colors.white);
|
||||
} else {
|
||||
showNoIconTopSnackBar(
|
||||
context,
|
||||
appLocalization(context)
|
||||
.notification_confirm_fake_fire_failed,
|
||||
Colors.red,
|
||||
Colors.red);
|
||||
}
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
showErrorTopSnackBarCustom(
|
||||
context, e.toString());
|
||||
}
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user