176 lines
6.3 KiB
Dart
176 lines
6.3 KiB
Dart
// ignore_for_file: use_build_context_synchronously
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:intl/intl.dart';
|
|
import '../../../product/shared/shared_rocket_container.dart';
|
|
import '../../../product/constant/enums/app_route_enums.dart';
|
|
import '../../../product/constant/image/image_constants.dart';
|
|
import '../../../product/extension/context_extension.dart';
|
|
import '../../../product/services/language_services.dart';
|
|
import '../../../product/utils/device_utils.dart';
|
|
|
|
import '../../../product/constant/icon/icon_constants.dart';
|
|
import '../device_alias_model.dart';
|
|
|
|
Future<Widget> notificationCard(BuildContext context, String notificationType,
|
|
String notificationTitle, DeviceWithAlias device) async {
|
|
String location = "";
|
|
if (device.areaPath != "") {
|
|
location = await DeviceUtils.instance
|
|
.getFullDeviceLocation(context, device.areaPath!, "");
|
|
}
|
|
String path = "";
|
|
String time = "";
|
|
for (var sensor in device.status!.sensors!) {
|
|
if (sensor.name! == "7") {
|
|
DateTime dateTime =
|
|
DateTime.fromMillisecondsSinceEpoch((sensor.time!) * 1000);
|
|
time = DateFormat('yyyy-MM-dd HH:mm:ss').format(dateTime);
|
|
}
|
|
}
|
|
if (notificationType == "lowBattery") {
|
|
path = ImageConstants.instance.getImage("low_battery");
|
|
}
|
|
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(
|
|
notificationTitle,
|
|
style: const TextStyle(
|
|
letterSpacing: 1,
|
|
fontWeight: FontWeight.bold,
|
|
color: Color.fromARGB(255, 250, 84, 34),
|
|
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(path),
|
|
),
|
|
],
|
|
),
|
|
SizedBox(height: context.lowValue),
|
|
Row(
|
|
children: [
|
|
IconConstants.instance
|
|
.getMaterialIcon(Icons.location_on_outlined),
|
|
SizedBox(
|
|
width: context.lowValue,
|
|
),
|
|
Expanded(
|
|
child: Text(
|
|
location,
|
|
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.toString(),
|
|
style: context.responsiveBodySmall,
|
|
maxLines: 2,
|
|
overflow: TextOverflow.ellipsis,
|
|
softWrap: true,
|
|
textAlign: TextAlign.start,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
device.isOwner!
|
|
? Align(
|
|
alignment: Alignment.centerRight,
|
|
child: 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),
|
|
),
|
|
),
|
|
)
|
|
: 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,
|
|
),
|
|
),
|
|
),
|
|
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),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|