feat(api_service): Update try-catch funtion and handle exception
update(loading_animation): Update loading animation using Lottie
This commit is contained in:
anhtunz
2025-06-09 14:29:43 +07:00
parent 477646ab9d
commit 3a8fa3633c
44 changed files with 1659 additions and 1065 deletions

View File

@@ -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();

View File

@@ -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,
),
],
),
],
),
],
),
),
),
);

View File

@@ -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();
},