incident module dev -1
parent
5391cc324c
commit
58ee00b00a
@ -0,0 +1,572 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:test_sa/controllers/validator/validator.dart';
|
||||
import 'package:test_sa/extensions/context_extension.dart';
|
||||
import 'package:test_sa/extensions/int_extensions.dart';
|
||||
import 'package:test_sa/extensions/string_extensions.dart';
|
||||
import 'package:test_sa/extensions/text_extensions.dart';
|
||||
import 'package:test_sa/extensions/widget_extensions.dart';
|
||||
import 'package:test_sa/models/device/asset.dart';
|
||||
import 'package:test_sa/models/generic_attachment_model.dart';
|
||||
import 'package:test_sa/models/lookup.dart';
|
||||
import 'package:test_sa/models/new_models/building.dart';
|
||||
import 'package:test_sa/models/new_models/floor.dart';
|
||||
import 'package:test_sa/models/new_models/site.dart';
|
||||
import 'package:test_sa/modules/cm_module/views/components/action_button/footer_action_button.dart';
|
||||
import 'package:test_sa/modules/incident_module/incident_lookup_provider.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/app_text_form_field.dart';
|
||||
import 'package:test_sa/new_views/common_widgets/default_app_bar.dart';
|
||||
import 'package:test_sa/new_views/common_widgets/single_item_drop_down_menu.dart';
|
||||
import 'package:test_sa/providers/gas_request_providers/site_provider.dart';
|
||||
import 'package:test_sa/providers/loading_list_notifier.dart';
|
||||
import 'package:test_sa/providers/lookups/yes_no_lookup_provider.dart';
|
||||
import 'package:test_sa/views/widgets/equipment/asset_picker.dart';
|
||||
import 'package:test_sa/views/widgets/images/multi_image_picker.dart';
|
||||
|
||||
import '../../models/new_models/department.dart';
|
||||
|
||||
class CreateIncidentRequestPage extends StatefulWidget {
|
||||
static const String id = "/create-incident";
|
||||
|
||||
CreateIncidentRequestPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_CreateIncidentRequestPageState createState() {
|
||||
return _CreateIncidentRequestPageState();
|
||||
}
|
||||
}
|
||||
|
||||
class _CreateIncidentRequestPageState extends State<CreateIncidentRequestPage> {
|
||||
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
||||
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
||||
final List<GenericAttachmentModel> attachments = [];
|
||||
|
||||
Site? _selectedSite;
|
||||
Building? _selectedBuilding;
|
||||
Floor? _selectedFloor;
|
||||
Department? _selectedDepartment;
|
||||
|
||||
Asset? device;
|
||||
|
||||
Lookup? incidentType;
|
||||
Lookup? ovrSystem;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
key: _scaffoldKey,
|
||||
appBar: DefaultAppBar(title: 'Incident'.addTranslation),
|
||||
body: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
children: [
|
||||
SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
...incidentInfoSection(),
|
||||
if (incidentType?.value == 1) ...[
|
||||
16.height,
|
||||
AssetPicker(
|
||||
device: device,
|
||||
showLoading: false,
|
||||
borderColor: AppColor.black20,
|
||||
onPick: (asset) async {
|
||||
device = asset;
|
||||
setState(() {});
|
||||
},
|
||||
)
|
||||
],
|
||||
if (incidentType?.value != 1) ...[
|
||||
16.height,
|
||||
...siteSection(),
|
||||
],
|
||||
16.height,
|
||||
...vendorDetailsSection(),
|
||||
16.height,
|
||||
AttachmentPicker(
|
||||
label: context.translation.attachments,
|
||||
attachment: attachments,
|
||||
buttonColor: AppColor.black10,
|
||||
onlyImages: false,
|
||||
showAsListView: true,
|
||||
buttonIcon: 'image-plus'.toSvgAsset(color: context.isDark ? AppColor.primary10 : AppColor.neutral120),
|
||||
onChange: (attachments) {
|
||||
attachments = attachments;
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
],
|
||||
).toShadowContainer(context, borderRadius: 20),
|
||||
).expanded,
|
||||
FooterActionButton.footerContainer(
|
||||
context: context,
|
||||
child: AppFilledButton(
|
||||
buttonColor: AppColor.primary10,
|
||||
label: context.translation.submitRequest,
|
||||
onPressed: _submit,
|
||||
// buttonColor: AppColor.primary10,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> siteSection() {
|
||||
return [
|
||||
'Site Details'.addTranslation.bodyText(context).custom(color: AppColor.black10),
|
||||
8.height,
|
||||
SingleItemDropDownMenu<Site, SiteProvider>(
|
||||
context: context,
|
||||
title: context.translation.site,
|
||||
initialValue: _selectedSite,
|
||||
showShadow: false,
|
||||
validator: (value) {
|
||||
if (value == null) return "Please select a site";
|
||||
return null;
|
||||
},
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
showAsBottomSheet: true,
|
||||
onSelect: (value) {
|
||||
_selectedSite = value;
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
8.height,
|
||||
SingleItemDropDownMenu<Building, NullableLoadingProvider>(
|
||||
context: context,
|
||||
title: context.translation.building,
|
||||
initialValue: _selectedBuilding,
|
||||
showShadow: false,
|
||||
showAsBottomSheet: true,
|
||||
validator: (value) {
|
||||
if (value == null) return "Please select a building";
|
||||
return null;
|
||||
},
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
enabled: _selectedSite?.buildings?.isNotEmpty ?? false,
|
||||
staticData: _selectedSite?.buildings ?? [],
|
||||
onSelect: (value) {
|
||||
_selectedBuilding = value;
|
||||
_selectedFloor = null;
|
||||
_selectedDepartment = null;
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
8.height,
|
||||
SingleItemDropDownMenu<Floor, NullableLoadingProvider>(
|
||||
context: context,
|
||||
title: context.translation.floor,
|
||||
showShadow: false,
|
||||
showAsBottomSheet: true,
|
||||
initialValue: _selectedFloor,
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
enabled: _selectedBuilding?.floors?.isNotEmpty ?? false,
|
||||
staticData: _selectedBuilding?.floors ?? [],
|
||||
validator: (value) {
|
||||
if (value == null) return "Please select a floor";
|
||||
return null;
|
||||
},
|
||||
onSelect: (value) {
|
||||
_selectedFloor = value;
|
||||
_selectedDepartment = null;
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
8.height,
|
||||
SingleItemDropDownMenu<Department, NullableLoadingProvider>(
|
||||
context: context,
|
||||
title: context.translation.department,
|
||||
showShadow: false,
|
||||
showAsBottomSheet: true,
|
||||
initialValue: _selectedDepartment,
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
enabled: _selectedFloor?.departments?.isNotEmpty ?? false,
|
||||
staticData: _selectedFloor?.departments ?? [],
|
||||
validator: (value) {
|
||||
if (value == null) return "Please select a department";
|
||||
return null;
|
||||
},
|
||||
onSelect: (value) {
|
||||
_selectedDepartment = value;
|
||||
// _demoFormModel.room = null;
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
// List<Widget> siteSection() {
|
||||
// return [
|
||||
// 'Site Details'.addTranslation.bodyText(context).custom(color: AppColor.black10),
|
||||
// 8.height,
|
||||
// SingleItemDropDownMenu<Site, SiteProvider>(
|
||||
// context: context,
|
||||
// title: context.translation.site,
|
||||
// initialValue: _demoFormModel.site,
|
||||
// showShadow: false,
|
||||
// validator: (value) {
|
||||
// if (value == null) return "Please select a site";
|
||||
// return null;
|
||||
// },
|
||||
// backgroundColor: AppColor.fieldBgColor(context),
|
||||
// showAsBottomSheet: true,
|
||||
// onSelect: (value) {
|
||||
// _demoFormModel.site = value;
|
||||
// setState(() {});
|
||||
// },
|
||||
// ),
|
||||
// 8.height,
|
||||
// SingleItemDropDownMenu<MedicalDepartmentModel, MedicalDepartmentProvider>(
|
||||
// context: context,
|
||||
// title: context.translation.department,
|
||||
// showShadow: false,
|
||||
// validator: (value) {
|
||||
// if (value == null) return "Please select a department";
|
||||
// return null;
|
||||
// },
|
||||
// showAsBottomSheet: true,
|
||||
// initialValue: _demoFormModel.department,
|
||||
// requestById: context.userProvider.user?.clientId,
|
||||
// backgroundColor: AppColor.fieldBgColor(context),
|
||||
// onSelect: (value) {
|
||||
// _demoFormModel.department = value;
|
||||
// setState(() {});
|
||||
// },
|
||||
// ),
|
||||
// ];
|
||||
// }
|
||||
|
||||
List<Widget> incidentInfoSection() {
|
||||
return [
|
||||
"Incident Details".bodyText(context).custom(color: AppColor.black10),
|
||||
8.height,
|
||||
SingleItemDropDownMenu<Lookup, IncidentTypeLookupProvider>(
|
||||
context: context,
|
||||
height: 56.toScreenHeight,
|
||||
title: "Incident Type",
|
||||
initialValue: incidentType,
|
||||
showShadow: false,
|
||||
validator: (value) {
|
||||
if (value == null) return "Mandatory";
|
||||
return null;
|
||||
},
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
showAsBottomSheet: true,
|
||||
onSelect: (value) {
|
||||
incidentType = value;
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
8.height,
|
||||
SingleItemDropDownMenu<Lookup, YesNoLookupProvider>(
|
||||
context: context,
|
||||
height: 56.toScreenHeight,
|
||||
title: "Is there any existing OVR System?",
|
||||
initialValue: ovrSystem,
|
||||
showShadow: false,
|
||||
validator: (value) {
|
||||
if (value == null) return "Mandatory";
|
||||
return null;
|
||||
},
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
showAsBottomSheet: true,
|
||||
onSelect: (value) {
|
||||
ovrSystem = value;
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
if (ovrSystem?.value == 1) ...[
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
initialValue: "",
|
||||
labelText: "OVR Ticket Number",
|
||||
validator: (value) {
|
||||
if ((value ?? "").isEmpty) return "Mandatory";
|
||||
return null;
|
||||
},
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
|
||||
showShadow: false,
|
||||
textInputType: TextInputType.name,
|
||||
textInputAction: TextInputAction.next,
|
||||
onChange: (value) {
|
||||
// _demoFormModel.vendorRepresentativeName = value;
|
||||
},
|
||||
),
|
||||
],
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
initialValue: "",
|
||||
labelText: "Name",
|
||||
validator: (value) {
|
||||
if ((value ?? "").isEmpty) return "Mandatory";
|
||||
return null;
|
||||
},
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
|
||||
showShadow: false,
|
||||
textInputType: TextInputType.text,
|
||||
onChange: (value) {
|
||||
// _demoFormModel.docName = value;
|
||||
},
|
||||
),
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
initialValue: "",
|
||||
labelText: "Contact Number",
|
||||
validator: (value) {
|
||||
if ((value ?? "").isEmpty) return "Mandatory";
|
||||
return null;
|
||||
},
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
|
||||
showShadow: false,
|
||||
textInputType: TextInputType.phone,
|
||||
onChange: (value) {
|
||||
// _demoFormModel.docNumber = value;
|
||||
},
|
||||
),
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
initialValue: "",
|
||||
labelText: "Email",
|
||||
validator: (value) {
|
||||
if ((value ?? "").isEmpty) {
|
||||
return "Mandatory";
|
||||
} else {
|
||||
return Validator.isEmail(value!) ? null : context.translation.emailValidateMessage;
|
||||
}
|
||||
},
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
|
||||
showShadow: false,
|
||||
textInputType: TextInputType.emailAddress,
|
||||
onChange: (value) {
|
||||
// _demoFormModel.docEmail = value;
|
||||
},
|
||||
),
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
labelText: "Item Description",
|
||||
validator: (value) {
|
||||
if ((value ?? "").isEmpty) return "Mandatory";
|
||||
return null;
|
||||
},
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
|
||||
floatingLabelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
|
||||
showShadow: false,
|
||||
textInputType: TextInputType.text,
|
||||
textInputAction: TextInputAction.next,
|
||||
onChange: (value) {
|
||||
// _demoFormModel.itemDescription = value;
|
||||
},
|
||||
),
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
labelText: "Request Description",
|
||||
// validator: (value) {
|
||||
// if ((value ?? "").isEmpty) return "Mandatory";
|
||||
// return null;
|
||||
// },
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
|
||||
floatingLabelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
|
||||
showShadow: false,
|
||||
textInputType: TextInputType.text,
|
||||
textInputAction: TextInputAction.next,
|
||||
onChange: (value) {
|
||||
// _demoFormModel.requestDescription = value;
|
||||
},
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
List<Widget> assetSection() {
|
||||
return [
|
||||
'Asset Details'.addTranslation.bodyText(context).custom(color: AppColor.black10),
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
labelText: "Model",
|
||||
validator: (value) {
|
||||
if ((value ?? "").isEmpty) return "Mandatory";
|
||||
return null;
|
||||
},
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
|
||||
floatingLabelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
|
||||
showShadow: false,
|
||||
textInputType: TextInputType.text,
|
||||
textInputAction: TextInputAction.next,
|
||||
onChange: (value) {
|
||||
// _demoFormModel.model = value;
|
||||
},
|
||||
),
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
labelText: "Manufacturer",
|
||||
validator: (value) {
|
||||
if ((value ?? "").isEmpty) return "Mandatory";
|
||||
return null;
|
||||
},
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
|
||||
floatingLabelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
|
||||
showShadow: false,
|
||||
textInputType: TextInputType.text,
|
||||
textInputAction: TextInputAction.next,
|
||||
onChange: (value) {
|
||||
// _demoFormModel.manufacturer = value;
|
||||
},
|
||||
),
|
||||
// 8.height,
|
||||
// SingleItemDropDownMenu<Lookup, DemoPeriodLookupProvider>(
|
||||
// context: context,
|
||||
// height: 56.toScreenHeight,
|
||||
// title: "Demo Period",
|
||||
// initialValue: demoPeriodLookup,
|
||||
// showShadow: false,
|
||||
// validator: (value) {
|
||||
// if (value == null) return "Mandatory";
|
||||
// return null;
|
||||
// },
|
||||
// backgroundColor: AppColor.fieldBgColor(context),
|
||||
// showAsBottomSheet: true,
|
||||
// onSelect: (value) {
|
||||
// demoPeriodLookup = value;
|
||||
// setState(() {});
|
||||
// },
|
||||
// ),
|
||||
];
|
||||
}
|
||||
|
||||
List<Widget> vendorDetailsSection() {
|
||||
return [
|
||||
'Vendor Details'.addTranslation.bodyText(context).custom(color: AppColor.black10),
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
initialValue: "",
|
||||
labelText: "Incident Title",
|
||||
validator: (value) {
|
||||
if ((value ?? "").isEmpty) return "Mandatory";
|
||||
return null;
|
||||
},
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
|
||||
showShadow: false,
|
||||
textInputType: TextInputType.name,
|
||||
textInputAction: TextInputAction.next,
|
||||
onChange: (value) {
|
||||
// _demoFormModel.vendorName = value;
|
||||
},
|
||||
),
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
initialValue: "",
|
||||
labelText: "Incident Description",
|
||||
validator: (value) {
|
||||
if ((value ?? "").isEmpty) return "Mandatory";
|
||||
return null;
|
||||
},
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
|
||||
showShadow: false,
|
||||
textInputType: TextInputType.name,
|
||||
textInputAction: TextInputAction.next,
|
||||
onChange: (value) {
|
||||
// _demoFormModel.vendorRepresentativeName = value;
|
||||
},
|
||||
),
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
initialValue: "",
|
||||
labelText: "Contact Number",
|
||||
validator: (value) {
|
||||
if ((value ?? "").isEmpty) return "Mandatory";
|
||||
return null;
|
||||
},
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
|
||||
showShadow: false,
|
||||
textInputType: TextInputType.phone,
|
||||
textInputAction: TextInputAction.next,
|
||||
onChange: (value) {
|
||||
// _demoFormModel.vendorNumber = value;
|
||||
},
|
||||
),
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
initialValue: "",
|
||||
labelText: "Email",
|
||||
validator: (value) {
|
||||
if ((value ?? "").isEmpty) {
|
||||
return "Mandatory";
|
||||
} else {
|
||||
return Validator.isEmail(value!) ? null : context.translation.emailValidateMessage;
|
||||
}
|
||||
},
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
|
||||
showShadow: false,
|
||||
textInputType: TextInputType.emailAddress,
|
||||
textInputAction: TextInputAction.next,
|
||||
onChange: (value) {
|
||||
// _demoFormModel.vendorEmail = value;
|
||||
},
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
Future<void> _submit() async {
|
||||
FocusScope.of(context).unfocus();
|
||||
if (_formKey.currentState!.validate()) {
|
||||
_formKey.currentState!.save();
|
||||
|
||||
// _demoFormModel.demoAttachment = [];
|
||||
// for (var item in attachments) {
|
||||
// String fileName = CMRequestUtils.isLocalUrl(item.name ?? '') ? ("${item.name ?? ''.split("/").last}|${base64Encode(File(item.name ?? '').readAsBytesSync())}") : item.name ?? '';
|
||||
// _demoFormModel.demoAttachment?.add(DemoAttachments(id: 0, attachmentName: fileName, demoRequestId: 0));
|
||||
// }
|
||||
// Utils.showLoading(context);
|
||||
// LoanProvider loanProvider = Provider.of<LoanProvider>(context, listen: false);
|
||||
// Map<String, dynamic> body = _demoFormModel.toJson();
|
||||
// body["id"] = 0;
|
||||
// // body["LoanTypeId"] = 0;
|
||||
// // body["requestorUserID"] = context.userProvider.user!.userID;
|
||||
//
|
||||
// bool isSuccess = await loanProvider.addLoanRequest(body);
|
||||
// Utils.hideLoading(context);
|
||||
// if (isSuccess) {
|
||||
// Navigator.pop(context);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,158 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart';
|
||||
import 'package:test_sa/providers/loading_list_notifier.dart';
|
||||
|
||||
import '../../controllers/api_routes/api_manager.dart';
|
||||
import '../../controllers/api_routes/urls.dart';
|
||||
import '../../models/lookup.dart';
|
||||
|
||||
class IncidentStatusLookupProvider extends LoadingListNotifier<Lookup> {
|
||||
@override
|
||||
Future getData({int? id}) async {
|
||||
if (loading == true) return -2;
|
||||
loading = true;
|
||||
notifyListeners();
|
||||
try {
|
||||
Response response = await ApiManager.instance.get(URLs.incidentStatusLookup);
|
||||
stateCode = response.statusCode;
|
||||
if (response.statusCode >= 200 && response.statusCode < 300) {
|
||||
List categoriesListJson = json.decode(response.body)["data"];
|
||||
items = categoriesListJson.map((item) => Lookup.fromJson(item)).toList();
|
||||
}
|
||||
loading = false;
|
||||
notifyListeners();
|
||||
return response.statusCode;
|
||||
} catch (error) {
|
||||
loading = false;
|
||||
stateCode = -1;
|
||||
notifyListeners();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class IncidentTypeLookupProvider extends LoadingListNotifier<Lookup> {
|
||||
@override
|
||||
Future getData({int? id}) async {
|
||||
if (loading == true) return -2;
|
||||
loading = true;
|
||||
notifyListeners();
|
||||
try {
|
||||
Response response = await ApiManager.instance.get(URLs.incidentTypeLookup);
|
||||
stateCode = response.statusCode;
|
||||
if (response.statusCode >= 200 && response.statusCode < 300) {
|
||||
List categoriesListJson = json.decode(response.body)["data"];
|
||||
items = categoriesListJson.map((item) => Lookup.fromJson(item)).toList();
|
||||
}
|
||||
loading = false;
|
||||
notifyListeners();
|
||||
return response.statusCode;
|
||||
} catch (error) {
|
||||
loading = false;
|
||||
stateCode = -1;
|
||||
notifyListeners();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class IncidentRootCauseLookupProvider extends LoadingListNotifier<Lookup> {
|
||||
@override
|
||||
Future getData({int? id}) async {
|
||||
if (loading == true) return -2;
|
||||
loading = true;
|
||||
notifyListeners();
|
||||
try {
|
||||
Response response = await ApiManager.instance.get(URLs.incidentRootCauseLookup);
|
||||
stateCode = response.statusCode;
|
||||
if (response.statusCode >= 200 && response.statusCode < 300) {
|
||||
List categoriesListJson = json.decode(response.body)["data"];
|
||||
items = categoriesListJson.map((item) => Lookup.fromJson(item)).toList();
|
||||
}
|
||||
loading = false;
|
||||
notifyListeners();
|
||||
return response.statusCode;
|
||||
} catch (error) {
|
||||
loading = false;
|
||||
stateCode = -1;
|
||||
notifyListeners();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class IncidentPersonInvolvedLookupProvider extends LoadingListNotifier<Lookup> {
|
||||
@override
|
||||
Future getData({int? id}) async {
|
||||
if (loading == true) return -2;
|
||||
loading = true;
|
||||
notifyListeners();
|
||||
try {
|
||||
Response response = await ApiManager.instance.get(URLs.incidentPersonInvolvedLookup);
|
||||
stateCode = response.statusCode;
|
||||
if (response.statusCode >= 200 && response.statusCode < 300) {
|
||||
List categoriesListJson = json.decode(response.body)["data"];
|
||||
items = categoriesListJson.map((item) => Lookup.fromJson(item)).toList();
|
||||
}
|
||||
loading = false;
|
||||
notifyListeners();
|
||||
return response.statusCode;
|
||||
} catch (error) {
|
||||
loading = false;
|
||||
stateCode = -1;
|
||||
notifyListeners();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ClinicalNonClinicalLookupProvider extends LoadingListNotifier<Lookup> {
|
||||
@override
|
||||
Future getData({int? id}) async {
|
||||
if (loading == true) return -2;
|
||||
loading = true;
|
||||
notifyListeners();
|
||||
try {
|
||||
Response response = await ApiManager.instance.get(URLs.clinicalNonClinicalLookup);
|
||||
stateCode = response.statusCode;
|
||||
if (response.statusCode >= 200 && response.statusCode < 300) {
|
||||
List categoriesListJson = json.decode(response.body)["data"];
|
||||
items = categoriesListJson.map((item) => Lookup.fromJson(item)).toList();
|
||||
}
|
||||
loading = false;
|
||||
notifyListeners();
|
||||
return response.statusCode;
|
||||
} catch (error) {
|
||||
loading = false;
|
||||
stateCode = -1;
|
||||
notifyListeners();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class GenderLookupProvider extends LoadingListNotifier<Lookup> {
|
||||
@override
|
||||
Future getData({int? id}) async {
|
||||
if (loading == true) return -2;
|
||||
loading = true;
|
||||
notifyListeners();
|
||||
try {
|
||||
Response response = await ApiManager.instance.get(URLs.genderLookup);
|
||||
stateCode = response.statusCode;
|
||||
if (response.statusCode >= 200 && response.statusCode < 300) {
|
||||
List categoriesListJson = json.decode(response.body)["data"];
|
||||
items = categoriesListJson.map((item) => Lookup.fromJson(item)).toList();
|
||||
}
|
||||
loading = false;
|
||||
notifyListeners();
|
||||
return response.statusCode;
|
||||
} catch (error) {
|
||||
loading = false;
|
||||
stateCode = -1;
|
||||
notifyListeners();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart';
|
||||
import 'package:test_sa/providers/loading_list_notifier.dart';
|
||||
|
||||
import '../../controllers/api_routes/api_manager.dart';
|
||||
import '../../controllers/api_routes/urls.dart';
|
||||
import '../../models/lookup.dart';
|
||||
|
||||
class DemoPeriodLookupProvider extends LoadingListNotifier<Lookup> {
|
||||
@override
|
||||
Future getData({int? id}) async {
|
||||
if (loading == true) return -2;
|
||||
loading = true;
|
||||
notifyListeners();
|
||||
try {
|
||||
Response response = await ApiManager.instance.get(URLs.incidentTypeLookup);
|
||||
stateCode = response.statusCode;
|
||||
if (response.statusCode >= 200 && response.statusCode < 300) {
|
||||
List categoriesListJson = json.decode(response.body)["data"];
|
||||
items = categoriesListJson.map((item) => Lookup.fromJson(item)).toList();
|
||||
}
|
||||
loading = false;
|
||||
notifyListeners();
|
||||
return response.statusCode;
|
||||
} catch (error) {
|
||||
loading = false;
|
||||
stateCode = -1;
|
||||
notifyListeners();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue