added form design for installation and pullout, handle pullout type task and other improvements
parent
af6ae868d7
commit
4f9f76515d
@ -0,0 +1,25 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:test_sa/modules/loan_module/models/loan_form_model.dart';
|
||||
|
||||
class LoanInstallationPullOutFormModel {
|
||||
String? snNo;
|
||||
DateTime? date;
|
||||
Uint8List? signature;
|
||||
List<LoanAttachments>? loanAttachment;
|
||||
|
||||
LoanInstallationPullOutFormModel({
|
||||
this.loanAttachment,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
//Need to check payload parm they need
|
||||
return {
|
||||
'snNo': snNo,
|
||||
'InstallationDate': date?.toIso8601String(),
|
||||
"loanAttachments": loanAttachment != null ? loanAttachment!.map((v) => v.toJson()).toList() : [],
|
||||
"signature": signature != null ? "${DateTime.now().toIso8601String()}.png|${base64Encode(signature!)}" : null,
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,152 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:test_sa/extensions/context_extension.dart';
|
||||
import 'package:test_sa/extensions/int_extensions.dart';
|
||||
import 'package:test_sa/extensions/string_extensions.dart';
|
||||
import 'package:test_sa/extensions/text_extensions.dart';
|
||||
import 'package:test_sa/extensions/widget_extensions.dart';
|
||||
import 'package:test_sa/models/generic_attachment_model.dart';
|
||||
import 'package:test_sa/modules/cm_module/views/components/action_button/footer_action_button.dart';
|
||||
import 'package:test_sa/modules/loan_module/models/loan_installation_pullout_form_model.dart';
|
||||
import 'package:test_sa/new_views/app_style/app_color.dart';
|
||||
import 'package:test_sa/new_views/common_widgets/app_filled_button.dart';
|
||||
import 'package:test_sa/new_views/common_widgets/app_text_form_field.dart';
|
||||
import 'package:test_sa/new_views/common_widgets/default_app_bar.dart';
|
||||
import 'package:test_sa/views/widgets/date_and_time/date_picker.dart';
|
||||
import 'package:test_sa/views/widgets/e_signature/e_signature.dart';
|
||||
import 'package:test_sa/views/widgets/images/multi_image_picker.dart';
|
||||
|
||||
class InstallationPullOutFormView extends StatefulWidget {
|
||||
final bool isPullout;
|
||||
const InstallationPullOutFormView({super.key,required this.isPullout});
|
||||
|
||||
@override
|
||||
State<InstallationPullOutFormView> createState() => _InstallationPullOutFormViewState();
|
||||
}
|
||||
|
||||
class _InstallationPullOutFormViewState extends State<InstallationPullOutFormView> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final _snController = TextEditingController();
|
||||
List<GenericAttachmentModel> _attachments = [];
|
||||
final _formData = LoanInstallationPullOutFormModel();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_snController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _pickInstallationDate(DateTime date) async {
|
||||
final time = await showTimePicker(
|
||||
context: context,
|
||||
initialTime: TimeOfDay.now(),
|
||||
);
|
||||
if (time == null) return;
|
||||
setState(() {
|
||||
_formData.date = DateTime(
|
||||
date.year,
|
||||
date.month,
|
||||
date.day,
|
||||
time.hour,
|
||||
time.minute,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void _onSignatureChanged(Uint8List signature) {
|
||||
if (signature.isEmpty) return;
|
||||
setState(() {
|
||||
_formData.signature = signature;
|
||||
});
|
||||
}
|
||||
|
||||
void _submitForm() {
|
||||
if (!_formKey.currentState!.validate()) return;
|
||||
//Validation if required .
|
||||
|
||||
// if (_formData.date == null) {
|
||||
// context.showSnackBar('Please select installation date');
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if (_formData.signature == null || _formData.signature!.isEmpty) {
|
||||
// context.showSnackBar('Signature is required');
|
||||
// return;
|
||||
// }
|
||||
|
||||
_formData.snNo = _snController.text;
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: DefaultAppBar(title: 'Installation Report'.addTranslation),
|
||||
body: SafeArea(
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
children: [
|
||||
SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if(widget.isPullout==false)...[
|
||||
AppTextFormField(
|
||||
controller: _snController,
|
||||
labelText: context.translation.snNo,
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
textAlign: TextAlign.center,
|
||||
labelStyle: AppTextStyles.textFieldLabelStyle,
|
||||
hintStyle: AppTextStyles.textFieldLabelStyle,
|
||||
textInputType: TextInputType.text,
|
||||
textInputAction: TextInputAction.next,
|
||||
showShadow: false,
|
||||
validator: (v) =>
|
||||
(v == null || v.isEmpty) ? 'Required' : null,
|
||||
),
|
||||
8.height,
|
||||
],
|
||||
ADatePicker(
|
||||
label: widget.isPullout?"Installation Date".addTranslation:"Installation Date".addTranslation,
|
||||
hideShadow: true,
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
to: DateTime.now().add(const Duration(days: 365)),
|
||||
formatDateWithTime: true,
|
||||
onDatePicker: _pickInstallationDate,
|
||||
),
|
||||
8.height,
|
||||
ESignature(
|
||||
title: 'End-user signature'.addTranslation,
|
||||
backgroundColor: AppColor.fieldBgColor(context),
|
||||
showShadow: false,
|
||||
oldSignature:'',
|
||||
newSignature: _formData.signature,
|
||||
onChange: _onSignatureChanged,
|
||||
),
|
||||
24.height,
|
||||
AttachmentPicker(
|
||||
label: context.translation.attachments,
|
||||
attachment: _attachments,
|
||||
),
|
||||
],
|
||||
).toShadowContainer(context, borderRadius: 20),
|
||||
).expanded,
|
||||
FooterActionButton.footerContainer(
|
||||
context: context,
|
||||
child: AppFilledButton(
|
||||
buttonColor: AppColor.primary10,
|
||||
label: context.translation.submitRequest,
|
||||
onPressed: _submitForm,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue