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.
150 lines
6.3 KiB
Dart
150 lines
6.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:test_sa/controllers/providers/api/user_provider.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/device/asset.dart';
|
|
import 'package:test_sa/models/service_request/service_request.dart';
|
|
import 'package:test_sa/views/widgets/equipment/pick_asset.dart';
|
|
|
|
import '../../../../controllers/providers/api/service_requests_provider.dart';
|
|
import '../../../../models/lookup.dart';
|
|
import '../../../../new_views/app_style/app_color.dart';
|
|
import '../../../../new_views/common_widgets/app_filled_button.dart';
|
|
import '../../../../new_views/common_widgets/app_text_form_field.dart';
|
|
import '../../../../new_views/common_widgets/single_item_drop_down_menu.dart';
|
|
import '../../../../providers/service_request_providers/first_action_provider.dart';
|
|
import '../../../widgets/date_and_time/date_picker.dart';
|
|
|
|
class FirstActionBottomSheet extends StatefulWidget {
|
|
final ServiceRequest request;
|
|
|
|
const FirstActionBottomSheet({Key key, @required this.request}) : super(key: key);
|
|
|
|
@override
|
|
State<FirstActionBottomSheet> createState() => _FirstActionBottomSheetState();
|
|
}
|
|
|
|
class _FirstActionBottomSheetState extends State<FirstActionBottomSheet> {
|
|
ServiceRequest _serviceRequest;
|
|
Asset asset;
|
|
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_serviceRequest = widget.request;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final userProvider = Provider.of<UserProvider>(context, listen: false);
|
|
return Wrap(
|
|
children: [
|
|
Container(
|
|
clipBehavior: Clip.antiAlias,
|
|
margin: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
|
|
decoration: BoxDecoration(
|
|
color: Theme.of(context).scaffoldBackgroundColor,
|
|
borderRadius: const BorderRadius.only(topRight: Radius.circular(20), topLeft: Radius.circular(20)),
|
|
),
|
|
padding: EdgeInsets.symmetric(horizontal: 16.toScreenWidth, vertical: 8.toScreenHeight),
|
|
child: Form(
|
|
key: _formKey,
|
|
child: SingleChildScrollView(
|
|
child: Column(
|
|
children: [
|
|
Container(
|
|
width: 40.toScreenWidth,
|
|
height: 5.toScreenHeight,
|
|
decoration: BoxDecoration(color: AppColor.neutral40, borderRadius: BorderRadius.circular(30)),
|
|
),
|
|
Align(
|
|
alignment: AlignmentDirectional.centerStart,
|
|
child: context.translation.firstAction.heading3(context).custom(fontWeight: FontWeight.w600).paddingOnly(top: 16, bottom: 16),
|
|
),
|
|
SingleItemDropDownMenu<Lookup, FirstActionStatusProvider>(
|
|
context: context,
|
|
title: context.translation.firstActionStatus,
|
|
initialValue: _serviceRequest.firstAction,
|
|
onSelect: (value) {
|
|
setState(() {
|
|
_serviceRequest.firstAction = value;
|
|
if (_serviceRequest?.firstAction?.value != 2) {
|
|
_serviceRequest.visitDate = null;
|
|
}
|
|
});
|
|
},
|
|
),
|
|
if (_serviceRequest?.firstAction?.value == 2) 8.height,
|
|
if (_serviceRequest?.firstAction?.value == 2)
|
|
ADatePicker(
|
|
label: context.translation.visitDate,
|
|
date: DateTime.tryParse(_serviceRequest.visitDate ?? ""),
|
|
onDatePicker: (date) {
|
|
setState(() {
|
|
_serviceRequest.visitDate = date?.toIso8601String();
|
|
});
|
|
},
|
|
),
|
|
|
|
/// Loan availability not required
|
|
// 8.height,
|
|
// SingleItemDropDownMenu<Lookup, LoanAvailabilityProvider>(
|
|
// context: context,
|
|
// title: context.translation.loanAvailability,
|
|
// initialValue: _serviceRequest.loanAvailability,
|
|
// onSelect: (status) {
|
|
// setState(() {
|
|
// _serviceRequest.loanAvailability = status;
|
|
// if (_serviceRequest.loanAvailability.value != 1) {
|
|
// asset = null;
|
|
// }
|
|
// });
|
|
// },
|
|
// ),
|
|
if (_serviceRequest?.loanAvailability?.value == 1) 8.height,
|
|
if (_serviceRequest?.loanAvailability?.value == 1)
|
|
PickAsset(
|
|
device: asset ?? _serviceRequest.device,
|
|
onPickAsset: (asset) {
|
|
setState(() {
|
|
this.asset = asset;
|
|
});
|
|
},
|
|
),
|
|
8.height,
|
|
AppTextFormField(
|
|
labelText: context.translation.comments,
|
|
textInputType: TextInputType.multiline,
|
|
alignLabelWithHint: true,
|
|
onSaved: (text) {
|
|
_serviceRequest.comments = text;
|
|
},
|
|
),
|
|
16.height,
|
|
Consumer<ServiceRequestsProvider>(
|
|
builder: (context, snapshot, _) => AppFilledButton(
|
|
label: context.translation.save,
|
|
loading: snapshot.isLoading,
|
|
onPressed: () async {
|
|
_formKey.currentState.save();
|
|
_serviceRequest.device = asset;
|
|
await snapshot.updateRequest(user: userProvider.user, request: _serviceRequest);
|
|
Navigator.pop(context);
|
|
},
|
|
),
|
|
),
|
|
16.height,
|
|
],
|
|
),
|
|
),
|
|
),
|
|
)
|
|
],
|
|
);
|
|
}
|
|
}
|