fix(ui): display interfamily tags when interfamily's devices state = 1
This commit is contained in:
@@ -1,12 +1,11 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:developer';
|
|
||||||
|
|
||||||
import 'package:sfm_app/feature/devices/device_model.dart';
|
import '../feature/devices/device_model.dart';
|
||||||
import 'package:sfm_app/product/base/bloc/base_bloc.dart';
|
import '../product/base/bloc/base_bloc.dart';
|
||||||
import 'package:sfm_app/product/constant/app/app_constants.dart';
|
import '../product/constant/app/app_constants.dart';
|
||||||
import 'package:sfm_app/product/services/api_services.dart';
|
import '../product/services/api_services.dart';
|
||||||
import 'package:sfm_app/product/utils/date_time_utils.dart';
|
import '../product/utils/date_time_utils.dart';
|
||||||
|
|
||||||
import '../product/utils/device_utils.dart';
|
import '../product/utils/device_utils.dart';
|
||||||
import '../feature/device_log/device_logs_model.dart';
|
import '../feature/device_log/device_logs_model.dart';
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import 'dart:developer';
|
|
||||||
|
|
||||||
import 'package:dropdown_button2/dropdown_button2.dart';
|
import 'package:dropdown_button2/dropdown_button2.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|||||||
@@ -103,8 +103,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
(item) => FutureBuilder<Widget>(
|
(item) => FutureBuilder<Widget>(
|
||||||
future: warningCard(
|
future: warningCard(
|
||||||
context, apiServices, item),
|
context, apiServices, item),
|
||||||
builder:
|
builder: (context, warningCardSnapshot) {
|
||||||
(context, warningCardSnapshot) {
|
|
||||||
if (warningCardSnapshot.hasData) {
|
if (warningCardSnapshot.hasData) {
|
||||||
return ConstrainedBox(
|
return ConstrainedBox(
|
||||||
constraints: const BoxConstraints(
|
constraints: const BoxConstraints(
|
||||||
@@ -128,11 +127,9 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
context,
|
context,
|
||||||
"lowBattery",
|
"lowBattery",
|
||||||
"Cảnh báo pin yếu",
|
"Cảnh báo pin yếu",
|
||||||
batteryItem.name!,
|
batteryItem
|
||||||
batteryItem.areaPath!,
|
|
||||||
),
|
),
|
||||||
builder:
|
builder: (context, warningCardSnapshot) {
|
||||||
(context, warningCardSnapshot) {
|
|
||||||
if (warningCardSnapshot.hasData) {
|
if (warningCardSnapshot.hasData) {
|
||||||
return ConstrainedBox(
|
return ConstrainedBox(
|
||||||
constraints: const BoxConstraints(
|
constraints: const BoxConstraints(
|
||||||
@@ -148,7 +145,8 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
.toList(),
|
.toList(),
|
||||||
]);
|
],
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: context.paddingMedium,
|
padding: context.paddingMedium,
|
||||||
@@ -355,13 +353,14 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
checkSettingdevice(allDevicesAliasJoined);
|
// checkSettingdevice(allDevicesAliasJoined);
|
||||||
homeBloc.sinkAllDevicesAlias.add(allDevicesAlias);
|
homeBloc.sinkAllDevicesAlias.add(allDevicesAlias);
|
||||||
homeBloc.sinkAllDevicesAliasJoined.add(allDevicesAliasJoined);
|
homeBloc.sinkAllDevicesAliasJoined.add(allDevicesAliasJoined);
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkSettingdevice(List<DeviceWithAlias> devices) async {
|
void checkSettingdevice(List<DeviceWithAlias> devices) async {
|
||||||
if (isFunctionCall) {
|
if (isFunctionCall) {
|
||||||
|
log("Ham check setting da duoc goi");
|
||||||
} else {
|
} else {
|
||||||
String? response =
|
String? response =
|
||||||
await apiServices.getAllSettingsNotificationOfDevices();
|
await apiServices.getAllSettingsNotificationOfDevices();
|
||||||
@@ -380,7 +379,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
await apiServices.setupDeviceNotification(
|
await apiServices.setupDeviceNotification(
|
||||||
device.thingId!, device.name!);
|
device.thingId!, device.name!);
|
||||||
} else {
|
} else {
|
||||||
log("All devives are in the notification settings list.");
|
log("All devices are in the notification settings list.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
// 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:go_router/go_router.dart';
|
||||||
|
import 'package:sfm_app/feature/home/device_alias_model.dart';
|
||||||
|
import '../../../product/constant/enums/app_route_enums.dart';
|
||||||
import '../../../product/constant/image/image_constants.dart';
|
import '../../../product/constant/image/image_constants.dart';
|
||||||
import '../../../product/extention/context_extention.dart';
|
import '../../../product/extention/context_extention.dart';
|
||||||
import '../../../product/services/language_services.dart';
|
import '../../../product/services/language_services.dart';
|
||||||
@@ -8,14 +11,13 @@ import '../../../product/utils/device_utils.dart';
|
|||||||
|
|
||||||
import '../../../product/constant/icon/icon_constants.dart';
|
import '../../../product/constant/icon/icon_constants.dart';
|
||||||
|
|
||||||
Future<Widget> notificationCard(
|
Future<Widget> notificationCard(BuildContext context, String notiticationType,
|
||||||
BuildContext context,
|
String notificationTitle, DeviceWithAlias device) async {
|
||||||
String notiticationType,
|
String location = "";
|
||||||
String notificationTitle,
|
if (device.areaPath != "") {
|
||||||
String notificationDevicename,
|
location = await DeviceUtils.instance
|
||||||
String notificationLocation) async {
|
.getFullDeviceLocation(context, device.areaPath!);
|
||||||
String location = await DeviceUtils.instance
|
}
|
||||||
.getFullDeviceLocation(context, notificationLocation);
|
|
||||||
String path = "";
|
String path = "";
|
||||||
DateTime time = DateTime.now();
|
DateTime time = DateTime.now();
|
||||||
if (notiticationType == "lowBattery") {
|
if (notiticationType == "lowBattery") {
|
||||||
@@ -50,7 +52,7 @@ Future<Widget> notificationCard(
|
|||||||
SizedBox(height: context.lowValue),
|
SizedBox(height: context.lowValue),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
child: Text(
|
child: Text(
|
||||||
"${appLocalization(context).device_title} $notificationDevicename",
|
"${appLocalization(context).device_title} ${device.isOwner! ? device.name : device.alias}",
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
fontSize: 18,
|
fontSize: 18,
|
||||||
@@ -113,8 +115,12 @@ Future<Widget> notificationCard(
|
|||||||
alignment: Alignment.centerRight,
|
alignment: Alignment.centerRight,
|
||||||
child: OutlinedButton(
|
child: OutlinedButton(
|
||||||
style: const ButtonStyle(
|
style: const ButtonStyle(
|
||||||
backgroundColor: WidgetStatePropertyAll(Colors.blueAccent)),
|
backgroundColor: WidgetStatePropertyAll(Colors.blueAccent),
|
||||||
onPressed: () {},
|
),
|
||||||
|
onPressed: () {
|
||||||
|
context.pushNamed(AppRoutes.DEVICE_DETAIL.name,
|
||||||
|
pathParameters: {'thingID': device.thingId!});
|
||||||
|
},
|
||||||
child: Text(
|
child: Text(
|
||||||
appLocalization(context).detail_message,
|
appLocalization(context).detail_message,
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:maps_launcher/maps_launcher.dart';
|
import 'package:maps_launcher/maps_launcher.dart';
|
||||||
|
import 'package:badges/badges.dart' as badges;
|
||||||
import '../device_alias_model.dart';
|
import '../device_alias_model.dart';
|
||||||
import '../../../product/constant/icon/icon_constants.dart';
|
import '../../../product/constant/icon/icon_constants.dart';
|
||||||
import '../../../product/constant/image/image_constants.dart';
|
import '../../../product/constant/image/image_constants.dart';
|
||||||
@@ -12,30 +13,33 @@ import '../../../product/services/language_services.dart';
|
|||||||
import '../../../product/utils/device_utils.dart';
|
import '../../../product/utils/device_utils.dart';
|
||||||
import '../../../product/shared/shared_snack_bar.dart';
|
import '../../../product/shared/shared_snack_bar.dart';
|
||||||
|
|
||||||
Future<Widget> warningCard(
|
Future<Widget> warningCard(BuildContext context, APIServices apiServices,
|
||||||
BuildContext context, APIServices apiServices, DeviceWithAlias item) async {
|
DeviceWithAlias device) async {
|
||||||
Color backgroundColor = Colors.blue;
|
Color backgroundColor = Colors.blue;
|
||||||
Color textColor = Colors.white;
|
Color textColor = Colors.white;
|
||||||
String message = "";
|
String message = "";
|
||||||
String fullLocation =
|
String fullLocation = "";
|
||||||
await DeviceUtils.instance.getFullDeviceLocation(context, item.areaPath!);
|
if (device.areaPath != "") {
|
||||||
|
fullLocation = await DeviceUtils.instance
|
||||||
|
.getFullDeviceLocation(context, device.areaPath!);
|
||||||
|
}
|
||||||
String time = "";
|
String time = "";
|
||||||
for (var sensor in item.status!.sensors!) {
|
for (var sensor in device.status!.sensors!) {
|
||||||
if (sensor.name! == "11") {
|
if (sensor.name! == "11") {
|
||||||
DateTime dateTime =
|
DateTime dateTime =
|
||||||
DateTime.fromMillisecondsSinceEpoch((sensor.time!) * 1000);
|
DateTime.fromMillisecondsSinceEpoch((sensor.time!) * 1000);
|
||||||
time = DateFormat('yyyy-MM-dd HH:mm:ss').format(dateTime);
|
time = DateFormat('yyyy-MM-dd HH:mm:ss').format(dateTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (item.state! == 3) {
|
if (device.state! == 3) {
|
||||||
backgroundColor = Colors.grey;
|
backgroundColor = Colors.grey;
|
||||||
textColor = Colors.black;
|
textColor = Colors.black;
|
||||||
message = appLocalization(context).in_progress_message;
|
message = appLocalization(context).in_progress_message;
|
||||||
} else if (item.state! == 2) {
|
} else if (device.state! == 2) {
|
||||||
backgroundColor = const Color.fromARGB(255, 6, 138, 72);
|
backgroundColor = const Color.fromARGB(255, 6, 138, 72);
|
||||||
textColor = const Color.fromARGB(255, 255, 255, 255);
|
textColor = const Color.fromARGB(255, 255, 255, 255);
|
||||||
message = appLocalization(context).gf_in_firefighting_message;
|
message = appLocalization(context).gf_in_firefighting_message;
|
||||||
} else if (item.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;
|
||||||
message = appLocalization(context).button_fake_fire_message;
|
message = appLocalization(context).button_fake_fire_message;
|
||||||
@@ -44,8 +48,26 @@ Future<Widget> warningCard(
|
|||||||
textColor = Colors.white;
|
textColor = Colors.white;
|
||||||
message = appLocalization(context).disconnect_message_uppercase;
|
message = appLocalization(context).disconnect_message_uppercase;
|
||||||
}
|
}
|
||||||
return Card(
|
return badges.Badge(
|
||||||
// color: Color.fromARGB(255, 208, 212, 217),
|
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(
|
||||||
@@ -74,7 +96,7 @@ Future<Widget> warningCard(
|
|||||||
SizedBox(height: context.lowValue),
|
SizedBox(height: context.lowValue),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
child: Text(
|
child: Text(
|
||||||
"${appLocalization(context).device_title}: ${item.name}",
|
"${appLocalization(context).device_title}: ${device.isOwner! ? device.name : device.alias}",
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
fontSize: 18,
|
fontSize: 18,
|
||||||
@@ -156,8 +178,8 @@ Future<Widget> warningCard(
|
|||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
String markerLabel = "Destination";
|
String markerLabel = "Destination";
|
||||||
MapsLauncher.launchCoordinates(
|
MapsLauncher.launchCoordinates(
|
||||||
double.parse(item.settings!.latitude!),
|
double.parse(device.settings!.latitude!),
|
||||||
double.parse(item.settings!.longitude!),
|
double.parse(device.settings!.longitude!),
|
||||||
markerLabel);
|
markerLabel);
|
||||||
},
|
},
|
||||||
icon: const Icon(Icons.directions),
|
icon: const Icon(Icons.directions),
|
||||||
@@ -191,7 +213,7 @@ Future<Widget> warningCard(
|
|||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
int statusCode = await apiServices
|
int statusCode = await apiServices
|
||||||
.confirmFakeFireByUser(item.thingId!);
|
.confirmFakeFireByUser(device.thingId!);
|
||||||
if (statusCode == 200) {
|
if (statusCode == 200) {
|
||||||
showNoIconTopSnackBar(
|
showNoIconTopSnackBar(
|
||||||
context,
|
context,
|
||||||
@@ -212,7 +234,8 @@ Future<Widget> warningCard(
|
|||||||
child: Text(
|
child: Text(
|
||||||
appLocalization(context)
|
appLocalization(context)
|
||||||
.confirm_fake_fire_sure_message,
|
.confirm_fake_fire_sure_message,
|
||||||
style: const TextStyle(color: Colors.red)),
|
style:
|
||||||
|
const TextStyle(color: Colors.red)),
|
||||||
),
|
),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
@@ -244,5 +267,6 @@ Future<Widget> warningCard(
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -329,4 +329,5 @@ class DeviceUtils {
|
|||||||
return Colors.red;
|
return Colors.red;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user