183 lines
6.4 KiB
Dart
183 lines
6.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:ftc_mobile_app/dialogs/app_dialogs.dart';
|
|
import 'package:ftc_mobile_app/models/clients/recent_incidents_model.dart';
|
|
import 'package:ftc_mobile_app/models/profileData/user_data.dart';
|
|
import 'package:ftc_mobile_app/view/custom_widgets/custom_app_bar_with_action.dart';
|
|
import 'package:ftc_mobile_app/view/screens/clientsListing/widgets/search_bar_widget.dart';
|
|
import 'package:get/get.dart';
|
|
import '../../../ftc_mobile_app.dart';
|
|
import 'add_new_recent_incident_screen.dart';
|
|
|
|
class RecentIncidentsScreen extends StatefulWidget {
|
|
final UserData userData;
|
|
|
|
const RecentIncidentsScreen({Key? key, required this.userData})
|
|
: super(key: key);
|
|
|
|
@override
|
|
State<RecentIncidentsScreen> createState() => _RecentIncidentsScreenState();
|
|
}
|
|
|
|
class _RecentIncidentsScreenState extends State<RecentIncidentsScreen> {
|
|
late final RecentIncidentsScreenController controller;
|
|
|
|
@override
|
|
void initState() {
|
|
controller = Get.put(RecentIncidentsScreenController(widget.userData));
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return CustomScaffold(
|
|
backgroundColor: CustomAppColors.kPrimaryColor,
|
|
screenKey: controller.screenKey,
|
|
onScreenTap: controller.removeFocus,
|
|
showAppBar: true,
|
|
appBar: _appBar(context),
|
|
body: SafeArea(
|
|
child: Column(
|
|
children: [
|
|
8.verticalSpace,
|
|
SearchBarWidget(
|
|
controller: controller.searchTEC,
|
|
onSearchTextChange: controller.onSearch,
|
|
),
|
|
8.verticalSpace,
|
|
Expanded(
|
|
child: Obx(
|
|
() => controller.recentIncidentsList.isEmpty
|
|
? FrequentFunctions.centerText(text: "No data found")
|
|
: ListView.separated(
|
|
itemCount: controller.recentIncidentsList.length,
|
|
separatorBuilder: (_, index) => 12.verticalSpace,
|
|
padding: REdgeInsets.symmetric(horizontal: 20.r),
|
|
itemBuilder: (_, int index) {
|
|
return RecentIncidentTile(
|
|
data: controller.recentIncidentsList[index],
|
|
onTap: () {
|
|
AppDialog.showRecentIncidentDetailDialog(
|
|
data: controller.recentIncidentsList[index]);
|
|
},
|
|
onEdit: () async {
|
|
dynamic result = await Navigator.pushNamed(
|
|
context,
|
|
CustomRouteNames
|
|
.kAddNewRecentIncidentsScreenRoute,
|
|
arguments: AddNewRecentIncidentsScreenArgs(
|
|
incidentsModel: controller
|
|
.recentIncidentsList[index]));
|
|
|
|
if (result is RecentIncidentsModel) {
|
|
controller.recentIncidentsList
|
|
.replaceRange(index, index + 1, [result]);
|
|
controller.recentIncidentsList.refresh();
|
|
}
|
|
},
|
|
);
|
|
}),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
AppBar _appBar(BuildContext context) {
|
|
return CustomAppBarTitleOnly(
|
|
context,
|
|
titleText: "Recent Incidents",
|
|
// actionText: '+ Add New',
|
|
// onActionTap: () async {
|
|
// dynamic result = await Navigator.pushNamed(
|
|
// context, CustomRouteNames.kAddNewRecentIncidentsScreenRoute,
|
|
// arguments: AddNewRecentIncidentsScreenArgs(
|
|
// userId: controller.serviceUser()!.id!));
|
|
// if (result is RecentIncidentsModel) {
|
|
// controller.recentIncidentsList.insert(0, result);
|
|
// controller.recentIncidentsList = controller.recentIncidentsList;
|
|
// }
|
|
// },
|
|
);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
controller.dispose();
|
|
super.dispose();
|
|
}
|
|
}
|
|
|
|
class RecentIncidentTile extends StatelessWidget {
|
|
final RecentIncidentsModel data;
|
|
final VoidCallback onTap;
|
|
final VoidCallback onEdit;
|
|
|
|
const RecentIncidentTile({
|
|
super.key,
|
|
required this.data,
|
|
required this.onTap,
|
|
required this.onEdit,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return InkWell(
|
|
onTap: onTap,
|
|
child: Container(
|
|
alignment: Alignment.centerLeft,
|
|
width: MediaQuery.of(context).size.width,
|
|
padding: EdgeInsets.symmetric(horizontal: 13.sp, vertical: 10),
|
|
decoration: BoxDecoration(
|
|
border: Border.all(color: CustomAppColors.kSecondaryColor),
|
|
borderRadius: BorderRadius.circular(10.r),
|
|
),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: CustomTextWidget(
|
|
text: data.incidentTitle.isNotEmpty
|
|
? data.incidentTitle
|
|
: "Untitled Incident",
|
|
isExpanded: false,
|
|
fontWeight: FontWeight.w600,
|
|
fontSize: 14.sp,
|
|
maxLines: 1,
|
|
textAlign: TextAlign.left,
|
|
fontColor: CustomAppColors.kSecondaryColor,
|
|
),
|
|
),
|
|
// 8.horizontalSpace,
|
|
// EditIcon(onTap: onEdit),
|
|
],
|
|
),
|
|
Text.rich(TextSpan(children: [
|
|
TextSpan(
|
|
text: "Incident Date - Time : ",
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.w600,
|
|
fontSize: 12.sp,
|
|
color: Colors.black,
|
|
)),
|
|
TextSpan(
|
|
text: DateFormatter.ddMMyyyyhhmmFormat(
|
|
DateTime.fromMillisecondsSinceEpoch(data.incidentDate)
|
|
.toLocal()),
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.w600,
|
|
fontSize: 12.sp,
|
|
color: CustomAppColors.kLightGreyColor,
|
|
)),
|
|
])),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|