@ -2,16 +2,16 @@ import 'dart:convert';
import ' dart:io ' ;
import ' package:flutter/material.dart ' ;
import ' package:flutter/rendering.dart ' ;
import ' package:fluttertoast/fluttertoast.dart ' ;
import ' package:provider/provider.dart ' ;
import ' ../../../../../api/user_api_client.dart ' ;
import ' ../../../../../controllers/http_status_manger/http_status_manger.dart ' ;
import ' ../../../../../controllers/localization/localization.dart ' ;
import ' ../../../../../controllers/providers/api/service_requests_provider.dart ' ;
import ' ../../../../../controllers/providers/api/status_drop_down/report/service_report_last_calls_provider.dart ' ;
import ' ../../../../../controllers/providers/api/user_provider.dart ' ;
import ' ../../../../../controllers/providers/settings/setting_provider.dart ' ;
import ' ../../../../../controllers/providers/user_provider.dart ' ;
import ' ../../../../../controllers/validator/validator.dart ' ;
import ' ../../../../../models/part.dart ' ;
import ' ../../../../../models/service_report.dart ' ;
@ -48,8 +48,6 @@ class EditServiceReport extends StatefulWidget {
}
class _EditServiceReportState extends State < EditServiceReport > with TickerProviderStateMixin {
late UserProvider _userProvider ;
late SettingProvider _settingProvider ;
late ServiceRequestsProvider _serviceRequestsProvider ;
@ -77,6 +75,7 @@ class _EditServiceReportState extends State<EditServiceReport> with TickerProvid
_workPreformedController . dispose ( ) ;
super . dispose ( ) ;
}
@ override
Widget build ( BuildContext context ) {
_userProvider = Provider . of < UserProvider > ( context ) ;
@ -98,43 +97,46 @@ class _EditServiceReportState extends State<EditServiceReport> with TickerProvid
ListView (
children: [
/ / AppNameBar ( ) ,
const SizedBox ( height: 16 , ) ,
const SizedBox (
height: 16 ,
) ,
Center (
child: Padding (
padding: const EdgeInsets . all ( 8.0 ) ,
child: Text (
_subtitle . editServiceReport ,
style: Theme . of ( context ) . textTheme . headline5 ? . copyWith (
color: AColors . cyan ,
fontSize: 28 ,
fontWeight: FontWeight . bold
) ,
style: Theme . of ( context ) . textTheme . headline5 ? . copyWith ( color: AColors . cyan , fontSize: 28 , fontWeight: FontWeight . bold ) ,
) ,
) ,
) ,
Container (
padding: const EdgeInsets . symmetric ( horizontal: 16 ) ,
margin: const EdgeInsets . symmetric ( horizontal: 16 , vertical: 16 ) ,
decoration: BoxDecoration (
color: AColors . grey ,
borderRadius: BorderRadius . circular ( AppStyle . getBorderRadius ( context ) ) ,
boxShadow: [
decoration: BoxDecoration ( color: AColors . grey , borderRadius: BorderRadius . circular ( AppStyle . getBorderRadius ( context ) ) , boxShadow: [
BoxShadow (
color: AColors . grey ,
offset: Offset ( 0 , - 1 ) ,
)
]
) ,
] ) ,
child: Column (
crossAxisAlignment: CrossAxisAlignment . start ,
children: [
const SizedBox ( height: 8 , ) ,
const SizedBox (
height: 8 ,
) ,
Wrap (
spacing: 10 ,
children: [
ASubTitle ( " ${ _subtitle . callId } : ${ widget . request . requestCode } " , font: 14 , ) ,
widget . request . deviceSerialNumber = = null ? const SizedBox ( ) :
ASubTitle ( " ${ _subtitle . deviceSN } : ${ widget . request . deviceSerialNumber } " , font: 14 , ) ,
ASubTitle (
" ${ _subtitle . callId } : ${ widget . request . requestCode } " ,
font: 14 ,
) ,
widget . request . deviceSerialNumber = = null
? const SizedBox ( )
: ASubTitle (
" ${ _subtitle . deviceSN } : ${ widget . request . deviceSerialNumber } " ,
font: 14 ,
) ,
Text (
" ${ _subtitle . customer } : ${ widget . request . hospitalName } " ,
style: Theme . of ( context ) . textTheme . subtitle1 ? . copyWith (
@ -143,7 +145,6 @@ class _EditServiceReportState extends State<EditServiceReport> with TickerProvid
) ,
textScaleFactor: AppStyle . getScaleFactor ( context ) ,
)
] ,
) ,
const Divider ( ) ,
@ -157,10 +158,15 @@ class _EditServiceReportState extends State<EditServiceReport> with TickerProvid
crossAxisAlignment: CrossAxisAlignment . start ,
children: [
ASubTitle ( _subtitle . reportType ) ,
_validate & & _serviceReport . type = = null ?
ASubTitle ( _subtitle . requiredWord , color: Colors . red , ) :
const SizedBox . shrink ( ) ,
const SizedBox ( height: 4 , ) ,
_validate & & _serviceReport . type = = null
? ASubTitle (
_subtitle . requiredWord ,
color: Colors . red ,
)
: const SizedBox . shrink ( ) ,
const SizedBox (
height: 4 ,
) ,
ServiceReportTypeMenu (
initialValue: _serviceReport . type ,
onSelect: ( status ) {
@ -170,16 +176,21 @@ class _EditServiceReportState extends State<EditServiceReport> with TickerProvid
] ,
) ,
) ,
const SizedBox ( width: 8 , ) ,
const SizedBox (
width: 8 ,
) ,
/ / visit date
Expanded (
child: Column (
crossAxisAlignment: CrossAxisAlignment . start ,
children: [
ASubTitle ( _subtitle . visitDate ) ,
_validate & & _serviceReport . visitDate = = null ?
ASubTitle ( _subtitle . requiredWord , color: Colors . red , ) :
const SizedBox . shrink ( ) ,
_validate & & _serviceReport . visitDate = = null
? ASubTitle (
_subtitle . requiredWord ,
color: Colors . red ,
)
: const SizedBox . shrink ( ) ,
Row (
children: [
Expanded (
@ -198,10 +209,11 @@ class _EditServiceReportState extends State<EditServiceReport> with TickerProvid
] ,
) ,
) ,
] ,
) ,
const SizedBox ( height: 8 , ) ,
const SizedBox (
height: 8 ,
) ,
/ / device sn
Visibility (
visible: true , / / widget . report . device = = null ,
@ -209,9 +221,12 @@ class _EditServiceReportState extends State<EditServiceReport> with TickerProvid
crossAxisAlignment: CrossAxisAlignment . start ,
children: [
ASubTitle ( _subtitle . deviceSN ) ,
_validate & & _serviceReport . device ? . id = = null ?
ASubTitle ( _subtitle . requiredWord , color: Colors . red , ) :
const SizedBox . shrink ( ) ,
_validate & & _serviceReport . device ? . id = = null
? ASubTitle (
_subtitle . requiredWord ,
color: Colors . red ,
)
: const SizedBox . shrink ( ) ,
AutoCompleteDeviceField (
hospitalId: widget . request . hospitalId ,
initialValue: _serviceReport . device ! ,
@ -219,23 +234,34 @@ class _EditServiceReportState extends State<EditServiceReport> with TickerProvid
_serviceReport . device ? . id = id ;
} ,
) ,
const SizedBox ( height: 8 , ) ,
const SizedBox (
height: 8 ,
) ,
] ,
) ,
) ,
const SizedBox ( height: 8 , ) ,
const SizedBox (
height: 8 ,
) ,
ASubTitle ( _subtitle . serviceType ) ,
_validate & & _serviceReport . serviceType = = null ?
ASubTitle ( _subtitle . requiredWord , color: Colors . red , ) :
const SizedBox . shrink ( ) ,
const SizedBox ( height: 4 , ) ,
_validate & & _serviceReport . serviceType = = null
? ASubTitle (
_subtitle . requiredWord ,
color: Colors . red ,
)
: const SizedBox . shrink ( ) ,
const SizedBox (
height: 4 ,
) ,
ServiceStatusMenu (
initialValue: _serviceReport . serviceType ,
onSelect: ( status ) {
_serviceReport . serviceType = status ;
} ,
) ,
const SizedBox ( height: 8 , ) ,
const SizedBox (
height: 8 ,
) ,
/ / Report status and Service Type
Row (
children: [
@ -245,10 +271,15 @@ class _EditServiceReportState extends State<EditServiceReport> with TickerProvid
crossAxisAlignment: CrossAxisAlignment . start ,
children: [
ASubTitle ( _subtitle . reportStatus ) ,
_validate & & _serviceReport . status = = null ?
ASubTitle ( _subtitle . requiredWord , color: Colors . red , ) :
const SizedBox . shrink ( ) ,
const SizedBox ( height: 4 , ) ,
_validate & & _serviceReport . status = = null
? ASubTitle (
_subtitle . requiredWord ,
color: Colors . red ,
)
: const SizedBox . shrink ( ) ,
const SizedBox (
height: 4 ,
) ,
ServiceReportStatusMenu (
report: _serviceReport ,
onSelect: ( status ) {
@ -258,25 +289,31 @@ class _EditServiceReportState extends State<EditServiceReport> with TickerProvid
] ,
) ,
) ,
const SizedBox ( width: 8 , ) ,
const SizedBox (
width: 8 ,
) ,
Provider . of < ServiceReportLastCallsProvider > ( context ) . isLoading = = null
? const SizedBox . shrink ( ) :
? const SizedBox . shrink ( )
:
/ / Call ' s last Situation
Expanded (
child: Column (
crossAxisAlignment: CrossAxisAlignment . start ,
children: [
ASubTitle ( _subtitle . callLastSituation ) ,
_validate & & _serviceReport . callLastSituation = = null ?
ASubTitle ( _subtitle . requiredWord , color: Colors . red , ) :
const SizedBox . shrink ( ) ,
const SizedBox ( height: 4 , ) ,
_validate & & _serviceReport . callLastSituation = = null
? ASubTitle (
_subtitle . requiredWord ,
color: Colors . red ,
)
: const SizedBox . shrink ( ) ,
const SizedBox (
height: 4 ,
) ,
ServiceReportLastCallsMenu (
report: _serviceReport ,
onSelect: ( status ) {
if ( status ? . id = = 12
| | _serviceReport . callLastSituation ? . id = = 12 ) {
if ( status ? . id = = 12 | | _serviceReport . callLastSituation ? . id = = 12 ) {
_serviceReport . callLastSituation = status ;
setState ( ( ) { } ) ;
} else {
@ -289,24 +326,27 @@ class _EditServiceReportState extends State<EditServiceReport> with TickerProvid
) ,
] ,
) ,
const SizedBox ( height: 8 , ) ,
const SizedBox (
height: 8 ,
) ,
/ / invoice number & code
_serviceReport . callLastSituation ? . id ! = 12 ? const SizedBox . shrink ( ) :
Row (
_serviceReport . callLastSituation ? . id ! = 12
? const SizedBox . shrink ( )
: Row (
children: [
Expanded (
child: Column (
crossAxisAlignment: CrossAxisAlignment . start ,
children: [
ASubTitle ( _subtitle . invoiceNumber ) ,
const SizedBox ( height: 8 , ) ,
const SizedBox (
height: 8 ,
) ,
ATextFormField (
initialValue: _serviceReport ? . invoiceNumber ,
textAlign: TextAlign . center ,
style: Theme . of ( context ) . textTheme . subtitle1 ,
validator: ( value ) = >
Validator . hasValue ( value ! )
? ' ' : _subtitle . requiredWord ,
validator: ( value ) = > Validator . hasValue ( value ! ) ? ' ' : _subtitle . requiredWord ,
textInputType: TextInputType . number ,
onSaved: ( value ) {
_serviceReport . invoiceNumber = value ;
@ -315,20 +355,22 @@ class _EditServiceReportState extends State<EditServiceReport> with TickerProvid
] ,
) ,
) ,
const SizedBox ( width: 8 , ) ,
const SizedBox (
width: 8 ,
) ,
Expanded (
child: Column (
crossAxisAlignment: CrossAxisAlignment . start ,
children: [
ASubTitle ( _subtitle . invoiceCode ) ,
const SizedBox ( height: 4 , ) ,
const SizedBox (
height: 4 ,
) ,
ATextFormField (
initialValue: _serviceReport ? . invoiceCode ,
textAlign: TextAlign . center ,
style: Theme . of ( context ) . textTheme . subtitle1 ,
validator: ( value ) = >
Validator . hasValue ( value ! )
? ' ' : _subtitle . requiredWord ,
validator: ( value ) = > Validator . hasValue ( value ! ) ? ' ' : _subtitle . requiredWord ,
textInputType: TextInputType . text ,
onSaved: ( value ) {
_serviceReport . invoiceCode = value ;
@ -340,7 +382,9 @@ class _EditServiceReportState extends State<EditServiceReport> with TickerProvid
] ,
) ,
const SizedBox ( height: 8 , ) ,
const SizedBox (
height: 8 ,
) ,
Row (
children: [
ASubTitle ( _subtitle . faultDescription ) ,
@ -355,21 +399,23 @@ class _EditServiceReportState extends State<EditServiceReport> with TickerProvid
) ,
] ,
) ,
const SizedBox ( height: 4 , ) ,
const SizedBox (
height: 4 ,
) ,
ATextFormField (
initialValue: _serviceReport ? . faultDescription ,
textAlign: TextAlign . center ,
controller: _faultController ,
style: Theme . of ( context ) . textTheme . subtitle1 ,
validator: ( value ) = >
Validator . hasValue ( value ! )
? ' ' : _subtitle . requiredWord ,
validator: ( value ) = > Validator . hasValue ( value ! ) ? ' ' : _subtitle . requiredWord ,
textInputType: TextInputType . multiline ,
onSaved: ( value ) {
_serviceReport . faultDescription = value ;
} ,
) ,
const SizedBox ( height: 8 , ) ,
const SizedBox (
height: 8 ,
) ,
Row (
children: [
ASubTitle ( _subtitle . workPreformed ) ,
@ -384,23 +430,27 @@ class _EditServiceReportState extends State<EditServiceReport> with TickerProvid
) ,
] ,
) ,
const SizedBox ( height: 4 , ) ,
const SizedBox (
height: 4 ,
) ,
ATextFormField (
initialValue: _serviceReport ? . workPreformed ,
textAlign: TextAlign . center ,
controller: _workPreformedController ,
style: Theme . of ( context ) . textTheme . subtitle1 ,
validator: ( value ) = >
Validator . hasValue ( value ! )
? ' ' : _subtitle . requiredWord ,
validator: ( value ) = > Validator . hasValue ( value ! ) ? ' ' : _subtitle . requiredWord ,
textInputType: TextInputType . multiline ,
onSaved: ( value ) {
_serviceReport . workPreformed = value ;
} ,
) ,
const SizedBox ( height: 8 , ) ,
const SizedBox (
height: 8 ,
) ,
const SizedBox ( height: 8 , ) ,
const SizedBox (
height: 8 ,
) ,
Row (
children: [
/ / reasons
@ -409,7 +459,9 @@ class _EditServiceReportState extends State<EditServiceReport> with TickerProvid
crossAxisAlignment: CrossAxisAlignment . start ,
children: [
ASubTitle ( _subtitle . reasons ) ,
const SizedBox ( height: 4 , ) ,
const SizedBox (
height: 4 ,
) ,
ServiceReportReasonsMenu (
initialValue: _serviceReport . reason ,
onSelect: ( status ) {
@ -419,7 +471,9 @@ class _EditServiceReportState extends State<EditServiceReport> with TickerProvid
] ,
) ,
) ,
const SizedBox ( width: 8 , ) ,
const SizedBox (
width: 8 ,
) ,
Expanded (
child: Column (
crossAxisAlignment: CrossAxisAlignment . start ,
@ -438,7 +492,9 @@ class _EditServiceReportState extends State<EditServiceReport> with TickerProvid
) ,
] ,
) ,
const SizedBox ( height: 8 , ) ,
const SizedBox (
height: 8 ,
) ,
/ / Traveling Hours & Working Hours
Row (
children: [
@ -447,7 +503,9 @@ class _EditServiceReportState extends State<EditServiceReport> with TickerProvid
crossAxisAlignment: CrossAxisAlignment . start ,
children: [
ASubTitle ( _subtitle . workingHours ) ,
const SizedBox ( height: 8 , ) ,
const SizedBox (
height: 8 ,
) ,
AppTimer (
timer: _serviceReport . timer ,
onChange: ( timer ) async {
@ -471,21 +529,23 @@ class _EditServiceReportState extends State<EditServiceReport> with TickerProvid
] ,
) ,
) ,
const SizedBox ( width: 8 , ) ,
const SizedBox (
width: 8 ,
) ,
Expanded (
child: Column (
crossAxisAlignment: CrossAxisAlignment . start ,
children: [
ASubTitle ( _subtitle . travelingHours ) ,
const SizedBox ( height: 4 , ) ,
const SizedBox (
height: 4 ,
) ,
ATextFormField (
initialValue: _serviceReport ? . travelingHours ,
textAlign: TextAlign . center ,
hintText: " i.e 3, 3.5, 4 " ,
style: Theme . of ( context ) . textTheme . subtitle1 ,
validator: ( value ) = >
Validator . isNumeric ( value ! )
? ' ' : _subtitle . requiredWord ,
validator: ( value ) = > Validator . isNumeric ( value ! ) ? ' ' : _subtitle . requiredWord ,
textInputType: TextInputType . number ,
onSaved: ( value ) {
_serviceReport . travelingHours = value ;
@ -496,7 +556,9 @@ class _EditServiceReportState extends State<EditServiceReport> with TickerProvid
) ,
] ,
) ,
const SizedBox ( height: 8 , ) ,
const SizedBox (
height: 8 ,
) ,
/ / Operating Hours and Job Sheet Number
Row (
children: [
@ -505,15 +567,15 @@ class _EditServiceReportState extends State<EditServiceReport> with TickerProvid
crossAxisAlignment: CrossAxisAlignment . start ,
children: [
ASubTitle ( _subtitle . operatingHours ) ,
const SizedBox ( height: 4 , ) ,
const SizedBox (
height: 4 ,
) ,
ATextFormField (
initialValue: _serviceReport ? . operatingHours ,
textAlign: TextAlign . center ,
hintText: " i.e 3, 3.5, 4 " ,
style: Theme . of ( context ) . textTheme . subtitle1 ,
validator: ( value ) = >
Validator . isNumeric ( value ! )
? ' ' : _subtitle . requiredWord ,
validator: ( value ) = > Validator . isNumeric ( value ! ) ? ' ' : _subtitle . requiredWord ,
textInputType: TextInputType . number ,
onSaved: ( value ) {
_serviceReport . operatingHours = value ;
@ -522,13 +584,17 @@ class _EditServiceReportState extends State<EditServiceReport> with TickerProvid
] ,
) ,
) ,
const SizedBox ( width: 8 , ) ,
const SizedBox (
width: 8 ,
) ,
Expanded (
child: Column (
crossAxisAlignment: CrossAxisAlignment . start ,
children: [
ASubTitle ( _subtitle . jobSheetNumber ) ,
const SizedBox ( height: 4 , ) ,
const SizedBox (
height: 4 ,
) ,
ATextFormField (
initialValue: _serviceReport ? . jobSheetNumber ,
textAlign: TextAlign . center ,
@ -543,7 +609,9 @@ class _EditServiceReportState extends State<EditServiceReport> with TickerProvid
) ,
] ,
) ,
const SizedBox ( height: 8 , ) ,
const SizedBox (
height: 8 ,
) ,
/ / Part Number and Quantity
Row (
children: [
@ -553,10 +621,15 @@ class _EditServiceReportState extends State<EditServiceReport> with TickerProvid
crossAxisAlignment: CrossAxisAlignment . start ,
children: [
ASubTitle ( _subtitle . partNumber ) ,
_validate & & _serviceReport . parts = = null ?
ASubTitle ( _subtitle . requiredWord , color: Colors . red , ) :
const SizedBox . shrink ( ) ,
const SizedBox ( height: 4 , ) ,
_validate & & _serviceReport . parts = = null
? ASubTitle (
_subtitle . requiredWord ,
color: Colors . red ,
)
: const SizedBox . shrink ( ) ,
const SizedBox (
height: 4 ,
) ,
AutoCompletePartsField (
onPick: ( part ) {
_serviceReport . parts ? . add ( part ) ;
@ -566,10 +639,11 @@ class _EditServiceReportState extends State<EditServiceReport> with TickerProvid
] ,
) ,
) ,
] ,
) ,
SizedBox ( height: 8 * AppStyle . getScaleFactor ( context ) , ) ,
SizedBox (
height: 8 * AppStyle . getScaleFactor ( context ) ,
) ,
Row (
children: [
Expanded ( flex: 3 , child: Text ( _subtitle . number ) ) ,
@ -577,9 +651,7 @@ class _EditServiceReportState extends State<EditServiceReport> with TickerProvid
] ,
) ,
Column (
children: List . generate (
_serviceReport . parts ! . length ,
( index ) {
children: List . generate ( _serviceReport . parts ! . length , ( index ) {
Part _part = _serviceReport . parts ! [ index ] ;
return PartItem (
part : _part ,
@ -588,12 +660,12 @@ class _EditServiceReportState extends State<EditServiceReport> with TickerProvid
setState ( ( ) { } ) ;
} ,
) ;
}
) ,
} ) ,
) ,
const SizedBox ( height: 16 , ) ,
const SizedBox (
height: 16 ,
) ,
] ,
) ,
) ,
@ -616,12 +688,8 @@ class _EditServiceReportState extends State<EditServiceReport> with TickerProvid
_isLoading = true ;
setState ( ( ) { } ) ;
int status = await _serviceRequestsProvider . updateServiceReport (
user: _userProvider . user ! ,
host: _settingProvider . host ? ? " " ,
report: _serviceReport ,
request: widget . request
) ;
int status =
await _serviceRequestsProvider . updateServiceReport ( user: UserApiClient ( ) . user ! , host: _settingProvider . host ? ? " " , report: _serviceReport , request: widget . request ) ;
_isLoading = false ;
setState ( ( ) { } ) ;
if ( status > = 200 & & status < 300 ) {
@ -631,20 +699,17 @@ class _EditServiceReportState extends State<EditServiceReport> with TickerProvid
Navigator . of ( context ) . pop ( ) ;
Navigator . of ( context ) . pop ( ) ;
} else {
String errorMessage = HttpStatusManger . getStatusMessage (
status: status , subtitle: _subtitle ) ;
ScaffoldMessenger . of ( context ) . showSnackBar (
SnackBar (
content: Text (
errorMessage
) ,
)
) ;
String errorMessage = HttpStatusManger . getStatusMessage ( status: status , subtitle: _subtitle ) ;
ScaffoldMessenger . of ( context ) . showSnackBar ( SnackBar (
content: Text ( errorMessage ) ,
) ) ;
}
} ,
) ,
) ,
const SizedBox ( height: 300 , )
const SizedBox (
height: 300 ,
)
] ,
) ,
const ABackButton ( ) ,