fist commit ftc staff app clone
This commit is contained in:
@@ -0,0 +1,358 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:ftc_mobile_app/models/clients/riskAssessmentResponse/RiskAssessmentData.dart';
|
||||
import 'package:ftc_mobile_app/models/profileData/user_data.dart';
|
||||
import 'package:ftc_mobile_app/utilities/extensions/custom_extensions.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'controller/add_edit_risk_assessment_screen_controller.dart';
|
||||
import 'package:ftc_mobile_app/ftc_mobile_app.dart';
|
||||
|
||||
class AddEditRiskAssessmentScreenArgs {
|
||||
final UserData userData;
|
||||
|
||||
//If [issueData] is not null, then this screen will update its content instead
|
||||
final RiskAssessmentData? riskAssessmentData;
|
||||
|
||||
AddEditRiskAssessmentScreenArgs({
|
||||
required this.userData,
|
||||
this.riskAssessmentData,
|
||||
});
|
||||
}
|
||||
|
||||
class AddEditRiskAssessmentScreen extends StatefulWidget {
|
||||
final AddEditRiskAssessmentScreenArgs args;
|
||||
|
||||
const AddEditRiskAssessmentScreen({Key? key, required this.args})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
State<AddEditRiskAssessmentScreen> createState() =>
|
||||
_AddDetailsToNewBodyPointScreenState();
|
||||
}
|
||||
|
||||
class _AddDetailsToNewBodyPointScreenState
|
||||
extends State<AddEditRiskAssessmentScreen> {
|
||||
final AddEditRiskAssessmentScreenController controller =
|
||||
Get.put(AddEditRiskAssessmentScreenController());
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
//Note: Important
|
||||
controller.serviceUserId = widget.args.userData.id!;
|
||||
|
||||
if (widget.args.riskAssessmentData != null) {
|
||||
controller.isEditing.value = true;
|
||||
|
||||
controller.hazardTEC.text = widget.args.riskAssessmentData!.hazard ?? "";
|
||||
controller.personsExposedToHazardTEC.text =
|
||||
widget.args.riskAssessmentData!.personsExposedToHazard ?? "";
|
||||
controller.riskIdentifiedTEC.text =
|
||||
widget.args.riskAssessmentData!.riskIdentified ?? "";
|
||||
controller.controlMeasuresRequiredTEC.text =
|
||||
widget.args.riskAssessmentData!.coldMeasureRequired ?? "";
|
||||
|
||||
//Pure Risk Rating
|
||||
controller.pureRiskRatingCTEC.text =
|
||||
widget.args.riskAssessmentData!.pureRiskRating?.c?.toString() ?? "";
|
||||
controller.pureRiskRatingLTEC.text =
|
||||
widget.args.riskAssessmentData!.pureRiskRating?.l?.toString() ?? "";
|
||||
controller.pureRiskRatingRTEC.text =
|
||||
widget.args.riskAssessmentData!.pureRiskRating?.r?.toString() ?? "";
|
||||
|
||||
//In Place Rating
|
||||
controller.inPlaceYTEC.text =
|
||||
widget.args.riskAssessmentData!.inPlace?.y?.toString() ?? "";
|
||||
controller.inPlaceNTEC.text =
|
||||
widget.args.riskAssessmentData!.inPlace?.n?.toString() ?? "";
|
||||
|
||||
//Residual Risk Rating
|
||||
controller.residualRiskRatingCTEC.text =
|
||||
widget.args.riskAssessmentData!.residualRiskRating?.c?.toString() ??
|
||||
"";
|
||||
controller.residualRiskRatingLTEC.text =
|
||||
widget.args.riskAssessmentData!.residualRiskRating?.l?.toString() ??
|
||||
"";
|
||||
controller.residualRiskRatingRTEC.text =
|
||||
widget.args.riskAssessmentData!.residualRiskRating?.r?.toString() ??
|
||||
"";
|
||||
}
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Obx(() {
|
||||
return CustomScaffold(
|
||||
backgroundColor: CustomAppColors.kPrimaryColor,
|
||||
screenKey: controller.screenKey,
|
||||
onScreenTap: controller.removeFocus,
|
||||
showAppBar: true,
|
||||
appBar: CustomAppBarTitleOnly(context,
|
||||
titleText: controller.isEditing()
|
||||
? "Update Risk Assessment"
|
||||
: "Add New Risk Assessment"),
|
||||
body: SafeArea(
|
||||
child: ListView(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.r),
|
||||
children: [
|
||||
20.verticalSpace,
|
||||
CustomTextFieldWidget(
|
||||
borderRadius: BorderRadius.circular(10.r),
|
||||
borderColor: CustomAppColors.kLightGreyColor,
|
||||
borderWidth: 1.0.sp,
|
||||
minLines: 1,
|
||||
maxLines: 1,
|
||||
controller: controller.hazardTEC,
|
||||
textCapitalization: TextCapitalization.sentences,
|
||||
heading: "Hazard",
|
||||
hintText: "",
|
||||
),
|
||||
20.verticalSpace,
|
||||
headingText("Pure Risk Rating"),
|
||||
8.verticalSpace,
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text("C"),
|
||||
4.verticalSpace,
|
||||
dropdown(
|
||||
textEditingController:
|
||||
controller.pureRiskRatingCTEC),
|
||||
],
|
||||
),
|
||||
),
|
||||
8.horizontalSpace,
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text("L"),
|
||||
4.verticalSpace,
|
||||
dropdown(
|
||||
textEditingController:
|
||||
controller.pureRiskRatingLTEC),
|
||||
],
|
||||
),
|
||||
),
|
||||
8.horizontalSpace,
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text("R"),
|
||||
4.verticalSpace,
|
||||
dropdown(
|
||||
textEditingController:
|
||||
controller.pureRiskRatingRTEC),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
20.verticalSpace,
|
||||
headingText("In Place"),
|
||||
8.verticalSpace,
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text("Y"),
|
||||
4.verticalSpace,
|
||||
dropdown(textEditingController: controller.inPlaceYTEC),
|
||||
],
|
||||
),
|
||||
),
|
||||
8.horizontalSpace,
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text("N"),
|
||||
4.verticalSpace,
|
||||
dropdown(textEditingController: controller.inPlaceNTEC),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
20.verticalSpace,
|
||||
headingText("Residual Risk Rating"),
|
||||
8.verticalSpace,
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text("C"),
|
||||
4.verticalSpace,
|
||||
dropdown(
|
||||
textEditingController:
|
||||
controller.residualRiskRatingCTEC),
|
||||
],
|
||||
),
|
||||
),
|
||||
8.horizontalSpace,
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text("L"),
|
||||
4.verticalSpace,
|
||||
dropdown(
|
||||
textEditingController:
|
||||
controller.residualRiskRatingLTEC),
|
||||
],
|
||||
),
|
||||
),
|
||||
8.horizontalSpace,
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text("R"),
|
||||
4.verticalSpace,
|
||||
dropdown(
|
||||
textEditingController:
|
||||
controller.residualRiskRatingRTEC),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
20.verticalSpace,
|
||||
CustomTextFieldWidget(
|
||||
borderRadius: BorderRadius.circular(10.r),
|
||||
borderColor: CustomAppColors.kLightGreyColor,
|
||||
borderWidth: 1.0.sp,
|
||||
minLines: 6,
|
||||
maxLines: 6,
|
||||
controller: controller.personsExposedToHazardTEC,
|
||||
inputType: TextInputType.multiline,
|
||||
textCapitalization: TextCapitalization.sentences,
|
||||
heading: "Personal (s) Exposed to hazard",
|
||||
hintText: "",
|
||||
onChange: (_) {},
|
||||
),
|
||||
20.verticalSpace,
|
||||
CustomTextFieldWidget(
|
||||
borderRadius: BorderRadius.circular(10.r),
|
||||
borderColor: CustomAppColors.kLightGreyColor,
|
||||
borderWidth: 1.0.sp,
|
||||
minLines: 6,
|
||||
maxLines: 6,
|
||||
controller: controller.riskIdentifiedTEC,
|
||||
inputType: TextInputType.multiline,
|
||||
textCapitalization: TextCapitalization.sentences,
|
||||
heading: "Risk Identified",
|
||||
hintText: "",
|
||||
onChange: (_) {},
|
||||
),
|
||||
20.verticalSpace,
|
||||
CustomTextFieldWidget(
|
||||
borderRadius: BorderRadius.circular(10.r),
|
||||
borderColor: CustomAppColors.kLightGreyColor,
|
||||
borderWidth: 1.0.sp,
|
||||
minLines: 6,
|
||||
maxLines: 6,
|
||||
controller: controller.controlMeasuresRequiredTEC,
|
||||
inputType: TextInputType.multiline,
|
||||
textCapitalization: TextCapitalization.sentences,
|
||||
heading: "Control Measures Required",
|
||||
hintText: "",
|
||||
onChange: (_) {},
|
||||
),
|
||||
20.verticalSpace,
|
||||
Obx(
|
||||
() => CustomAppButton(
|
||||
buttonText: controller.isEditing() ? "Update" : "Save",
|
||||
onTap: () => controller.submitButtonPressed(context),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Widget headingText(String text) => CustomTextWidget(
|
||||
text: text,
|
||||
isExpanded: false,
|
||||
fontSize: 16.sp,
|
||||
fontWeight: FontWeight.w600,
|
||||
textAlign: TextAlign.left,
|
||||
);
|
||||
|
||||
Widget dropdown({
|
||||
required TextEditingController textEditingController,
|
||||
}) {
|
||||
return SizedBox(
|
||||
height: 48.r,
|
||||
child: DropdownButtonFormField<String>(
|
||||
value: textEditingController.text,
|
||||
isDense: true,
|
||||
onTap: () {
|
||||
FocusScopeNode().unfocus();
|
||||
},
|
||||
dropdownColor: Colors.white,
|
||||
decoration: InputDecoration(
|
||||
contentPadding: REdgeInsets.symmetric(horizontal: 12),
|
||||
border: OutlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: CustomAppColors.kLightGreyColor.withOpacity(0.2)),
|
||||
borderRadius: 8.toRadius(),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(color: CustomAppColors.kLightGreyColor),
|
||||
borderRadius: 8.toRadius(),
|
||||
),
|
||||
),
|
||||
hint: Text(
|
||||
"Select...",
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 14.sp,
|
||||
color: CustomAppColors.kLightTextColor,
|
||||
),
|
||||
),
|
||||
items: controller.ratings
|
||||
.map(
|
||||
(e) => DropdownMenuItem(
|
||||
value: e.toString(),
|
||||
child: Text(e.toString()),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
isExpanded: true,
|
||||
iconSize: 20.h,
|
||||
icon: Padding(
|
||||
padding: REdgeInsets.only(right: 4.0),
|
||||
child: const Icon(Icons.arrow_drop_down_sharp, color: Colors.grey),
|
||||
),
|
||||
onChanged: (v) {
|
||||
textEditingController.text = v ?? "1";
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:ftc_mobile_app/ftc_mobile_app.dart';
|
||||
import 'package:ftc_mobile_app/models/clients/riskAssessmentResponse/InPlace.dart';
|
||||
import 'package:ftc_mobile_app/models/clients/riskAssessmentResponse/PureRiskRating.dart';
|
||||
import 'package:ftc_mobile_app/models/clients/riskAssessmentResponse/ResidualRiskRating.dart';
|
||||
import 'package:ftc_mobile_app/models/clients/riskAssessmentResponse/RiskAssessmentData.dart';
|
||||
import 'package:ftc_mobile_app/utilities/extensions/custom_extensions.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class AddEditRiskAssessmentScreenController extends GetxController {
|
||||
final GlobalKey<ScaffoldState> screenKey = GlobalKey<ScaffoldState>();
|
||||
|
||||
final ratings = List.generate(9, (i) => i + 1);
|
||||
|
||||
final hazardTEC = TextEditingController();
|
||||
final personsExposedToHazardTEC = TextEditingController();
|
||||
final riskIdentifiedTEC = TextEditingController();
|
||||
final controlMeasuresRequiredTEC = TextEditingController();
|
||||
|
||||
final pureRiskRatingCTEC = TextEditingController(text: "1");
|
||||
final pureRiskRatingLTEC = TextEditingController(text: "1");
|
||||
final pureRiskRatingRTEC = TextEditingController(text: "1");
|
||||
|
||||
final residualRiskRatingCTEC = TextEditingController(text: "1");
|
||||
final residualRiskRatingLTEC = TextEditingController(text: "1");
|
||||
final residualRiskRatingRTEC = TextEditingController(text: "1");
|
||||
|
||||
final inPlaceYTEC = TextEditingController(text: "1");
|
||||
final inPlaceNTEC = TextEditingController(text: "1");
|
||||
|
||||
///[isEditing] will be true if using [AddDetailsToNewBodyPointScreen] screen to edit issue details,
|
||||
/// or say issueData is not null
|
||||
final isEditing = false.obs;
|
||||
|
||||
String serviceUserId = "";
|
||||
RiskAssessmentData? issueData;
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
if (issueData != null) {
|
||||
isEditing.value = true;
|
||||
hazardTEC.text = issueData!.hazard ?? "";
|
||||
personsExposedToHazardTEC.text = issueData!.personsExposedToHazard ?? "";
|
||||
}
|
||||
super.onReady();
|
||||
}
|
||||
|
||||
Future<void> submitButtonPressed(BuildContext context) async {
|
||||
if (hazardTEC.text.trim().isEmpty) {
|
||||
FrequentFunctions.showToast(message: "Hazard is required");
|
||||
return;
|
||||
}
|
||||
if (personsExposedToHazardTEC.text.trim().isEmpty) {
|
||||
FrequentFunctions.showToast(
|
||||
message: "Personal (s) Exposed to hazard is required");
|
||||
return;
|
||||
}
|
||||
if (riskIdentifiedTEC.text.trim().isEmpty) {
|
||||
FrequentFunctions.showToast(message: "Risk Identified is required");
|
||||
return;
|
||||
}
|
||||
if (controlMeasuresRequiredTEC.text.trim().isEmpty) {
|
||||
FrequentFunctions.showToast(
|
||||
message: "Control Measures Required is required");
|
||||
return;
|
||||
}
|
||||
|
||||
// var result = (isEditing.isFalse)
|
||||
final result = await ClientService()
|
||||
.createRiskAssesments(
|
||||
data: RiskAssessmentData(
|
||||
userId: serviceUserId,
|
||||
hazard: hazardTEC.text.trim(),
|
||||
personsExposedToHazard: personsExposedToHazardTEC.text.trim(),
|
||||
riskIdentified: riskIdentifiedTEC.text.trim(),
|
||||
coldMeasureRequired: controlMeasuresRequiredTEC.text.trim(),
|
||||
pureRiskRating: PureRiskRating(
|
||||
c: int.parse(pureRiskRatingCTEC.text.trim()),
|
||||
l: int.parse(pureRiskRatingLTEC.text.trim()),
|
||||
r: int.parse(pureRiskRatingRTEC.text.trim()),
|
||||
),
|
||||
residualRiskRating: ResidualRiskRating(
|
||||
c: int.parse(residualRiskRatingCTEC.text.trim()),
|
||||
l: int.parse(residualRiskRatingLTEC.text.trim()),
|
||||
r: int.parse(residualRiskRatingRTEC.text.trim()),
|
||||
),
|
||||
inPlace: InPlace(
|
||||
y: int.parse(inPlaceYTEC.text.trim()),
|
||||
n: int.parse(inPlaceNTEC.text.trim()),
|
||||
),
|
||||
),
|
||||
)
|
||||
.showLoader();
|
||||
if (result == true) {
|
||||
Navigator.of(screenKey.currentContext!).pop(true);
|
||||
} else {
|
||||
FrequentFunctions.showToast(message: result);
|
||||
}
|
||||
// : await ClientService()
|
||||
// .updateHealthIssueData(
|
||||
// issueId: issueData!.id,
|
||||
// categoryId: issueData!.bodyPointsCategory!.id,
|
||||
// healthNote: healthNoteController.text.trim(),
|
||||
// complaint: complaintController.text.trim())
|
||||
// .showLoader();
|
||||
//
|
||||
// if (result is! String) {
|
||||
// Navigator.of(context).pop(true);
|
||||
// } else {
|
||||
// if (result.isNotEmpty) {
|
||||
// FrequentFunctions.showToast(message: result);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
void removeFocus() {
|
||||
FocusScope.of(screenKey.currentContext!).unfocus();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
hazardTEC.dispose();
|
||||
personsExposedToHazardTEC.dispose();
|
||||
riskIdentifiedTEC.dispose();
|
||||
controlMeasuresRequiredTEC.dispose();
|
||||
|
||||
pureRiskRatingCTEC.dispose();
|
||||
pureRiskRatingLTEC.dispose();
|
||||
pureRiskRatingRTEC.dispose();
|
||||
|
||||
residualRiskRatingCTEC.dispose();
|
||||
residualRiskRatingLTEC.dispose();
|
||||
residualRiskRatingRTEC.dispose();
|
||||
|
||||
inPlaceYTEC.dispose();
|
||||
inPlaceNTEC.dispose();
|
||||
|
||||
Get.delete<AddEditRiskAssessmentScreenController>();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user