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

@@ -12,7 +12,7 @@ import 'group_detail_model.dart';
addDeviceDialog(BuildContext context, DetailGroupBloc detailGroupBloc,
String groupID, List<DeviceOfGroup> devices) async {
List<Device> ownerDevices = await detailGroupBloc.getOwnerDevices();
List<Device> ownerDevices = await detailGroupBloc.getOwnerDevices(context);
List<String> selectedItems = [];
List<String> selectedDevices = [];
if (devices.isNotEmpty) {
@@ -131,7 +131,7 @@ addDeviceDialog(BuildContext context, DetailGroupBloc detailGroupBloc,
for (var device in selectedItems) {
await detailGroupBloc.addDeviceToGroup(
context, groupID, device);
await detailGroupBloc.getGroupDetail(groupID);
await detailGroupBloc.getGroupDetail(context,groupID);
}
Navigator.of(dialogContext).pop();

View File

@@ -4,6 +4,8 @@ import 'dart:async';
import 'package:flutter/material.dart';
import '../../../bloc/group_detail_bloc.dart';
import '../../../product/shared/shared_loading_animation.dart';
import '../../../product/shared/shared_snack_bar.dart';
import 'group_detail_model.dart';
import '../../../product/base/bloc/base_bloc.dart';
import '../../../product/constant/app/app_constants.dart';
@@ -35,15 +37,13 @@ class _DetailGroupScreenState extends State<DetailGroupScreen> {
const duration = Duration(seconds: 10);
getGroupDetailTimer = Timer.periodic(
duration,
(Timer t) => detailGroupBloc.getGroupDetail(widget.group),
(Timer t) => detailGroupBloc.getGroupDetail(context, widget.group),
);
}
@override
void dispose() {
getGroupDetailTimer?.cancel();
// Thieeus hamf
super.dispose();
}
@@ -53,10 +53,8 @@ class _DetailGroupScreenState extends State<DetailGroupScreen> {
stream: detailGroupBloc.streamDetailGroup,
builder: (context, detailGroupSnapshot) {
if (detailGroupSnapshot.data?.id == null) {
detailGroupBloc.getGroupDetail(widget.group);
return const Center(
child: CircularProgressIndicator(),
);
detailGroupBloc.getGroupDetail(context, widget.group);
return const SharedLoadingAnimation();
} else {
return Scaffold(
key: scaffoldKey,
@@ -142,8 +140,8 @@ class _DetailGroupScreenState extends State<DetailGroupScreen> {
widget.group,
user.id!,
user.name!);
detailGroupBloc
.getGroupDetail(widget.group);
detailGroupBloc.getGroupDetail(
context, widget.group);
},
icon: const Icon(
Icons.check,
@@ -160,8 +158,8 @@ class _DetailGroupScreenState extends State<DetailGroupScreen> {
widget.group,
user.id!,
user.name!);
await detailGroupBloc
.getGroupDetail(widget.group);
await detailGroupBloc.getGroupDetail(
context, widget.group);
},
icon: const Icon(
Icons.close,
@@ -207,8 +205,8 @@ class _DetailGroupScreenState extends State<DetailGroupScreen> {
widget.group,
user.id!,
user.name!);
await detailGroupBloc
.getGroupDetail(widget.group);
await detailGroupBloc.getGroupDetail(
context, widget.group);
},
value: 2,
child: Text(appLocalization(context)
@@ -241,7 +239,7 @@ class _DetailGroupScreenState extends State<DetailGroupScreen> {
? PopupMenuButton(
icon: IconConstants.instance
.getMaterialIcon(Icons.more_horiz),
itemBuilder: (contex) => [
itemBuilder: (context) => [
PopupMenuItem(
onTap: () {
Navigator.pop(context);
@@ -327,15 +325,21 @@ class _DetailGroupScreenState extends State<DetailGroupScreen> {
Future.delayed(context.lowDuration).then(
(value) => Navigator.pop(context),
);
int statusCode = await apiServices
.deleteGroup(widget.group);
showSnackBarResponseByStatusCode(
context,
statusCode,
appLocalization(context)
.notification_delete_group_success,
appLocalization(context)
.notification_delete_group_failed);
try {
int statusCode = await apiServices
.deleteGroup(widget.group);
showSnackBarResponseByStatusCode(
context,
statusCode,
appLocalization(context)
.notification_delete_group_success,
appLocalization(context)
.notification_delete_group_failed);
} catch (e) {
if (!context.mounted) return;
showErrorTopSnackBarCustom(
context, e.toString());
}
},
child: Text(
appLocalization(context)
@@ -463,7 +467,8 @@ class _DetailGroupScreenState extends State<DetailGroupScreen> {
DeviceUtils.instance.checkStateDevice(
context, devices[index].state!),
style: TextStyle(
color: DeviceUtils.instance.getTableRowColor(context,
color: DeviceUtils.instance.getTableRowColor(
context,
devices[index].state!,
),
),
@@ -525,7 +530,7 @@ class _DetailGroupScreenState extends State<DetailGroupScreen> {
String alias = aliasController.text;
await detailGroupBloc.updateDeviceNameInGroup(
context, device.thingId!, alias);
await detailGroupBloc.getGroupDetail(widget.group);
await detailGroupBloc.getGroupDetail(context, widget.group);
},
child: Text(appLocalization(context).confirm_button_content)),
)