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.
		
		
		
		
		
			
		
			
				
	
	
		
			178 lines
		
	
	
		
			7.5 KiB
		
	
	
	
		
			Dart
		
	
			
		
		
	
	
			178 lines
		
	
	
		
			7.5 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>();
 | 
						|
 | 
						|
  Lookup firstAction;
 | 
						|
 | 
						|
  @override
 | 
						|
  void initState() {
 | 
						|
    super.initState();
 | 
						|
    _serviceRequest = widget.request;
 | 
						|
    firstAction = _serviceRequest.firstAction;
 | 
						|
  }
 | 
						|
 | 
						|
  @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: firstAction, //_serviceRequest.firstAction,
 | 
						|
                    onSelect: (value) {
 | 
						|
                      setState(() {
 | 
						|
                        //_serviceRequest.firstAction = value;
 | 
						|
                        firstAction = value;
 | 
						|
                        if (firstAction.value != 2) {
 | 
						|
                          _serviceRequest.visitDate = null;
 | 
						|
                        }
 | 
						|
                      });
 | 
						|
                    },
 | 
						|
                  ),
 | 
						|
                  if (firstAction?.value == 2) 8.height,
 | 
						|
                  if (firstAction?.value == 2)
 | 
						|
                    ADatePicker(
 | 
						|
                      label: context.translation.visitDate,
 | 
						|
                      date: DateTime.tryParse(_serviceRequest.visitDate ?? ""),
 | 
						|
                      formatDateWithTime: true,
 | 
						|
                      onDatePicker: (selectedDate) {
 | 
						|
                        if (selectedDate != null) {
 | 
						|
                          showTimePicker(
 | 
						|
                            context: context,
 | 
						|
                            initialTime: TimeOfDay.now(),
 | 
						|
                          ).then((selectedTime) {
 | 
						|
                            // Handle the selected date and time here.
 | 
						|
                            if (selectedTime != null) {
 | 
						|
                              DateTime selectedDateTime = DateTime(
 | 
						|
                                selectedDate.year,
 | 
						|
                                selectedDate.month,
 | 
						|
                                selectedDate.day,
 | 
						|
                                selectedTime.hour,
 | 
						|
                                selectedTime.minute,
 | 
						|
                              );
 | 
						|
                              if (selectedDateTime != null) {
 | 
						|
                                setState(() {
 | 
						|
                                  _serviceRequest.visitDate = selectedDateTime?.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,
 | 
						|
                    onChange: (text) {
 | 
						|
                      _serviceRequest.comments = text;
 | 
						|
                    },
 | 
						|
                    onSaved: (text) {
 | 
						|
                      _serviceRequest.comments = text;
 | 
						|
                    },
 | 
						|
                  ),
 | 
						|
                  16.height,
 | 
						|
                  Consumer<ServiceRequestsProvider>(
 | 
						|
                    builder: (context, snapshot, _) => AppFilledButton(
 | 
						|
                      label: context.translation.save,
 | 
						|
                      loading: snapshot.isLoading ?? false,
 | 
						|
                      onPressed: () async {
 | 
						|
                        _formKey.currentState.save();
 | 
						|
                        _serviceRequest.device = asset;
 | 
						|
                        _serviceRequest.firstAction = firstAction;
 | 
						|
                        await snapshot.updateRequest(user: userProvider.user, request: _serviceRequest);
 | 
						|
                        Navigator.pop(context, true);
 | 
						|
                      },
 | 
						|
                    ),
 | 
						|
                  ),
 | 
						|
                  16.height,
 | 
						|
                ],
 | 
						|
              ),
 | 
						|
            ),
 | 
						|
          ),
 | 
						|
        )
 | 
						|
      ],
 | 
						|
    );
 | 
						|
  }
 | 
						|
}
 |