fix(ui): fix error text in warning card and update information for device's inter-family owner
This commit is contained in:
@@ -13,10 +13,10 @@ class HomeBloc extends BlocBase {
|
|||||||
APIServices apiServices = APIServices();
|
APIServices apiServices = APIServices();
|
||||||
|
|
||||||
final allDevicesAliasMap =
|
final allDevicesAliasMap =
|
||||||
StreamController<Map<String, List<DeviceWithAlias>>>.broadcast();
|
StreamController<Map<String, List<DeviceWithAlias>>?>.broadcast();
|
||||||
StreamSink<Map<String, List<DeviceWithAlias>>> get sinkAllDevicesAliasMap =>
|
StreamSink<Map<String, List<DeviceWithAlias>>?> get sinkAllDevicesAliasMap =>
|
||||||
allDevicesAliasMap.sink;
|
allDevicesAliasMap.sink;
|
||||||
Stream<Map<String, List<DeviceWithAlias>>> get streamAllDevicesAliasMap =>
|
Stream<Map<String, List<DeviceWithAlias>>?> get streamAllDevicesAliasMap =>
|
||||||
allDevicesAliasMap.stream;
|
allDevicesAliasMap.stream;
|
||||||
|
|
||||||
// final allDevicesAliasJoinedMap =
|
// final allDevicesAliasJoinedMap =
|
||||||
@@ -47,7 +47,6 @@ class HomeBloc extends BlocBase {
|
|||||||
Stream<List<DeviceWithAlias>?> get streamAliasDevices => aliasDevices.stream;
|
Stream<List<DeviceWithAlias>?> get streamAliasDevices => aliasDevices.stream;
|
||||||
|
|
||||||
void getOwnerAndJoinedDevices(BuildContext context) async {
|
void getOwnerAndJoinedDevices(BuildContext context) async {
|
||||||
|
|
||||||
await apiServices.execute(context, () async {
|
await apiServices.execute(context, () async {
|
||||||
List<DeviceWithAlias> devices = await apiServices.getDashBoardDevices().handleApiError();
|
List<DeviceWithAlias> devices = await apiServices.getDashBoardDevices().handleApiError();
|
||||||
List<DeviceWithAlias> publicDevices = [];
|
List<DeviceWithAlias> publicDevices = [];
|
||||||
@@ -56,6 +55,8 @@ class HomeBloc extends BlocBase {
|
|||||||
publicDevices.add(device);
|
publicDevices.add(device);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// getDeviceStatusAliasMap(publicDevices);
|
||||||
|
sinkAllDevicesAliasMap.add(null);
|
||||||
sinkAliasDevices.add(publicDevices);
|
sinkAliasDevices.add(publicDevices);
|
||||||
if (!context.mounted) return;
|
if (!context.mounted) return;
|
||||||
getOwnerDeviceState(context, publicDevices);
|
getOwnerDeviceState(context, publicDevices);
|
||||||
|
|||||||
@@ -33,10 +33,17 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
super.initState();
|
super.initState();
|
||||||
homeBloc = BlocProvider.of(context);
|
homeBloc = BlocProvider.of(context);
|
||||||
const duration = Duration(seconds: 10);
|
const duration = Duration(seconds: 10);
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
// Code ở đây chạy sau khi giao diện render xong
|
||||||
getAllDevicesTimer =
|
getAllDevicesTimer =
|
||||||
Timer.periodic(duration, (Timer t) => homeBloc.getOwnerAndJoinedDevices(context));
|
Timer.periodic(duration, (Timer t) => homeBloc.getOwnerAndJoinedDevices(context));
|
||||||
|
// Ví dụ: gọi API, scroll tới vị trí nào đó, v.v.
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
getAllDevicesTimer?.cancel();
|
getAllDevicesTimer?.cancel();
|
||||||
@@ -53,7 +60,6 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
homeBloc.getOwnerAndJoinedDevices(context);
|
homeBloc.getOwnerAndJoinedDevices(context);
|
||||||
return const SharedLoadingAnimation();
|
return const SharedLoadingAnimation();
|
||||||
}else{
|
}else{
|
||||||
log("Goi else");
|
|
||||||
homeBloc.getOwnerDeviceState(context, aliasDevicesSnapshot.data ?? []);
|
homeBloc.getOwnerDeviceState(context, aliasDevicesSnapshot.data ?? []);
|
||||||
homeBloc.getDeviceStatusAliasMap(aliasDevicesSnapshot.data ?? []);
|
homeBloc.getDeviceStatusAliasMap(aliasDevicesSnapshot.data ?? []);
|
||||||
checkSettingDevice(aliasDevicesSnapshot.data ?? []);
|
checkSettingDevice(aliasDevicesSnapshot.data ?? []);
|
||||||
@@ -210,7 +216,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
StreamBuilder<Map<String, List<DeviceWithAlias>>>(
|
StreamBuilder<Map<String, List<DeviceWithAlias>>?>(
|
||||||
stream: homeBloc.streamAllDevicesAliasMap,
|
stream: homeBloc.streamAllDevicesAliasMap,
|
||||||
builder: (context, allDevicesAliasMapSnapshot) {
|
builder: (context, allDevicesAliasMapSnapshot) {
|
||||||
if(allDevicesAliasMapSnapshot.data == null){
|
if(allDevicesAliasMapSnapshot.data == null){
|
||||||
|
|||||||
@@ -117,6 +117,9 @@ Future<Widget> notificationCard(BuildContext context, String notificationType,
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
SizedBox(
|
||||||
|
height: context.lowValue,
|
||||||
|
),
|
||||||
device.isOwner!
|
device.isOwner!
|
||||||
? Align(
|
? Align(
|
||||||
alignment: Alignment.centerRight,
|
alignment: Alignment.centerRight,
|
||||||
@@ -152,20 +155,6 @@ Future<Widget> notificationCard(BuildContext context, String notificationType,
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
OutlinedButton(
|
|
||||||
style: const ButtonStyle(
|
|
||||||
backgroundColor:
|
|
||||||
WidgetStatePropertyAll(Colors.blueAccent),
|
|
||||||
),
|
|
||||||
onPressed: () {
|
|
||||||
context.pushNamed(AppRoutes.DEVICE_DETAIL.name,
|
|
||||||
pathParameters: {'thingID': device.thingId!});
|
|
||||||
},
|
|
||||||
child: Text(
|
|
||||||
appLocalization(context).detail_message,
|
|
||||||
style: const TextStyle(color: Colors.white),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ Future<Widget> warningCard(BuildContext context, APIServices apiServices,
|
|||||||
}
|
}
|
||||||
if (device.state! == 3) {
|
if (device.state! == 3) {
|
||||||
backgroundColor = Colors.grey;
|
backgroundColor = Colors.grey;
|
||||||
textColor = Colors.black;
|
textColor = Colors.white;
|
||||||
message = appLocalization(context).in_progress_message;
|
message = appLocalization(context).in_progress_message;
|
||||||
} else if (device.state! == 2) {
|
} else if (device.state! == 2) {
|
||||||
backgroundColor = const Color.fromARGB(255, 6, 138, 72);
|
backgroundColor = const Color.fromARGB(255, 6, 138, 72);
|
||||||
@@ -44,32 +44,18 @@ Future<Widget> warningCard(BuildContext context, APIServices apiServices,
|
|||||||
} else if (device.state! == 1) {
|
} else if (device.state! == 1) {
|
||||||
backgroundColor = const Color.fromARGB(255, 250, 63, 63);
|
backgroundColor = const Color.fromARGB(255, 250, 63, 63);
|
||||||
textColor = Colors.white;
|
textColor = Colors.white;
|
||||||
|
if(device.isOwner == true){
|
||||||
|
|
||||||
message = appLocalization(context).button_fake_fire_message;
|
message = appLocalization(context).button_fake_fire_message;
|
||||||
|
}else{
|
||||||
|
message = appLocalization(context).smoke_detecting_message_lowercase;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
backgroundColor = Colors.black;
|
backgroundColor = Colors.black;
|
||||||
textColor = Colors.white;
|
textColor = Colors.white;
|
||||||
message = appLocalization(context).disconnect_message_uppercase;
|
message = appLocalization(context).disconnect_message_uppercase;
|
||||||
}
|
}
|
||||||
return badges.Badge(
|
return Card(
|
||||||
badgeAnimation: const badges.BadgeAnimation.fade(),
|
|
||||||
position: badges.BadgePosition.bottomStart(bottom: 15, start: 10),
|
|
||||||
badgeContent: device.isOwner!
|
|
||||||
? null
|
|
||||||
: Text(
|
|
||||||
appLocalization(context).interfamily_page_name,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 20,
|
|
||||||
color: Theme.of(context).colorScheme.onSurface,
|
|
||||||
fontWeight: FontWeight.bold),
|
|
||||||
),
|
|
||||||
badgeStyle: badges.BadgeStyle(
|
|
||||||
shape: badges.BadgeShape.square,
|
|
||||||
borderRadius: BorderRadius.circular(10),
|
|
||||||
borderSide: const BorderSide(color: Colors.white, width: 2),
|
|
||||||
badgeColor: Theme.of(context).colorScheme.surfaceDim,
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
|
||||||
),
|
|
||||||
child: Card(
|
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: context.paddingLow,
|
padding: context.paddingLow,
|
||||||
child: Column(
|
child: Column(
|
||||||
@@ -158,14 +144,16 @@ Future<Widget> warningCard(BuildContext context, APIServices apiServices,
|
|||||||
SizedBox(
|
SizedBox(
|
||||||
height: context.lowValue,
|
height: context.lowValue,
|
||||||
),
|
),
|
||||||
Row(
|
device.isOwner == true
|
||||||
|
? Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
IconButton.outlined(
|
IconButton.outlined(
|
||||||
onPressed: () async => {},
|
onPressed: () async => {},
|
||||||
// displayListOfFireStationPhoneNumbers(testDevice),
|
// displayListOfFireStationPhoneNumbers(testDevice),
|
||||||
icon: IconConstants.instance.getMaterialIcon(Icons.call),
|
icon:
|
||||||
|
IconConstants.instance.getMaterialIcon(Icons.call),
|
||||||
iconSize: 25,
|
iconSize: 25,
|
||||||
style: ButtonStyle(
|
style: ButtonStyle(
|
||||||
backgroundColor:
|
backgroundColor:
|
||||||
@@ -189,8 +177,7 @@ Future<Widget> warningCard(BuildContext context, APIServices apiServices,
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(width: context.mediumValue),
|
SizedBox(width: context.mediumValue),
|
||||||
device.isOwner!
|
Expanded(
|
||||||
? Expanded(
|
|
||||||
child: Align(
|
child: Align(
|
||||||
alignment: Alignment.centerRight,
|
alignment: Alignment.centerRight,
|
||||||
child: OutlinedButton(
|
child: OutlinedButton(
|
||||||
@@ -268,6 +255,8 @@ Future<Widget> warningCard(BuildContext context, APIServices apiServices,
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
)
|
)
|
||||||
: Row(
|
: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
@@ -286,79 +275,15 @@ Future<Widget> warningCard(BuildContext context, APIServices apiServices,
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
SizedBox(width: context.mediumValue),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Align(
|
child: Align(
|
||||||
alignment: Alignment.centerRight,
|
alignment: Alignment.centerRight,
|
||||||
child: OutlinedButton(
|
child: OutlinedButton(
|
||||||
style: ButtonStyle(
|
style: ButtonStyle(
|
||||||
backgroundColor: WidgetStatePropertyAll(
|
backgroundColor:
|
||||||
backgroundColor)),
|
WidgetStatePropertyAll(backgroundColor)),
|
||||||
onPressed: () async {
|
onPressed: () async {},
|
||||||
if (message ==
|
|
||||||
appLocalization(context)
|
|
||||||
.button_fake_fire_message) {
|
|
||||||
await showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (context) => AlertDialog(
|
|
||||||
icon: const Icon(Icons.warning),
|
|
||||||
iconColor: Colors.red,
|
|
||||||
title: Text(appLocalization(context)
|
|
||||||
.confirm_fake_fire_message),
|
|
||||||
content: Text(appLocalization(context)
|
|
||||||
.confirm_fake_fire_body),
|
|
||||||
actions: [
|
|
||||||
TextButton(
|
|
||||||
onPressed: () async {
|
|
||||||
await apiServices.execute(context,
|
|
||||||
() 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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
},
|
|
||||||
child: Text(
|
|
||||||
appLocalization(context)
|
|
||||||
.confirm_fake_fire_sure_message,
|
|
||||||
style: const TextStyle(
|
|
||||||
color: Colors.red)),
|
|
||||||
),
|
|
||||||
TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
},
|
|
||||||
child: Text(appLocalization(context)
|
|
||||||
.cancel_button_content),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
showNoIconTopSnackBar(
|
|
||||||
context,
|
|
||||||
appLocalization(context)
|
|
||||||
.let_PCCC_handle_message,
|
|
||||||
Colors.orange,
|
|
||||||
Colors.white);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child: Text(
|
child: Text(
|
||||||
message,
|
message,
|
||||||
style: TextStyle(color: textColor),
|
style: TextStyle(color: textColor),
|
||||||
@@ -370,9 +295,7 @@ Future<Widget> warningCard(BuildContext context, APIServices apiServices,
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user