You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
220 lines
7.8 KiB
Dart
220 lines
7.8 KiB
Dart
|
3 years ago
|
import 'dart:convert';
|
||
|
3 years ago
|
|
||
|
|
import 'package:flutter/foundation.dart';
|
||
|
|
import 'package:flutter/material.dart';
|
||
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
||
|
|
import 'package:provider/provider.dart';
|
||
|
|
|
||
|
3 years ago
|
import '../../../controllers/http_status_manger/http_status_manger.dart';
|
||
|
|
import '../../../controllers/localization/localization.dart';
|
||
|
3 years ago
|
import '../../../controllers/providers/api/device_transfer_provider.dart';
|
||
|
|
import '../../../controllers/providers/api/user_provider.dart';
|
||
|
|
import '../../../controllers/providers/settings/setting_provider.dart';
|
||
|
|
import '../../../models/device/device_transfer.dart';
|
||
|
|
import '../../../models/device/device_transfer_info.dart';
|
||
|
|
import '../../../models/subtitle.dart';
|
||
|
3 years ago
|
import '../../../models/user.dart';
|
||
|
|
import '../../app_style/sizing.dart';
|
||
|
|
import '../../widgets/app_text_form_field.dart';
|
||
|
|
import '../../widgets/buttons/app_button.dart';
|
||
|
|
import '../../widgets/e_signature/e_signature.dart';
|
||
|
|
import '../../widgets/loaders/loading_manager.dart';
|
||
|
|
import '../../widgets/status/gas_refill/gas_status.dart';
|
||
|
|
import '../../widgets/titles/app_sub_title.dart';
|
||
|
3 years ago
|
|
||
|
3 years ago
|
class UpdateDeviceTransfer extends StatefulWidget {
|
||
|
3 years ago
|
final DeviceTransfer? model;
|
||
|
|
final bool? isSender;
|
||
|
|
const UpdateDeviceTransfer({Key? key, this.model, this.isSender}) : super(key: key);
|
||
|
3 years ago
|
|
||
|
|
@override
|
||
|
|
State<UpdateDeviceTransfer> createState() => _UpdateDeviceTransferState();
|
||
|
|
}
|
||
|
|
|
||
|
|
class _UpdateDeviceTransferState extends State<UpdateDeviceTransfer> {
|
||
|
|
bool _isLoading = false;
|
||
|
|
bool _validate = false;
|
||
|
3 years ago
|
Subtitle? _subtitle;
|
||
|
|
UserProvider? _userProvider;
|
||
|
|
SettingProvider? _settingProvider;
|
||
|
|
Uint8List? _signature;
|
||
|
|
DeviceTransferProvider? _deviceTransferProvider;
|
||
|
3 years ago
|
final TextEditingController _requestedQuantityController = TextEditingController();
|
||
|
|
final DeviceTransferInfo _formModel = DeviceTransferInfo();
|
||
|
|
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
||
|
|
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
||
|
|
|
||
|
|
_update() async {
|
||
|
|
_validate = true;
|
||
|
3 years ago
|
if((_formKey.currentState?.validate()??false)){
|
||
|
3 years ago
|
setState(() {});
|
||
|
|
return false;
|
||
|
|
}
|
||
|
3 years ago
|
_formKey.currentState?.save();
|
||
|
3 years ago
|
|
||
|
|
_isLoading =true;
|
||
|
|
setState(() {});
|
||
|
3 years ago
|
int? status = await _deviceTransferProvider?.updateRequest(
|
||
|
3 years ago
|
user: _userProvider?.user??User(),
|
||
|
|
host: _settingProvider?.host??"",
|
||
|
|
requestId: widget.model?.id??"",
|
||
|
3 years ago
|
isSender: widget.isSender??false,
|
||
|
3 years ago
|
newModel: _formModel,
|
||
|
|
oldModel: widget.model
|
||
|
|
);
|
||
|
|
_isLoading =false;
|
||
|
|
setState(() {});
|
||
|
3 years ago
|
if(status!=null && status >= 200 && status < 300){
|
||
|
3 years ago
|
Fluttertoast.showToast(
|
||
|
3 years ago
|
msg: _subtitle?.requestCompleteSuccessfully??"",
|
||
|
3 years ago
|
);
|
||
|
|
_validate = false;
|
||
|
|
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
|
||
|
|
),
|
||
|
|
)
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
@override
|
||
|
|
void setState(VoidCallback fn){
|
||
|
|
if(mounted) super.setState(() {});
|
||
|
|
}
|
||
|
|
|
||
|
|
@override
|
||
|
|
void initState() {
|
||
|
3 years ago
|
_formModel.fromDetails((widget.isSender??false) ? widget.model?.sender : widget.model?.receiver,
|
||
|
3 years ago
|
withSignature: false
|
||
|
|
);
|
||
|
|
super.initState();
|
||
|
|
}
|
||
|
|
|
||
|
|
@override
|
||
|
|
void dispose() {
|
||
|
|
_requestedQuantityController.dispose();
|
||
|
|
super.dispose();
|
||
|
|
}
|
||
|
|
|
||
|
|
@override
|
||
|
|
Widget build(BuildContext context) {
|
||
|
3 years ago
|
_subtitle = AppLocalization.of(context)?.subtitle;
|
||
|
3 years ago
|
_userProvider = Provider.of<UserProvider>(context);
|
||
|
|
_settingProvider = Provider.of<SettingProvider>(context);
|
||
|
|
_deviceTransferProvider = Provider.of<DeviceTransferProvider>(context,listen: false);
|
||
|
|
return Scaffold(
|
||
|
|
key: _scaffoldKey,
|
||
|
|
body: Form(
|
||
|
|
key: _formKey,
|
||
|
|
child: SafeArea(
|
||
|
|
child: LoadingManager(
|
||
|
|
isLoading: _isLoading,
|
||
|
|
isFailedLoading: false,
|
||
|
|
stateCode: 200,
|
||
|
|
onRefresh: () async {},
|
||
|
|
child: SingleChildScrollView(
|
||
|
|
padding: EdgeInsets.all(12 * AppStyle.getScaleFactor(context)),
|
||
|
|
child: Column(
|
||
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||
|
|
children: [
|
||
|
|
Center(
|
||
|
|
child: Padding(
|
||
|
|
padding: const EdgeInsets.all(8.0),
|
||
|
|
child: Text(
|
||
|
|
"Edit Transfer Device",
|
||
|
3 years ago
|
style: Theme.of(context).textTheme.headline5?.copyWith(
|
||
|
3 years ago
|
color: Theme.of(context).primaryColor,
|
||
|
|
fontSize: 28,
|
||
|
|
fontWeight: FontWeight.bold
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
const SizedBox(height: 8,),
|
||
|
|
ASubTitle("Comment"),
|
||
|
|
|
||
|
|
const SizedBox(height: 4,),
|
||
|
|
ATextFormField(
|
||
|
3 years ago
|
initialValue: _formModel.comment??"",
|
||
|
3 years ago
|
textAlign: TextAlign.center,
|
||
|
|
style: Theme.of(context).textTheme.subtitle1,
|
||
|
|
textInputType: TextInputType.text,
|
||
|
|
onSaved: (value){
|
||
|
|
_formModel.comment = value;
|
||
|
|
},
|
||
|
|
),
|
||
|
|
const SizedBox(height: 8,),
|
||
|
3 years ago
|
ASubTitle(_subtitle?.travelingHours??""),
|
||
|
3 years ago
|
const SizedBox(height: 4,),
|
||
|
|
ATextFormField(
|
||
|
3 years ago
|
initialValue: _formModel.travelingHours??"",
|
||
|
3 years ago
|
textAlign: TextAlign.center,
|
||
|
|
style: Theme.of(context).textTheme.subtitle1,
|
||
|
|
textInputType: TextInputType.number,
|
||
|
|
onSaved: (value){
|
||
|
|
_formModel.travelingHours = value;
|
||
|
|
},
|
||
|
|
),
|
||
|
|
const SizedBox(height: 8,),
|
||
|
3 years ago
|
ASubTitle(_subtitle?.workingHours??""),
|
||
|
3 years ago
|
const SizedBox(height: 4,),
|
||
|
|
ATextFormField(
|
||
|
3 years ago
|
initialValue: _formModel.workingHours??"",
|
||
|
3 years ago
|
textAlign: TextAlign.center,
|
||
|
|
style: Theme.of(context).textTheme.subtitle1,
|
||
|
|
textInputType: TextInputType.number,
|
||
|
|
onSaved: (value){
|
||
|
|
_formModel.workingHours = value;
|
||
|
|
},
|
||
|
|
),
|
||
|
|
const SizedBox(height: 8,),
|
||
|
3 years ago
|
ASubTitle(_subtitle?.status??""),
|
||
|
3 years ago
|
const SizedBox(height: 4,),
|
||
|
|
GasStatusMenu(
|
||
|
|
initialValue: _formModel.status,
|
||
|
|
onSelect: (status){
|
||
|
|
_formModel.status = status;
|
||
|
|
setState(() {});
|
||
|
|
},
|
||
|
|
),
|
||
|
|
const SizedBox(height: 8,),
|
||
|
|
const ASubTitle("Signature"),
|
||
|
|
// if(_validate && _formModel.signature == null)
|
||
|
|
// ASubTitle(_subtitle.requiredWord,color: Colors.red,),
|
||
|
|
const SizedBox(height: 4,),
|
||
|
|
ESignature(
|
||
|
3 years ago
|
oldSignature: (widget.isSender??false)
|
||
|
|
? widget.model?.sender?.signature
|
||
|
|
: widget.model?.receiver?.signature,
|
||
|
3 years ago
|
newSignature: _signature,
|
||
|
|
onSaved: (signature){
|
||
|
|
_signature = signature;
|
||
|
|
_formModel.signature = base64Encode(signature);
|
||
|
|
},
|
||
|
|
),
|
||
|
|
Padding(
|
||
|
|
padding: const EdgeInsets.all(16.0),
|
||
|
|
child: AButton(
|
||
|
3 years ago
|
text: _subtitle?.update??"",
|
||
|
3 years ago
|
onPressed: _update,
|
||
|
|
),
|
||
|
|
),
|
||
|
|
const SizedBox(height: 100,)
|
||
|
|
],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|