|
|
|
@ -1,17 +1,12 @@
|
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
import 'dart:io';
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
|
|
|
|
|
|
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
|
|
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
|
|
|
|
import '../../../../api/user_api_client.dart';
|
|
|
|
import '../../../../api/user_api_client.dart';
|
|
|
|
import '../../../../controllers/http_status_manger/http_status_manger.dart';
|
|
|
|
|
|
|
|
import '../../../../controllers/localization/localization.dart';
|
|
|
|
import '../../../../controllers/localization/localization.dart';
|
|
|
|
import '../../../../controllers/providers/api/service_requests_provider.dart';
|
|
|
|
import '../../../../controllers/providers/api/service_requests_provider.dart';
|
|
|
|
import '../../../../controllers/providers/settings/setting_provider.dart';
|
|
|
|
|
|
|
|
import '../../../../controllers/providers/user_provider.dart';
|
|
|
|
|
|
|
|
import '../../../../controllers/validator/validator.dart';
|
|
|
|
import '../../../../controllers/validator/validator.dart';
|
|
|
|
import '../../../../extensions/int_extensions.dart';
|
|
|
|
import '../../../../extensions/int_extensions.dart';
|
|
|
|
import '../../../../extensions/widget_extensions.dart';
|
|
|
|
import '../../../../extensions/widget_extensions.dart';
|
|
|
|
@ -32,30 +27,29 @@ import '../../../widgets/status/service_request/service_request_priority_mune.da
|
|
|
|
import '../../../widgets/titles/app_sub_title.dart';
|
|
|
|
import '../../../widgets/titles/app_sub_title.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class CreateRequestPage extends StatefulWidget {
|
|
|
|
class CreateRequestPage extends StatefulWidget {
|
|
|
|
static final String id = "/create-request";
|
|
|
|
static const String id = "/create-request";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const CreateRequestPage({super.key});
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
_CreateRequestPageState createState() => _CreateRequestPageState();
|
|
|
|
CreateRequestPageState createState() => CreateRequestPageState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class _CreateRequestPageState extends State<CreateRequestPage> {
|
|
|
|
class CreateRequestPageState extends State<CreateRequestPage> {
|
|
|
|
late double _height;
|
|
|
|
late double _height;
|
|
|
|
late UserProvider _userProvider;
|
|
|
|
|
|
|
|
late SettingProvider _settingProvider;
|
|
|
|
|
|
|
|
late ServiceRequestsProvider _serviceRequestsProvider;
|
|
|
|
late ServiceRequestsProvider _serviceRequestsProvider;
|
|
|
|
ServiceRequest _serviceRequest = ServiceRequest();
|
|
|
|
final ServiceRequest _serviceRequest = ServiceRequest();
|
|
|
|
List<File> _deviceImages = [];
|
|
|
|
|
|
|
|
bool _isLoading = false;
|
|
|
|
|
|
|
|
Device? _device;
|
|
|
|
Device? _device;
|
|
|
|
late Subtitle _subtitle;
|
|
|
|
Subtitle? _subtitle;
|
|
|
|
|
|
|
|
final List<File> _deviceImages = [];
|
|
|
|
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
|
|
|
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
|
|
|
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
|
|
|
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
|
|
|
late TextEditingController _controller;
|
|
|
|
late TextEditingController _controller;
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
void initState() {
|
|
|
|
_controller = TextEditingController();
|
|
|
|
|
|
|
|
super.initState();
|
|
|
|
super.initState();
|
|
|
|
|
|
|
|
_controller = TextEditingController();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
@ -67,15 +61,13 @@ class _CreateRequestPageState extends State<CreateRequestPage> {
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
_height = MediaQuery.of(context).size.height;
|
|
|
|
_height = MediaQuery.of(context).size.height;
|
|
|
|
_userProvider = Provider.of<UserProvider>(context);
|
|
|
|
_subtitle = AppLocalization.of(context)?.subtitle;
|
|
|
|
_settingProvider = Provider.of<SettingProvider>(context);
|
|
|
|
|
|
|
|
_serviceRequestsProvider = Provider.of<ServiceRequestsProvider>(context);
|
|
|
|
_serviceRequestsProvider = Provider.of<ServiceRequestsProvider>(context);
|
|
|
|
_subtitle = AppLocalization.of(context)!.subtitle!;
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
return Scaffold(
|
|
|
|
key: _scaffoldKey,
|
|
|
|
key: _scaffoldKey,
|
|
|
|
body: SafeArea(
|
|
|
|
body: SafeArea(
|
|
|
|
child: LoadingManager(
|
|
|
|
child: LoadingManager(
|
|
|
|
isLoading: _isLoading,
|
|
|
|
isLoading: _serviceRequestsProvider.loading,
|
|
|
|
isFailedLoading: false,
|
|
|
|
isFailedLoading: false,
|
|
|
|
stateCode: 200,
|
|
|
|
stateCode: 200,
|
|
|
|
onRefresh: () async {},
|
|
|
|
onRefresh: () async {},
|
|
|
|
@ -86,22 +78,22 @@ class _CreateRequestPageState extends State<CreateRequestPage> {
|
|
|
|
ListView(
|
|
|
|
ListView(
|
|
|
|
children: [
|
|
|
|
children: [
|
|
|
|
//AppNameBar(),
|
|
|
|
//AppNameBar(),
|
|
|
|
SizedBox(
|
|
|
|
const SizedBox(
|
|
|
|
height: 16,
|
|
|
|
height: 16,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Hero(
|
|
|
|
Hero(
|
|
|
|
tag: "logo",
|
|
|
|
tag: "logo",
|
|
|
|
child: Image(
|
|
|
|
child: Image(
|
|
|
|
height: _height / 6,
|
|
|
|
height: _height / 6,
|
|
|
|
image: AssetImage("assets/images/logo.png"),
|
|
|
|
image: const AssetImage("assets/images/logo.png"),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Center(
|
|
|
|
Center(
|
|
|
|
child: Padding(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
child: Text(
|
|
|
|
child: Text(
|
|
|
|
_subtitle.newServiceRequest,
|
|
|
|
_subtitle?.newServiceRequest ?? '',
|
|
|
|
style: Theme.of(context).textTheme.headline5?.copyWith(color: AColors.cyan, fontWeight: FontWeight.w600),
|
|
|
|
style: Theme.of(context).textTheme.headlineSmall?.copyWith(color: AColors.cyan, fontWeight: FontWeight.w600),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
@ -110,23 +102,23 @@ class _CreateRequestPageState extends State<CreateRequestPage> {
|
|
|
|
children: [
|
|
|
|
children: [
|
|
|
|
12.height,
|
|
|
|
12.height,
|
|
|
|
UserApiClient().user?.hospital == null
|
|
|
|
UserApiClient().user?.hospital == null
|
|
|
|
? SizedBox.shrink()
|
|
|
|
? const SizedBox.shrink()
|
|
|
|
: ATextFormField(
|
|
|
|
: ATextFormField(
|
|
|
|
enable: false,
|
|
|
|
enable: false,
|
|
|
|
initialValue: UserApiClient().user?.hospital?.name ?? _subtitle.noHospitalFound,
|
|
|
|
initialValue: UserApiClient().user?.hospital?.name ?? _subtitle?.noHospitalFound,
|
|
|
|
hintText: _subtitle.hospital,
|
|
|
|
hintText: _subtitle?.hospital,
|
|
|
|
prefixIconData: FontAwesomeIcons.hospital,
|
|
|
|
prefixIconData: FontAwesomeIcons.hospital,
|
|
|
|
style: Theme.of(context).textTheme.subtitle1,
|
|
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
12.height,
|
|
|
|
12.height,
|
|
|
|
UserApiClient().user?.department == null
|
|
|
|
UserApiClient().user?.department == null
|
|
|
|
? SizedBox.shrink()
|
|
|
|
? const SizedBox.shrink()
|
|
|
|
: ATextFormField(
|
|
|
|
: ATextFormField(
|
|
|
|
enable: false,
|
|
|
|
enable: false,
|
|
|
|
initialValue: UserApiClient().user?.department?.name ?? _subtitle.noUniteFound,
|
|
|
|
initialValue: UserApiClient().user?.department?.name ?? _subtitle?.noUniteFound,
|
|
|
|
hintText: _subtitle.unite,
|
|
|
|
hintText: _subtitle?.unite,
|
|
|
|
prefixIconData: FontAwesomeIcons.hospitalUser,
|
|
|
|
prefixIconData: FontAwesomeIcons.hospitalUser,
|
|
|
|
style: Theme.of(context).textTheme.subtitle1,
|
|
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
12.height,
|
|
|
|
12.height,
|
|
|
|
DeviceButton(
|
|
|
|
DeviceButton(
|
|
|
|
@ -164,7 +156,7 @@ class _CreateRequestPageState extends State<CreateRequestPage> {
|
|
|
|
),
|
|
|
|
),
|
|
|
|
12.height,
|
|
|
|
12.height,
|
|
|
|
MultiImagesPicker(
|
|
|
|
MultiImagesPicker(
|
|
|
|
label: _subtitle.deviceImages,
|
|
|
|
label: _subtitle?.deviceImages,
|
|
|
|
images: _deviceImages,
|
|
|
|
images: _deviceImages,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
12.height,
|
|
|
|
12.height,
|
|
|
|
@ -173,11 +165,11 @@ class _CreateRequestPageState extends State<CreateRequestPage> {
|
|
|
|
ATextFormField(
|
|
|
|
ATextFormField(
|
|
|
|
controller: _controller,
|
|
|
|
controller: _controller,
|
|
|
|
initialValue: _serviceRequest.maintenanceIssue,
|
|
|
|
initialValue: _serviceRequest.maintenanceIssue,
|
|
|
|
hintText: _subtitle.maintenanceIssue,
|
|
|
|
hintText: _subtitle?.maintenanceIssue,
|
|
|
|
prefixIconData: FontAwesomeIcons.triangleExclamation,
|
|
|
|
prefixIconData: FontAwesomeIcons.triangleExclamation,
|
|
|
|
style: Theme.of(context).textTheme.headline6,
|
|
|
|
style: Theme.of(context).textTheme.titleLarge,
|
|
|
|
textInputType: TextInputType.multiline,
|
|
|
|
textInputType: TextInputType.multiline,
|
|
|
|
validator: (value) => Validator.hasValue(value!) ? '' : _subtitle.maintenanceIssueRequired,
|
|
|
|
validator: (value) => Validator.hasValue(value) ? null : _subtitle?.maintenanceIssueRequired,
|
|
|
|
onSaved: (value) {
|
|
|
|
onSaved: (value) {
|
|
|
|
_serviceRequest.maintenanceIssue = value;
|
|
|
|
_serviceRequest.maintenanceIssue = value;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
@ -192,42 +184,19 @@ class _CreateRequestPageState extends State<CreateRequestPage> {
|
|
|
|
Padding(
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(20.0),
|
|
|
|
padding: const EdgeInsets.all(20.0),
|
|
|
|
child: AButton(
|
|
|
|
child: AButton(
|
|
|
|
text: _subtitle.submit,
|
|
|
|
text: _subtitle?.submit ?? '',
|
|
|
|
onPressed: () async {
|
|
|
|
onPressed: () async {
|
|
|
|
if (!(_formKey.currentState?.validate() ?? false)) return;
|
|
|
|
if (_formKey.currentState?.validate() ?? false) {
|
|
|
|
_formKey.currentState?.save();
|
|
|
|
_formKey.currentState?.save();
|
|
|
|
_serviceRequest.deviceId = _device?.id ?? "";
|
|
|
|
_serviceRequest.deviceId = _device?.id ?? "";
|
|
|
|
_isLoading = true;
|
|
|
|
await _serviceRequestsProvider.createRequest(context, serviceRequest: _serviceRequest, deviceImages: _deviceImages);
|
|
|
|
setState(() {});
|
|
|
|
|
|
|
|
_serviceRequest.devicePhotos = _deviceImages.map((e) => base64Encode(e.readAsBytesSync())).toList();
|
|
|
|
|
|
|
|
if (_serviceRequest.audio != null) {
|
|
|
|
|
|
|
|
final file = File(_serviceRequest.audio!);
|
|
|
|
|
|
|
|
_serviceRequest.audio = base64Encode(file.readAsBytesSync());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int status = await _serviceRequestsProvider.createRequest(
|
|
|
|
|
|
|
|
user: UserApiClient().user!,
|
|
|
|
|
|
|
|
host: _settingProvider.host ?? "",
|
|
|
|
|
|
|
|
serviceRequest: _serviceRequest,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
_isLoading = false;
|
|
|
|
|
|
|
|
setState(() {});
|
|
|
|
|
|
|
|
if (status >= 200 && status < 300) {
|
|
|
|
|
|
|
|
Fluttertoast.showToast(
|
|
|
|
|
|
|
|
msg: _subtitle.requestCompleteSuccessfully,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
String errorMessage = HttpStatusManger.getStatusMessage(status: status, subtitle: _subtitle);
|
|
|
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
|
|
|
|
|
|
|
content: Text(errorMessage),
|
|
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
ABackButton(),
|
|
|
|
const ABackButton(),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|