You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
130 lines
5.5 KiB
Dart
130 lines
5.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:test_sa/extensions/context_extension.dart';
|
|
import 'package:test_sa/extensions/int_extensions.dart';
|
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
|
import 'package:test_sa/helper/utils.dart';
|
|
import 'package:test_sa/modules/alerts/alert_model.dart';
|
|
import 'package:test_sa/modules/alerts/alert_provider.dart';
|
|
import 'package:test_sa/modules/cm_module/views/components/action_button/footer_action_button.dart';
|
|
import 'package:test_sa/new_views/app_style/app_color.dart';
|
|
import 'package:test_sa/new_views/common_widgets/app_filled_button.dart';
|
|
import 'package:test_sa/new_views/common_widgets/default_app_bar.dart';
|
|
import 'package:test_sa/views/widgets/item_views/info_date_widget.dart';
|
|
import 'package:test_sa/views/widgets/item_views/info_header_widget.dart';
|
|
import 'package:test_sa/views/widgets/item_views/info_text_widget.dart';
|
|
import 'package:test_sa/views/widgets/loaders/app_loading.dart';
|
|
import 'package:test_sa/views/widgets/loaders/no_data_found.dart';
|
|
import 'package:test_sa/views/widgets/requests/request_status.dart';
|
|
|
|
class AlertDetailPage extends StatefulWidget {
|
|
static const String id = "/alert-detail-page";
|
|
final int alertId;
|
|
|
|
const AlertDetailPage({Key? key, required this.alertId}) : super(key: key);
|
|
|
|
@override
|
|
State<AlertDetailPage> createState() => _AlertDetailPageState();
|
|
}
|
|
|
|
class _AlertDetailPageState extends State<AlertDetailPage> {
|
|
AlertModel _model = AlertModel();
|
|
late AlertProvider alertProvider;
|
|
bool isDataUpdated = false;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
alertProvider = Provider.of<AlertProvider>(context, listen: false);
|
|
|
|
return Scaffold(
|
|
appBar: const DefaultAppBar(title: "Alert Details"),
|
|
body: FutureBuilder(
|
|
future: alertProvider.getAlertById(widget.alertId, refresh: isDataUpdated),
|
|
builder: (context, snap) {
|
|
if (snap.connectionState == ConnectionState.waiting) {
|
|
return const ALoading();
|
|
} else if (snap.hasData && snap.data != null) {
|
|
_model = snap.data as AlertModel;
|
|
isDataUpdated = false;
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
SingleChildScrollView(
|
|
padding: const EdgeInsets.all(16),
|
|
child: informationCard(_model),
|
|
).expanded,
|
|
if (!_model.isResolved)
|
|
FooterActionButton.footerContainer(
|
|
context: context,
|
|
child: AppFilledButton(
|
|
label: "Resolve",
|
|
onPressed: () async {
|
|
Utils.showLoading(context);
|
|
bool success = await alertProvider.resolveAlert(_model.id!);
|
|
isDataUpdated = !success;
|
|
Utils.hideLoading(context);
|
|
setState(() {});
|
|
},
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
return NoDataFound(message: context.translation.noDataFound).center;
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget informationCard(AlertModel alertModel) {
|
|
String zonesText = (alertModel.zones ?? [])
|
|
.map((z) => z.zoneName ?? (z.zoneId != null ? 'Zone ${z.zoneId}' : null))
|
|
.whereType<String>()
|
|
.join(', ');
|
|
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
StatusLabel(
|
|
label: alertModel.statusLabel,
|
|
textColor: AppColor.getRequestStatusTextColorByName(context, alertModel.statusLabel),
|
|
backgroundColor: AppColor.getRequestStatusColorByName(context, alertModel.statusLabel),
|
|
),
|
|
],
|
|
),
|
|
8.height,
|
|
InfoHeader16Widget("Alert Details"),
|
|
InfoTextWidget(label: "Alert No", value: alertModel.alertId ?? '-', copyValue: true),
|
|
InfoTextWidget(label: "Rule Name", value: alertModel.ruleName ?? '-'),
|
|
InfoTextWidget(label: "Trigger Type", value: alertModel.ruleTriggerType ?? '-'),
|
|
InfoTextWidget(label: "Severity", value: alertModel.severity ?? '-'),
|
|
if (alertModel.enter != null) InfoTextWidget(label: "Direction", value: alertModel.enter == true ? "Enter" : "Exit"),
|
|
const Divider().defaultStyle(context),
|
|
InfoHeader16Widget("Location"),
|
|
InfoTextWidget(label: context.translation.site, value: alertModel.campusName ?? '-'),
|
|
if (alertModel.venueName?.isNotEmpty ?? false) InfoTextWidget(label: "Venue", value: alertModel.venueName ?? '-'),
|
|
if (alertModel.floorName?.isNotEmpty ?? false) InfoTextWidget(label: context.translation.floor, value: alertModel.floorName ?? '-'),
|
|
if (zonesText.isNotEmpty) InfoTextWidget(label: "Zones", value: zonesText),
|
|
],
|
|
).expanded,
|
|
InfoDateWidget(alertModel.createdDate ?? alertModel.dateTime ?? ""),
|
|
],
|
|
),
|
|
],
|
|
).toShadowContainer(context, padding: 16);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|