Files
sfm_app_final/lib/feature/home/shared/warning_card.dart

302 lines
13 KiB
Dart

// ignore_for_file: use_build_context_synchronously
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:maps_launcher/maps_launcher.dart';
import 'package:badges/badges.dart' as badges;
import '../../../product/shared/shared_rocket_container.dart';
import '../device_alias_model.dart';
import '../../../product/constant/icon/icon_constants.dart';
import '../../../product/constant/image/image_constants.dart';
import '../../../product/extension/context_extension.dart';
import '../../../product/services/api_services.dart';
import '../../../product/services/language_services.dart';
import '../../../product/utils/device_utils.dart';
import '../../../product/shared/shared_snack_bar.dart';
Future<Widget> warningCard(BuildContext context, APIServices apiServices,
DeviceWithAlias device) async {
Color backgroundColor = Colors.blue;
Color textColor = Colors.white;
String message = "";
String fullLocation = "";
if (device.areaPath != "") {
fullLocation = await DeviceUtils.instance
.getFullDeviceLocation(context, device.areaPath!, "");
}
String time = "";
for (var sensor in device.status!.sensors!) {
if (sensor.name! == "11") {
DateTime dateTime =
DateTime.fromMillisecondsSinceEpoch((sensor.time!) * 1000);
time = DateFormat('yyyy-MM-dd HH:mm:ss').format(dateTime);
}
}
if (device.state! == 3) {
backgroundColor = Colors.grey;
textColor = Colors.white;
message = appLocalization(context).in_progress_message;
} else if (device.state! == 2) {
backgroundColor = const Color.fromARGB(255, 6, 138, 72);
textColor = const Color.fromARGB(255, 255, 255, 255);
message = appLocalization(context).gf_in_firefighting_message;
} else if (device.state! == 1) {
backgroundColor = const Color.fromARGB(255, 250, 63, 63);
textColor = Colors.white;
if(device.isOwner == true){
message = appLocalization(context).button_fake_fire_message;
}else{
message = appLocalization(context).smoke_detecting_message_lowercase;
}
} else {
backgroundColor = Colors.black;
textColor = Colors.white;
message = appLocalization(context).disconnect_message_uppercase;
}
return Card(
child: Padding(
padding: context.paddingLow,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
child: Text(
appLocalization(context).smoke_detecting_message,
style: const TextStyle(
letterSpacing: 1,
fontWeight: FontWeight.bold,
color: Colors.red,
fontSize: 18,
),
),
),
SizedBox(height: context.lowValue),
SizedBox(
child: Text(
"${appLocalization(context).device_title}: ${device.isOwner! ? device.name : device.alias}",
style: context.responsiveBodyLargeWithBold,
maxLines: 2,
overflow: TextOverflow.ellipsis,
softWrap: true,
textAlign: TextAlign.start,
),
),
],
),
SizedBox(
height: context.dynamicWidth(0.15),
width: context.dynamicWidth(0.15),
child: Image.asset(
ImageConstants.instance.getImage("fire_warning")),
)
],
),
SizedBox(height: context.lowValue),
Row(
children: [
IconConstants.instance
.getMaterialIcon(Icons.location_on_outlined),
SizedBox(
width: context.lowValue,
),
Expanded(
child: Text(
fullLocation,
style: context.responsiveBodySmall,
maxLines: 2,
overflow: TextOverflow.ellipsis,
softWrap: true,
textAlign: TextAlign.start,
),
),
],
),
SizedBox(height: context.lowValue),
Row(
children: [
IconConstants.instance.getMaterialIcon(Icons.schedule),
SizedBox(
width: context.lowValue,
),
Expanded(
child: Text(
time,
style: context.responsiveBodySmall,
maxLines: 2,
overflow: TextOverflow.ellipsis,
softWrap: true,
textAlign: TextAlign.start,
),
),
],
),
SizedBox(
height: context.lowValue,
),
device.isOwner == true
? Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
IconButton.outlined(
onPressed: () async => {},
// displayListOfFireStationPhoneNumbers(testDevice),
icon:
IconConstants.instance.getMaterialIcon(Icons.call),
iconSize: 25,
style: ButtonStyle(
backgroundColor:
WidgetStateProperty.all<Color>(Colors.blue[300]!),
),
),
const SizedBox(width: 10),
IconButton.outlined(
onPressed: () async {
String markerLabel = "Destination";
MapsLauncher.launchCoordinates(
double.parse(device.settings!.latitude!),
double.parse(device.settings!.longitude!),
markerLabel);
},
icon: const Icon(Icons.directions),
iconSize: 25,
style: ButtonStyle(
backgroundColor:
WidgetStateProperty.all<Color>(Colors.blue[300]!),
),
),
SizedBox(width: context.mediumValue),
Expanded(
child: Align(
alignment: Alignment.centerRight,
child: OutlinedButton(
style: ButtonStyle(
backgroundColor:
WidgetStatePropertyAll(backgroundColor)),
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(
message,
style: TextStyle(color: textColor),
),
),
),
),
],
)
: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
ClipPath(
clipper: SharedRocketContainer(),
child: Container(
padding: EdgeInsets.all(context.lowValue),
height: context.mediumValue,
width: context.dynamicWidth(0.22),
decoration: BoxDecoration(
color: Colors.green[300],
),
child: Text(
appLocalization(context).interfamily_page_name,
),
),
),
SizedBox(width: context.mediumValue),
Expanded(
child: Align(
alignment: Alignment.centerRight,
child: OutlinedButton(
style: ButtonStyle(
backgroundColor:
WidgetStatePropertyAll(backgroundColor)),
onPressed: () async {},
child: Text(
message,
style: TextStyle(color: textColor),
),
),
),
),
],
),
],
),
),
);
}