|
|
|
|
@ -1,43 +1,34 @@
|
|
|
|
|
import 'dart:convert';
|
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
|
|
import 'package:file_picker/file_picker.dart';
|
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
|
|
|
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
|
|
|
|
import 'package:image_picker/image_picker.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
import 'package:test_sa/controllers/api_routes/http_status_manger.dart';
|
|
|
|
|
import 'package:test_sa/controllers/localization/localization.dart';
|
|
|
|
|
import 'package:test_sa/controllers/providers/api/service_requests_provider.dart';
|
|
|
|
|
import 'package:test_sa/controllers/providers/api/user_provider.dart';
|
|
|
|
|
import 'package:test_sa/controllers/providers/settings/setting_provider.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/text_extensions.dart';
|
|
|
|
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
|
|
|
|
import 'package:test_sa/models/service_request/service_request.dart';
|
|
|
|
|
import 'package:test_sa/models/subtitle.dart';
|
|
|
|
|
import 'package:test_sa/new_views/common_widgets/app_filled_button.dart';
|
|
|
|
|
import 'package:test_sa/views/widgets/app_text_form_field.dart';
|
|
|
|
|
import 'package:test_sa/views/widgets/date_and_time/time_picker.dart';
|
|
|
|
|
import 'package:test_sa/views/widgets/equipment/pick_asset.dart';
|
|
|
|
|
import 'package:test_sa/views/widgets/images/multi_image_picker.dart';
|
|
|
|
|
import 'package:test_sa/views/widgets/loaders/loading_manager.dart';
|
|
|
|
|
import 'package:test_sa/views/widgets/sound/record_sound.dart';
|
|
|
|
|
import 'package:test_sa/views/widgets/sound/sound_player.dart';
|
|
|
|
|
import 'package:test_sa/views/widgets/speech_to_text/speech_to_text.dart';
|
|
|
|
|
import 'package:test_sa/views/widgets/status/service_request/service_request_defect_types_mune.dart';
|
|
|
|
|
import 'package:test_sa/views/widgets/status/service_request/service_request_priority_mune.dart';
|
|
|
|
|
import 'package:test_sa/views/widgets/status/service_request/service_request_through_mune.dart';
|
|
|
|
|
import 'package:test_sa/views/widgets/status/service_request/service_request_types_mune.dart';
|
|
|
|
|
import 'package:test_sa/views/widgets/titles/app_sub_title.dart';
|
|
|
|
|
|
|
|
|
|
import '../../../../controllers/providers/api/status_drop_down/service_reqest/service_request_through_provider.dart';
|
|
|
|
|
import '../../../../controllers/providers/api/status_drop_down/service_reqest/service_request_type_provider.dart';
|
|
|
|
|
import '../../../../models/device/device.dart';
|
|
|
|
|
import '../../../../models/enums/translation_keys.dart';
|
|
|
|
|
import '../../../../models/lookup.dart';
|
|
|
|
|
import '../../../../new_views/app_style/app_color.dart';
|
|
|
|
|
import '../../../../new_views/common_widgets/app_dashed_button.dart';
|
|
|
|
|
import '../../../../new_views/common_widgets/app_lazy_loading.dart';
|
|
|
|
|
import '../../../../new_views/common_widgets/app_text_form_field.dart';
|
|
|
|
|
import '../../../../new_views/common_widgets/default_app_bar.dart';
|
|
|
|
|
import '../../../widgets/status/service_request/service_request_first_action.dart';
|
|
|
|
|
import '../../../widgets/status/service_request/service_request_loan_availability.dart';
|
|
|
|
|
import '../../../../new_views/common_widgets/single_item_drop_down_menu.dart';
|
|
|
|
|
import '../../../../providers/service_request_providers/equipment_status_provider.dart';
|
|
|
|
|
import '../../../../providers/service_request_providers/priority_provider.dart';
|
|
|
|
|
|
|
|
|
|
class CreateRequestPage extends StatefulWidget {
|
|
|
|
|
static const String id = "/create-request";
|
|
|
|
|
@ -50,6 +41,8 @@ class CreateRequestPage extends StatefulWidget {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class CreateRequestPageState extends State<CreateRequestPage> {
|
|
|
|
|
TextEditingController _commentController;
|
|
|
|
|
|
|
|
|
|
double _height;
|
|
|
|
|
UserProvider _userProvider;
|
|
|
|
|
SettingProvider _settingProvider;
|
|
|
|
|
@ -58,21 +51,17 @@ class CreateRequestPageState extends State<CreateRequestPage> {
|
|
|
|
|
final List<File> _deviceImages = [];
|
|
|
|
|
bool _isLoading = false;
|
|
|
|
|
bool _showDatePicker = false;
|
|
|
|
|
Device _asset;
|
|
|
|
|
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
|
|
|
|
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
|
|
|
|
TextEditingController _maintenanceController, _commentController, _reviewCommentController;
|
|
|
|
|
DateTime _dateTime;
|
|
|
|
|
|
|
|
|
|
bool isFirstActionSubmitted = false;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
_maintenanceController = TextEditingController();
|
|
|
|
|
_commentController = TextEditingController();
|
|
|
|
|
if (widget.serviceRequest != null) {
|
|
|
|
|
_serviceRequest = widget.serviceRequest;
|
|
|
|
|
_asset = _serviceRequest.device;
|
|
|
|
|
_deviceImages.addAll(_serviceRequest.devicePhotos.map((e) => File(e)).toList());
|
|
|
|
|
_showDatePicker = _serviceRequest.firstAction != null && _serviceRequest.firstAction.name == "Need a visit";
|
|
|
|
|
if (_showDatePicker && _serviceRequest.visitDate != null) {
|
|
|
|
|
@ -107,7 +96,6 @@ class CreateRequestPageState extends State<CreateRequestPage> {
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
_maintenanceController.dispose();
|
|
|
|
|
_commentController.dispose();
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
@ -127,7 +115,7 @@ class CreateRequestPageState extends State<CreateRequestPage> {
|
|
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
|
key: _scaffoldKey,
|
|
|
|
|
appBar: DefaultAppBar(title: context.translation.newServiceRequest),
|
|
|
|
|
appBar: DefaultAppBar(title: context.translation.newServiceRequest),
|
|
|
|
|
body: SafeArea(
|
|
|
|
|
child: LoadingManager(
|
|
|
|
|
isLoading: _isLoading,
|
|
|
|
|
@ -143,235 +131,58 @@ class CreateRequestPageState extends State<CreateRequestPage> {
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
PickAsset(
|
|
|
|
|
device: _asset,
|
|
|
|
|
device: _serviceRequest.device,
|
|
|
|
|
onPickAsset: (asset) {
|
|
|
|
|
_asset = asset;
|
|
|
|
|
_serviceRequest.device = asset;
|
|
|
|
|
setState(() {});
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(
|
|
|
|
|
height: 8,
|
|
|
|
|
),
|
|
|
|
|
const ASubTitle("Priority"),
|
|
|
|
|
const SizedBox(
|
|
|
|
|
height: 4,
|
|
|
|
|
),
|
|
|
|
|
ServiceRequestPriorityMenu(
|
|
|
|
|
initialValue: widget.serviceRequest?.priority,
|
|
|
|
|
onSelect: (status) {
|
|
|
|
|
_serviceRequest.priority = status;
|
|
|
|
|
8.height,
|
|
|
|
|
SingleItemDropDownMenu<Lookup, PriorityProvider>(
|
|
|
|
|
context: context,
|
|
|
|
|
title: context.translation.priority,
|
|
|
|
|
initialValue: _serviceRequest?.priority,
|
|
|
|
|
onSelect: (value) {
|
|
|
|
|
_serviceRequest.priority = value;
|
|
|
|
|
},
|
|
|
|
|
enabled: widget.serviceRequest == null ? true : false,
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(
|
|
|
|
|
height: 8,
|
|
|
|
|
),
|
|
|
|
|
const ASubTitle("Equipment Status"),
|
|
|
|
|
const SizedBox(
|
|
|
|
|
height: 4,
|
|
|
|
|
),
|
|
|
|
|
ServiceRequestDefectTypesMenu(
|
|
|
|
|
initialValue: _serviceRequest.defectType,
|
|
|
|
|
onSelect: (status) {
|
|
|
|
|
_serviceRequest.defectType = status;
|
|
|
|
|
8.height,
|
|
|
|
|
SingleItemDropDownMenu<Lookup, EquipmentStatusProvider>(
|
|
|
|
|
context: context,
|
|
|
|
|
title: context.translation.equipmentStatus,
|
|
|
|
|
initialValue: _serviceRequest?.defectType,
|
|
|
|
|
onSelect: (value) {
|
|
|
|
|
_serviceRequest.defectType = value;
|
|
|
|
|
},
|
|
|
|
|
enabled: widget.serviceRequest == null ? true : false,
|
|
|
|
|
),
|
|
|
|
|
12.height,
|
|
|
|
|
const SizedBox(
|
|
|
|
|
height: 8,
|
|
|
|
|
8.height,
|
|
|
|
|
AppDashedButton(title: _serviceRequest.devicePhotos?.first?.split("/")?.last ?? context.translation.attachImage, onPressed: _attachImage),
|
|
|
|
|
16.height,
|
|
|
|
|
Align(
|
|
|
|
|
alignment: AlignmentDirectional.centerStart,
|
|
|
|
|
child: context.translation.callComments.heading5(context),
|
|
|
|
|
),
|
|
|
|
|
const ASubTitle("Type of Request"),
|
|
|
|
|
const SizedBox(
|
|
|
|
|
height: 4,
|
|
|
|
|
8.height,
|
|
|
|
|
AppTextFormField(
|
|
|
|
|
controller: _commentController,
|
|
|
|
|
labelText: context.translation.comments,
|
|
|
|
|
suffixIcon: "warning".toSvgAsset(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20, width: 24).paddingOnly(end: 16),
|
|
|
|
|
),
|
|
|
|
|
ServiceRequestTypesMenu(
|
|
|
|
|
initialValue: _serviceRequest.type,
|
|
|
|
|
onSelect: (status) {
|
|
|
|
|
_serviceRequest.type = status;
|
|
|
|
|
8.height,
|
|
|
|
|
RecordSound(
|
|
|
|
|
onRecord: (audio) {
|
|
|
|
|
_serviceRequest.audio = audio;
|
|
|
|
|
},
|
|
|
|
|
enabled: false,
|
|
|
|
|
withDefaultItem: widget.serviceRequest == null,
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(
|
|
|
|
|
height: 8,
|
|
|
|
|
),
|
|
|
|
|
const ASubTitle("Through"),
|
|
|
|
|
const SizedBox(
|
|
|
|
|
height: 4,
|
|
|
|
|
),
|
|
|
|
|
ServiceRequestedThroughMenu(
|
|
|
|
|
initialValue: _serviceRequest.requestedThrough,
|
|
|
|
|
enabled: false,
|
|
|
|
|
),
|
|
|
|
|
if (widget.serviceRequest != null) 12.height,
|
|
|
|
|
if (widget.serviceRequest != null) const ASubTitle("First Action"),
|
|
|
|
|
const SizedBox(
|
|
|
|
|
height: 4,
|
|
|
|
|
),
|
|
|
|
|
if (widget.serviceRequest != null)
|
|
|
|
|
ServiceRequestedFirstAction(
|
|
|
|
|
initialValue: _serviceRequest.firstAction,
|
|
|
|
|
enabled: !isFirstActionSubmitted,
|
|
|
|
|
onSelect: (status) {
|
|
|
|
|
_dateTime = null;
|
|
|
|
|
_serviceRequest.firstAction = status;
|
|
|
|
|
_showDatePicker = _serviceRequest.firstAction != null && _serviceRequest.firstAction.name == "Need a visit";
|
|
|
|
|
_serviceRequestsProvider.notifyListeners();
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
if (_showDatePicker) 12.height,
|
|
|
|
|
if (_showDatePicker)
|
|
|
|
|
ADateTimePicker(
|
|
|
|
|
date: _dateTime,
|
|
|
|
|
enable: !isFirstActionSubmitted,
|
|
|
|
|
from: DateTime.now(),
|
|
|
|
|
onDateTimePicker: (date) {
|
|
|
|
|
_dateTime = date;
|
|
|
|
|
setState(() {});
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
if (widget.serviceRequest != null) 12.height,
|
|
|
|
|
if (widget.serviceRequest != null) const ASubTitle("Loan Availability"),
|
|
|
|
|
const SizedBox(
|
|
|
|
|
height: 4,
|
|
|
|
|
),
|
|
|
|
|
if (widget.serviceRequest != null)
|
|
|
|
|
ServiceRequestedLoanAvailability(
|
|
|
|
|
initialValue: _serviceRequest.loanAvailability,
|
|
|
|
|
onSelect: (status) {
|
|
|
|
|
_serviceRequest.loanAvailability = status;
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
12.height,
|
|
|
|
|
if (widget.serviceRequest != null) const ASubTitle("Comments"),
|
|
|
|
|
const SizedBox(
|
|
|
|
|
height: 4,
|
|
|
|
|
),
|
|
|
|
|
if (widget.serviceRequest != null)
|
|
|
|
|
ATextFormField(
|
|
|
|
|
controller: _reviewCommentController,
|
|
|
|
|
initialValue: _serviceRequest.reviewComment,
|
|
|
|
|
hintText: context.translation.comment,
|
|
|
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
|
|
|
textInputType: TextInputType.multiline,
|
|
|
|
|
onSaved: (value) {
|
|
|
|
|
_serviceRequest.reviewComment = value;
|
|
|
|
|
},
|
|
|
|
|
enable: widget.serviceRequest != null ? false : true,
|
|
|
|
|
),
|
|
|
|
|
12.height,
|
|
|
|
|
MultiFilesPicker(
|
|
|
|
|
label: context.translation.deviceFiles,
|
|
|
|
|
files: _deviceImages,
|
|
|
|
|
enabled: widget.serviceRequest == null ? true : false,
|
|
|
|
|
),
|
|
|
|
|
12.height,
|
|
|
|
|
SpeechToTextButton(
|
|
|
|
|
controller: _maintenanceController,
|
|
|
|
|
enabled: widget.serviceRequest == null ? true : false,
|
|
|
|
|
),
|
|
|
|
|
12.height,
|
|
|
|
|
ATextFormField(
|
|
|
|
|
controller: _maintenanceController,
|
|
|
|
|
initialValue: _serviceRequest.callComments,
|
|
|
|
|
hintText: context.translation.maintenanceIssue,
|
|
|
|
|
prefixIconData: FontAwesomeIcons.triangleExclamation,
|
|
|
|
|
style: Theme.of(context).textTheme.titleLarge,
|
|
|
|
|
textInputType: TextInputType.multiline,
|
|
|
|
|
validator: (value) => widget.serviceRequest != null || Validator.hasValue(value) ? null : context.translation.maintenanceIssueRequired,
|
|
|
|
|
onSaved: (value) {
|
|
|
|
|
_serviceRequest.callComments = value;
|
|
|
|
|
},
|
|
|
|
|
enable: widget.serviceRequest == null ? true : false,
|
|
|
|
|
),
|
|
|
|
|
12.height,
|
|
|
|
|
if (_serviceRequest.audio?.isNotEmpty == true)
|
|
|
|
|
ASoundPlayer(
|
|
|
|
|
audio: _serviceRequest.audio,
|
|
|
|
|
)
|
|
|
|
|
else
|
|
|
|
|
RecordSound(
|
|
|
|
|
onRecord: (audio) {
|
|
|
|
|
_serviceRequest.audio = audio;
|
|
|
|
|
},
|
|
|
|
|
enabled: widget.serviceRequest == null ? true : false,
|
|
|
|
|
),
|
|
|
|
|
12.height,
|
|
|
|
|
if (widget.serviceRequest != null)
|
|
|
|
|
ATextFormField(
|
|
|
|
|
controller: _commentController,
|
|
|
|
|
initialValue: _serviceRequest.comments,
|
|
|
|
|
hintText: context.translation.comment,
|
|
|
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
|
|
|
textInputType: TextInputType.multiline,
|
|
|
|
|
onSaved: (value) {
|
|
|
|
|
_serviceRequest.comments = value;
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
16.height,
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
).expanded,
|
|
|
|
|
AppFilledButton(
|
|
|
|
|
onPressed: () async {
|
|
|
|
|
if (!_formKey.currentState.validate()) return;
|
|
|
|
|
if (_asset?.id == null) {
|
|
|
|
|
Fluttertoast.showToast(msg: context.translation.pickDevice);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (_serviceRequest.firstAction?.name == "Need a visit" && _dateTime == null) {
|
|
|
|
|
Fluttertoast.showToast(msg: "first action is required");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (widget.serviceRequest != null && (_serviceRequest?.engineerId == null || (_serviceRequest?.engineerId?.isEmpty ?? false))) {
|
|
|
|
|
await Fluttertoast.showToast(msg: "No Assigned Employee");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_formKey.currentState.save();
|
|
|
|
|
_serviceRequest.deviceId = _asset?.id;
|
|
|
|
|
if (widget.serviceRequest == null) {
|
|
|
|
|
_serviceRequest.type = Provider.of<ServiceRequestTypeProvider>(context, listen: false).getDefaultItem();
|
|
|
|
|
}
|
|
|
|
|
_serviceRequest.requestedThrough = Provider.of<ServiceRequestedThroughProvider>(context, listen: false).getDefaultItem();
|
|
|
|
|
_isLoading = true;
|
|
|
|
|
setState(() {});
|
|
|
|
|
_serviceRequest.devicePhotos = _deviceImages.map((e) => _isLocalUrl(e.path) ? "${e.path.split("/").last}|${base64Encode(e.readAsBytesSync())}" : e.path).toList();
|
|
|
|
|
if (_serviceRequest.audio != null) {
|
|
|
|
|
if (_isLocalUrl(_serviceRequest.audio)) {
|
|
|
|
|
final File file = File(_serviceRequest.audio);
|
|
|
|
|
_serviceRequest.audio = "${file.path.split("/").last}|${base64Encode(file.readAsBytesSync())}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
int status = 0;
|
|
|
|
|
if (widget.serviceRequest == null) {
|
|
|
|
|
status = await _serviceRequestsProvider.createRequest(
|
|
|
|
|
user: _userProvider.user,
|
|
|
|
|
host: _settingProvider.host,
|
|
|
|
|
serviceRequest: _serviceRequest,
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
status = await _serviceRequestsProvider.updateDate(
|
|
|
|
|
user: _userProvider.user,
|
|
|
|
|
host: _settingProvider.host,
|
|
|
|
|
request: _serviceRequest,
|
|
|
|
|
date: _dateTime,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
_isLoading = false;
|
|
|
|
|
setState(() {});
|
|
|
|
|
if (status >= 200 && status < 300) {
|
|
|
|
|
Fluttertoast.showToast(
|
|
|
|
|
msg: context.translation.successfulRequestMessage,
|
|
|
|
|
);
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
} else {
|
|
|
|
|
String errorMessage = HttpStatusManger.getStatusMessage(status: status, subtitle: context.translation);
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
|
|
|
|
content: Text(errorMessage),
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
label: context.translation.submitRequest),
|
|
|
|
|
onPressed: _submit,
|
|
|
|
|
label: context.translation.submitRequest,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
).paddingOnly(start: 16, end: 16, bottom: 24, top: 16),
|
|
|
|
|
@ -379,4 +190,81 @@ class CreateRequestPageState extends State<CreateRequestPage> {
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_attachImage() async {
|
|
|
|
|
ImageSource source = await showDialog(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (dialogContext) => CupertinoAlertDialog(
|
|
|
|
|
actions: <Widget>[
|
|
|
|
|
TextButton(
|
|
|
|
|
child: Text(context.translation.pickFromCamera),
|
|
|
|
|
onPressed: () {
|
|
|
|
|
Navigator.of(dialogContext).pop(ImageSource.camera);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
TextButton(
|
|
|
|
|
child: Text(context.translation.pickFromGallery),
|
|
|
|
|
onPressed: () {
|
|
|
|
|
Navigator.of(dialogContext).pop(ImageSource.gallery);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
TextButton(
|
|
|
|
|
child: Text(context.translation.pickFromFiles),
|
|
|
|
|
onPressed: () async {
|
|
|
|
|
await _fromFilePicker();
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
if (source == null) return;
|
|
|
|
|
|
|
|
|
|
final pickedFile = await ImagePicker().pickImage(source: source, imageQuality: 70, maxWidth: 800, maxHeight: 800);
|
|
|
|
|
if (pickedFile != null) {
|
|
|
|
|
_serviceRequest.devicePhotos ??= [];
|
|
|
|
|
_serviceRequest.devicePhotos?.clear();
|
|
|
|
|
_serviceRequest.devicePhotos?.add(pickedFile.path);
|
|
|
|
|
setState(() {});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_fromFilePicker() async {
|
|
|
|
|
FilePickerResult result = await FilePicker.platform.pickFiles(
|
|
|
|
|
type: FileType.custom,
|
|
|
|
|
allowedExtensions: ['jpg', 'jpeg', 'png', 'pdf', 'doc', 'docx', 'xlsx', 'pptx'],
|
|
|
|
|
);
|
|
|
|
|
if (result?.files?.first != null) {
|
|
|
|
|
_serviceRequest.devicePhotos ??= [];
|
|
|
|
|
_serviceRequest.devicePhotos?.clear();
|
|
|
|
|
_serviceRequest.devicePhotos?.add(result?.files?.first?.path);
|
|
|
|
|
setState(() {});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _submit() async {
|
|
|
|
|
if (_formKey.currentState.validate() && await _serviceRequest.validateNewRequest(context)) {
|
|
|
|
|
_formKey.currentState.save();
|
|
|
|
|
_serviceRequest.devicePhotos = _deviceImages.map((e) => _isLocalUrl(e.path) ? "${e.path.split("/").last}|${base64Encode(e.readAsBytesSync())}" : e.path).toList();
|
|
|
|
|
if (_serviceRequest.audio != null) {
|
|
|
|
|
if (_isLocalUrl(_serviceRequest.audio)) {
|
|
|
|
|
final File file = File(_serviceRequest.audio);
|
|
|
|
|
_serviceRequest.audio = "${file.path.split("/").last}|${base64Encode(file.readAsBytesSync())}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading());
|
|
|
|
|
int status = await _serviceRequestsProvider.createRequest(
|
|
|
|
|
user: _userProvider.user,
|
|
|
|
|
host: _settingProvider.host,
|
|
|
|
|
serviceRequest: _serviceRequest,
|
|
|
|
|
);
|
|
|
|
|
Navigator.of(context);
|
|
|
|
|
if (status >= 200 && status < 300) {
|
|
|
|
|
Fluttertoast.showToast(msg: context.translation.successfulRequestMessage);
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
} else {
|
|
|
|
|
Fluttertoast.showToast(msg: context.translation.failedRequestMessage);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|