|
|
|
|
@ -1,11 +1,14 @@
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:test_sa/models/part.dart';
|
|
|
|
|
import 'package:test_sa/models/service_request/search_work_order.dart';
|
|
|
|
|
import 'package:test_sa/views/app_style/colors.dart';
|
|
|
|
|
|
|
|
|
|
import '../../../controllers/localization/localization.dart';
|
|
|
|
|
import '../../../models/subtitle.dart';
|
|
|
|
|
import '../../widgets/app_text_form_field.dart';
|
|
|
|
|
import '../../app_style/sizing.dart';
|
|
|
|
|
import '../../widgets/buttons/app_button.dart';
|
|
|
|
|
import '../../widgets/parts/auto_complete_parts_field.dart';
|
|
|
|
|
import '../../widgets/parts/part_item.dart';
|
|
|
|
|
import '../../widgets/titles/app_sub_title.dart';
|
|
|
|
|
|
|
|
|
|
class SparePartsBottomSheet extends StatefulWidget {
|
|
|
|
|
@ -19,6 +22,7 @@ class SparePartsBottomSheet extends StatefulWidget {
|
|
|
|
|
class _SparePartsBottomSheetState extends State<SparePartsBottomSheet> {
|
|
|
|
|
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
|
|
|
|
final SearchWorkOrder _workOrder = SearchWorkOrder();
|
|
|
|
|
bool _validate = false;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
@ -53,97 +57,92 @@ class _SparePartsBottomSheetState extends State<SparePartsBottomSheet> {
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
|
if (_workOrder.sparePartsWorkOrders?.length != null)
|
|
|
|
|
ListView.builder(
|
|
|
|
|
itemCount: _workOrder.sparePartsWorkOrders?.length,
|
|
|
|
|
shrinkWrap: true,
|
|
|
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
|
final wo = _workOrder.sparePartsWorkOrders[index];
|
|
|
|
|
return Column(
|
|
|
|
|
children: [
|
|
|
|
|
ATextFormField(
|
|
|
|
|
labelText: _workOrder?.sparePartsWorkOrders[index]?.sparePart?.partNo ?? "Part No.",
|
|
|
|
|
onChange: (value) {
|
|
|
|
|
_workOrder.sparePartsWorkOrders[index].sparePart = SparePart(partNo: value);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
// const SizedBox(height: 8),
|
|
|
|
|
// ATextFormField(
|
|
|
|
|
// labelText: "Description",
|
|
|
|
|
// hintText: "Add Some Text",
|
|
|
|
|
// textInputType: TextInputType.multiline,
|
|
|
|
|
// onSaved: (value) {
|
|
|
|
|
// _workOrder.sparePartsWorkOrders[index].sparePart = value;
|
|
|
|
|
// },
|
|
|
|
|
// ),
|
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
|
ATextFormField(
|
|
|
|
|
labelText: _workOrder?.sparePartsWorkOrders[index]?.qty?.toString() ?? "Quantity",
|
|
|
|
|
textInputType: TextInputType.number,
|
|
|
|
|
onSaved: (value) {
|
|
|
|
|
_workOrder.sparePartsWorkOrders[index].qty = double.tryParse(value ?? "");
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
|
InkWell(
|
|
|
|
|
onTap: () {
|
|
|
|
|
_workOrder.sparePartsWorkOrders.removeWhere(
|
|
|
|
|
(element) => (element.sparePart?.partNo == wo.sparePart?.partNo && element.id == wo.id),
|
|
|
|
|
);
|
|
|
|
|
setState(() {});
|
|
|
|
|
},
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
|
children: [
|
|
|
|
|
const Icon(Icons.delete, color: Colors.red),
|
|
|
|
|
Text(
|
|
|
|
|
"Remove this part",
|
|
|
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Container(
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
|
margin: const EdgeInsets.symmetric(vertical: 16),
|
|
|
|
|
decoration: BoxDecoration(color: AColors.grey, borderRadius: BorderRadius.circular(AppStyle.getBorderRadius(context)), boxShadow: const [
|
|
|
|
|
BoxShadow(
|
|
|
|
|
color: AColors.grey,
|
|
|
|
|
offset: Offset(0, -1),
|
|
|
|
|
)
|
|
|
|
|
]),
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
flex: 3,
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
ASubTitle(subtitle.partNumber),
|
|
|
|
|
_validate && _workOrder.sparePartsWorkOrders == null
|
|
|
|
|
? ASubTitle(
|
|
|
|
|
subtitle.requiredWord,
|
|
|
|
|
color: Colors.red,
|
|
|
|
|
)
|
|
|
|
|
: const SizedBox.shrink(),
|
|
|
|
|
const SizedBox(height: 4),
|
|
|
|
|
AutoCompletePartsField(
|
|
|
|
|
onPick: (part) {
|
|
|
|
|
_workOrder.sparePartsWorkOrders ??= [];
|
|
|
|
|
_workOrder.sparePartsWorkOrders.add(SparePartsWorkOrders(
|
|
|
|
|
id: part.id,
|
|
|
|
|
qty: part.quantity,
|
|
|
|
|
sparePart: SparePart(id: part.reportPartID, partName: part.name, partNo: part.code),
|
|
|
|
|
));
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
const Divider(),
|
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
|
InkWell(
|
|
|
|
|
onTap: () {
|
|
|
|
|
_workOrder.sparePartsWorkOrders ??= [];
|
|
|
|
|
_workOrder.sparePartsWorkOrders.add(SparePartsWorkOrders());
|
|
|
|
|
setState(() {});
|
|
|
|
|
},
|
|
|
|
|
child: Container(
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: AColors.primaryColor.withOpacity(0.15),
|
|
|
|
|
borderRadius: BorderRadius.circular(10),
|
|
|
|
|
border: Border.all(color: AColors.primaryColor),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: 8 * AppStyle.getScaleFactor(context),
|
|
|
|
|
),
|
|
|
|
|
child: ListTile(
|
|
|
|
|
title: Text(
|
|
|
|
|
"Add Part",
|
|
|
|
|
style: Theme.of(context).textTheme.bodyMedium?.copyWith(color: AColors.primaryColor),
|
|
|
|
|
if (_workOrder.sparePartsWorkOrders?.isNotEmpty ?? false)
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(flex: 3, child: Text(subtitle.number)),
|
|
|
|
|
Expanded(flex: 1, child: Text(subtitle.quantity)),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
trailing: const Icon(
|
|
|
|
|
Icons.add_circle,
|
|
|
|
|
color: AColors.primaryColor,
|
|
|
|
|
size: 20,
|
|
|
|
|
if (_workOrder.sparePartsWorkOrders?.isNotEmpty ?? false)
|
|
|
|
|
Column(
|
|
|
|
|
children: List.generate(_workOrder.sparePartsWorkOrders?.length, (index) {
|
|
|
|
|
final spare = _workOrder.sparePartsWorkOrders[index];
|
|
|
|
|
Part part = Part(
|
|
|
|
|
id: spare.id,
|
|
|
|
|
reportPartID: spare.sparePart?.id,
|
|
|
|
|
code: spare.sparePart?.partNo,
|
|
|
|
|
name: spare.sparePart?.partName,
|
|
|
|
|
quantity: spare.qty,
|
|
|
|
|
);
|
|
|
|
|
return PartItem(
|
|
|
|
|
part: part,
|
|
|
|
|
onDelete: (part) {
|
|
|
|
|
_workOrder.sparePartsWorkOrders.remove(SparePartsWorkOrders(
|
|
|
|
|
id: part.id,
|
|
|
|
|
qty: part.quantity,
|
|
|
|
|
sparePart: SparePart(id: part.reportPartID, partName: part.name, partNo: part.code),
|
|
|
|
|
));
|
|
|
|
|
setState(() {});
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 24),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 24),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
|