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/string_extensions.dart ' ;
import ' package:test_sa/extensions/text_extensions.dart ' ;
import ' package:test_sa/extensions/widget_extensions.dart ' ;
import ' package:test_sa/helper/utils.dart ' ;
import ' package:test_sa/models/device/asset.dart ' ;
import ' package:test_sa/models/lookup.dart ' ;
import ' package:test_sa/models/new_models/traf_department.dart ' ;
import ' package:test_sa/models/new_models/users_based_on_search_model.dart ' ;
import ' package:test_sa/modules/cm_module/views/components/action_button/footer_action_button.dart ' ;
import ' package:test_sa/modules/traf_module/asset_auto_complete_field.dart ' ;
import ' package:test_sa/modules/traf_module/traf_request_detail_page.dart ' ;
import ' package:test_sa/modules/traf_module/update_traf_request_page.dart ' ;
import ' package:test_sa/modules/traf_module/users_auto_complete_field.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/multiple_item_drop_down_menu.dart ' ;
import ' package:test_sa/new_views/common_widgets/single_item_drop_down_menu.dart ' ;
import ' package:test_sa/providers/loading_list_notifier.dart ' ;
import ' package:test_sa/providers/lookups/department_lookup_provider.dart ' ;
import ' package:test_sa/providers/lookups/request_type_lookup_provider.dart ' ;
import ' package:test_sa/providers/lookups/yes_no_lookup_provider.dart ' ;
import ' package:test_sa/views/widgets/equipment/asset_picker.dart ' ;
import ' traf_request_model.dart ' ;
import ' traf_request_provider.dart ' ;
class CreateTRAFRequestPage extends StatefulWidget {
static const String id = " /create-TRAF " ;
CreateTRAFRequestPage ( { Key ? key } ) : super ( key: key ) ;
@ override
_CreateTRAFRequestPageState createState ( ) {
return _CreateTRAFRequestPageState ( ) ;
}
}
class _CreateTRAFRequestPageState extends State < CreateTRAFRequestPage > {
final GlobalKey < FormState > _formKey = GlobalKey < FormState > ( ) ;
bool _acknowledgement = false ;
Asset ? asset ;
Lookup ? requestType ;
Lookup ? isUsedSolelyOrShared ;
Lookup ? otherServicesEffects ;
Lookup ? useInCombination ;
TrafRequestDataModel ? trafRequest ;
List < Lookup > abc = [ ] ;
List < TrafDepartment > departments = [ ] ;
List < UsersBasedOnSearchModel > userBasedOnSearch = [ ] ;
FocusNode otherServicesEffectsNode = FocusNode ( ) ;
FocusNode useInCombinationNode = FocusNode ( ) ;
FocusNode departmentNode = FocusNode ( ) ;
@ override
void initState ( ) {
super . initState ( ) ;
trafRequest = TrafRequestDataModel ( id: 0 , attachments: [ ] , departments: [ ] , qty: 1 ) ;
resetProviders ( ) ;
}
void resetProviders ( ) {
Provider . of < RequestTypeLookupProvider > ( context , listen: false ) . reset ( ) ;
// Provider.of<YesNoLookupProvider>(context, listen: false).reset();
}
@ override
void dispose ( ) {
super . dispose ( ) ;
}
@ override
Widget build ( BuildContext context ) {
return Scaffold (
appBar: const DefaultAppBar ( title: " TRAF Request " ) ,
body: Form (
key: _formKey ,
child: Column (
children: [
ListView ( padding: const EdgeInsets . all ( 16 ) , children: [
Column (
crossAxisAlignment: CrossAxisAlignment . start ,
children: [
// SingleItemDropDownMenu<TaskType, TaskTypeProvider>(
// context: context,
// height: 56.toScreenHeight,
// title: context.translation.taskType,
// showShadow: false,
// backgroundColor: AppColor.fieldBgColor(context),
// showAsBottomSheet: true,
// initialValue: selectedType,
// onSelect: (type) {},
// ),
SingleItemDropDownMenu < Lookup , RequestTypeLookupProvider > (
context: context ,
showAsBottomSheet: true ,
backgroundColor: AppColor . neutral100 ,
showShadow: false ,
title: context . translation . requestType ,
initialValue: requestType ,
onSelect: ( value ) {
requestType = value ;
trafRequest ? . requestTypeId = value ? . id ;
if ( requestType ? . value = = 1 ) {
trafRequest ? . assetId = null ;
// trafRequest?.qty = 0;
} else if ( requestType ? . value = = 2 ) {
trafRequest ? . assetNDId = null ;
}
setState ( ( ) { } ) ;
} ,
) ,
if ( requestType ? . value = = 1 ) . . . [
12. height ,
AssetAutoCompleteField (
clearAfterPick: false ,
byName: true ,
initialValue: " " ,
onPick: ( asset ) {
trafRequest ? . assetNDId = asset . id ;
// model.partCatalogItem = PartCatalogItem(id: part.sparePart?.id, partNumber: part.sparePart?.partNo, partName: part.sparePart?.partName, oracleCode: part.sparePart?.oracleCode);
// setState(() {});
} ,
) ,
] ,
if ( requestType ? . value = = 2 ) . . . [
12. height ,
AssetPicker (
device: asset ,
editable: false ,
showLoading: false ,
borderColor: AppColor . black20 ,
backgroundColor: AppColor . white936 ,
onPick: ( asset ) async {
this . asset = asset ;
trafRequest ? . assetId = asset . id ? . toInt ( ) ;
// trafRequest?.qty = 1;
setState ( ( ) { } ) ;
// pendingAssetServiceRequest = null;
// _serviceRequest.device = asset;
// await checkAssetForPendingServiceRequest(asset.id!.toInt());
// if (pendingAssetServiceRequest != null && pendingAssetServiceRequest!.details!.isNotEmpty) {
// showPendingRequestBottomSheet();
// }
} ,
) ,
] ,
12. height ,
Text (
" Request Details " ,
style: AppTextStyles . bodyText . copyWith ( color: context . isDark ? AppColor . neutral30 : AppColor . neutral50 , fontWeight: FontWeight . w600 ) ,
) ,
12. height ,
AppTextFormField (
initialValue: " " ,
labelText: " How would the requested technology solve the current situation and/or serve the purpose? " ,
backgroundColor: AppColor . fieldBgColor ( context ) ,
labelStyle: AppTextStyles . textFieldLabelStyle . copyWith ( color: AppColor . textColor ( context ) ) ,
floatingLabelStyle: AppTextStyles . textFieldLabelStyle . copyWith ( color: AppColor . textColor ( context ) ) ,
showShadow: false ,
makeMultiLinesNull: true ,
onChange: ( value ) {
trafRequest ? . purposeAnswer = value ;
} ,
) ,
12. height ,
AppTextFormField (
initialValue: " " ,
labelText: " What is the current practice? " ,
backgroundColor: AppColor . fieldBgColor ( context ) ,
labelStyle: AppTextStyles . textFieldLabelStyle . copyWith ( color: AppColor . textColor ( context ) ) ,
showShadow: false ,
makeMultiLinesNull: true ,
onChange: ( value ) {
trafRequest ? . currentPractise = value ;
} ,
) ,
12. height ,
AppTextFormField (
initialValue: " " ,
makeMultiLinesNull: true ,
labelText: " Census Q1 " ,
backgroundColor: AppColor . fieldBgColor ( context ) ,
labelStyle: AppTextStyles . textFieldLabelStyle . copyWith ( color: AppColor . textColor ( context ) ) ,
showShadow: false ,
textInputType: TextInputType . number ,
onChange: ( value ) {
trafRequest ? . censusQ1 = int . tryParse ( value ) ;
} ,
) ,
12. height ,
AppTextFormField (
initialValue: " " ,
makeMultiLinesNull: true ,
labelText: " Census Q2 " ,
backgroundColor: AppColor . fieldBgColor ( context ) ,
labelStyle: AppTextStyles . textFieldLabelStyle . copyWith ( color: AppColor . textColor ( context ) ) ,
showShadow: false ,
textInputType: TextInputType . number ,
onChange: ( value ) {
trafRequest ? . censusQ2 = int . tryParse ( value ) ;
} ,
) ,
12. height ,
AppTextFormField (
initialValue: " " ,
makeMultiLinesNull: true ,
labelText: " Census Q3 " ,
backgroundColor: AppColor . fieldBgColor ( context ) ,
labelStyle: AppTextStyles . textFieldLabelStyle . copyWith ( color: AppColor . textColor ( context ) ) ,
showShadow: false ,
textInputType: TextInputType . number ,
onChange: ( value ) {
trafRequest ? . censusQ3 = int . tryParse ( value ) ;
} ,
) ,
12. height ,
AppTextFormField (
initialValue: " " ,
makeMultiLinesNull: true ,
labelText: " Census Q4 " ,
backgroundColor: AppColor . fieldBgColor ( context ) ,
labelStyle: AppTextStyles . textFieldLabelStyle . copyWith ( color: AppColor . textColor ( context ) ) ,
showShadow: false ,
textInputType: TextInputType . number ,
onChange: ( value ) {
trafRequest ? . censusQ4 = int . tryParse ( value ) ;
} ,
) ,
12. height ,
SearchUserAutoCompleteField (
clearAfterPick: true ,
byName: true ,
initialValue: " " ,
onPick: ( user ) {
userBasedOnSearch . add ( user ) ;
FocusScope . of ( context ) . unfocus ( ) ;
// model.partCatalogItem = PartCatalogItem(id: part.sparePart?.id, partNumber: part.sparePart?.partNo, partName: part.sparePart?.partName, oracleCode: part.sparePart?.oracleCode);
setState ( ( ) { } ) ;
} ,
) ,
if ( userBasedOnSearch . isNotEmpty ) . . . [
// 12.height,
ListView . separated (
shrinkWrap: true ,
physics: const NeverScrollableScrollPhysics ( ) ,
padding: const EdgeInsets . only ( left: 12 , right: 12 ) ,
itemBuilder: ( cxt , index ) = > Column (
crossAxisAlignment: CrossAxisAlignment . start ,
mainAxisSize: MainAxisSize . min ,
children: [
ListTile (
dense: true ,
contentPadding: EdgeInsets . zero ,
title: Text ( " Name: ${ userBasedOnSearch [ index ] . userName ? ? " " } " ) ,
subtitle: Text ( " Email: ${ userBasedOnSearch [ index ] . email ? ? " " } \n Phone: ${ userBasedOnSearch [ index ] . phoneNumber ? ? " " } " ) ,
trailing: const Icon ( Icons . delete_rounded , color: Color ( 0xffF63939 ) , size: 20 ) . onPress ( ( ) {
userBasedOnSearch . removeAt ( index ) ;
setState ( ( ) { } ) ;
} ) ,
) ,
] ,
) ,
separatorBuilder: ( cxt , index ) = > Divider ( thickness: 1 , height: 1 , color: context . isDark ? AppColor . neutral20 : AppColor . neutral30 ) ,
itemCount: userBasedOnSearch . length )
] ,
12. height ,
SingleItemDropDownMenu < Lookup , YesNoLookupProvider > (
context: context ,
showAsBottomSheet: true ,
backgroundColor: AppColor . neutral100 ,
showShadow: false ,
height: 80 ,
title: " Is the requesting department going to use the technology solely or shared with other departments? " ,
initialValue: isUsedSolelyOrShared ,
onSelect: ( value ) {
isUsedSolelyOrShared = value ;
trafRequest ? . usingSolelyOrSharedId = value ? . value ;
if ( isUsedSolelyOrShared ? . value ! = 1 ) {
departments = [ ] ;
trafRequest ? . trafDepartments = [ ] ;
Provider . of < DepartmentLookupProvider > ( context , listen: false ) . reset ( ) ;
FocusScope . of ( context ) . unfocus ( ) ;
} else {
departmentNode . requestFocus ( ) ;
}
setState ( ( ) { } ) ;
} ,
) ,
if ( isUsedSolelyOrShared ? . value = = 1 ) . . . [
12. height ,
Focus (
focusNode: departmentNode ,
child: MultipleItemDropDownMenu < TrafDepartment , DepartmentLookupProvider > (
context: context ,
showAsBottomSheet: true ,
backgroundColor: AppColor . neutral100 ,
showShadow: false ,
showCancel: true ,
requestById: context . userProvider . user ? . clientId ,
title: " Please specify departments and relations " ,
initialValue: departments ,
onSelect: ( value ) {
departments = value ? ? [ ] ;
trafRequest ? . trafDepartments = departments . map ( ( element ) = > Departments ( id: 0 , trafId: 0 , departmentId: element . id ! . toInt ( ) ) ) . toList ( ) ;
} ,
) ,
) ,
] ,
12. height ,
SingleItemDropDownMenu < Lookup , YesNoLookupProvider > (
context: context ,
showAsBottomSheet: true ,
backgroundColor: AppColor . neutral100 ,
showShadow: false ,
height: 80 ,
title: " Would other services be effected by acquiring the new equipment? " ,
initialValue: otherServicesEffects ,
onSelect: ( value ) {
otherServicesEffects = value ;
trafRequest ? . isEffectedId = value ? . value ;
if ( otherServicesEffects ? . value ! = 1 ) {
trafRequest ? . effectedServices = null ;
FocusScope . of ( context ) . unfocus ( ) ;
} else {
otherServicesEffectsNode . requestFocus ( ) ;
}
setState ( ( ) { } ) ;
} ,
) ,
if ( otherServicesEffects ? . value = = 1 ) . . . [
12. height ,
AppTextFormField (
initialValue: " " ,
// makeMultiLinesNull: true,
textInputType: TextInputType . multiline ,
alignLabelWithHint: true ,
node: otherServicesEffectsNode ,
labelText: " List down these services and stat how would it be effected " ,
backgroundColor: AppColor . fieldBgColor ( context ) ,
labelStyle: AppTextStyles . textFieldLabelStyle . copyWith ( color: AppColor . textColor ( context ) ) ,
showShadow: false ,
onChange: ( value ) {
trafRequest ? . effectedServices = value ;
} ,
) ,
] ,
12. height ,
SingleItemDropDownMenu < Lookup , YesNoLookupProvider > (
context: context ,
showAsBottomSheet: true ,
backgroundColor: AppColor . neutral100 ,
showShadow: false ,
height: 80 ,
title: " Is the equipment going to be used with combination of other equipment to accomplish a specific procedure? " ,
initialValue: useInCombination ,
onSelect: ( value ) {
useInCombination = value ;
trafRequest ? . isCombinationId = value ? . value ;
if ( useInCombination ? . value ! = 1 ) {
trafRequest ? . usedWithCombination = null ;
FocusScope . of ( context ) . unfocus ( ) ;
} else {
useInCombinationNode . requestFocus ( ) ;
}
setState ( ( ) { } ) ;
} ,
) ,
if ( useInCombination ? . value = = 1 ) . . . [
12. height ,
AppTextFormField (
initialValue: " " ,
textInputType: TextInputType . multiline ,
alignLabelWithHint: true ,
node: useInCombinationNode ,
labelText: " kindly describe in detail " ,
backgroundColor: AppColor . fieldBgColor ( context ) ,
labelStyle: AppTextStyles . textFieldLabelStyle . copyWith ( color: AppColor . textColor ( context ) ) ,
showShadow: false ,
onChange: ( value ) {
trafRequest ? . usedWithCombination = value ;
} ,
) ,
]
] ,
) . toShadowContainer ( context , padding: 12 , borderRadius: 20 ) ,
16. height ,
Row (
children: [
Checkbox (
value: _acknowledgement ,
visualDensity: const VisualDensity ( horizontal: - 4.0 , vertical: - 4.0 ) ,
activeColor: AppColor . blueStatus ( context ) ,
materialTapTargetSize: MaterialTapTargetSize . shrinkWrap ,
onChanged: ( value ) {
setState ( ( ) {
_acknowledgement = value ! ;
} ) ;
} ) ,
12. width ,
" I acknowledge the information filled above is correct " . addTranslation . bodyText ( context ) . custom ( color: context . isDark ? AppColor . primary50 : AppColor . neutral120 ) . expanded ,
] ,
) ,
] ) . expanded ,
FooterActionButton . footerContainer (
context: context ,
child: AppFilledButton (
buttonColor: AppColor . primary10 ,
label: context . translation . submitRequest ,
disableButton: ! _acknowledgement ,
onPressed: _verifyAndSubmit ,
// buttonColor: AppColor.primary10,
) ,
) ,
] ,
) ,
) ,
) ;
}
void _verifyAndSubmit ( ) async {
trafRequest ? . employeeId = context . userProvider . user ? . userID ;
trafRequest ? . siteId = context . userProvider . user ? . clientId ;
trafRequest ? . trafContacts = [ ] ;
trafRequest ? . trafContacts = userBasedOnSearch . map ( ( item ) = > TrafContacts ( id: 0 , trafId: 0 , name: item . userName , userId: item . userId ) ) . toList ( ) ;
Utils . showLoading ( context ) ;
await Provider . of < TrafRequestProvider > ( context , listen: false ) . addTraf ( trafRequest ! . toJson ( ) ) ;
Utils . hideLoading ( context ) ;
Navigator . pop ( context ) ;
}
}