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.
347 lines
14 KiB
Dart
347 lines
14 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.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/modules/asset_delivery_module/models/asset_delivery_data_model.dart';
|
|
import 'package:test_sa/modules/asset_delivery_module/pages/asset_delivery_table_card_view.dart';
|
|
import 'package:test_sa/modules/asset_delivery_module/pages/change_status_bottomsheet.dart';
|
|
import 'package:test_sa/modules/asset_delivery_module/pages/delivery_inspection/delivery_inspection_form_view.dart';
|
|
import 'package:test_sa/modules/asset_delivery_module/pages/history_log_view.dart';
|
|
import 'package:test_sa/modules/asset_delivery_module/provider/asset_delivery_provider.dart';
|
|
import 'package:test_sa/new_views/app_style/app_color.dart';
|
|
import 'package:test_sa/new_views/common_widgets/app_lazy_loading.dart';
|
|
import 'package:test_sa/new_views/common_widgets/default_app_bar.dart';
|
|
import 'package:test_sa/views/widgets/loaders/no_data_found.dart';
|
|
|
|
class AssetDeliveryPage extends StatefulWidget {
|
|
final int? requestId;
|
|
final String? poInternal;
|
|
final String? poExternal;
|
|
|
|
const AssetDeliveryPage({
|
|
Key? key,
|
|
this.requestId,
|
|
this.poInternal,
|
|
this.poExternal,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
State<AssetDeliveryPage> createState() => _AssetDeliveryPageState();
|
|
}
|
|
|
|
class _AssetDeliveryPageState extends State<AssetDeliveryPage> {
|
|
AssetDeliveryDataModel? dataModel;
|
|
AssetDeliveryProvider? assetDeliveryProvider;
|
|
|
|
@override
|
|
void initState() {
|
|
assetDeliveryProvider = Provider.of<AssetDeliveryProvider>(context, listen: false);
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
getDetailsById();
|
|
});
|
|
super.initState();
|
|
}
|
|
|
|
Future<void> getDetailsById() async {
|
|
final futures = <Future>[
|
|
assetDeliveryProvider!.getAssetDeliveryDetailById(requestId: widget.requestId).then((value) => dataModel = value),
|
|
assetDeliveryProvider!.getAssetDeliveryTableListById(requestId: widget.requestId),
|
|
];
|
|
|
|
await Future.wait(futures);
|
|
}
|
|
|
|
@override
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
|
appBar: DefaultAppBar(
|
|
title: 'Asset Delivery'.addTranslation,
|
|
onBackPress: () {
|
|
Navigator.pop(context);
|
|
},
|
|
),
|
|
body: Consumer<AssetDeliveryProvider>(
|
|
builder: (context, provider, child) {
|
|
final dataModel = provider.assetDeliveryDataModel;
|
|
if (provider.isLoading) {
|
|
return const CircularProgressIndicator(color: AppColor.primary10).center;
|
|
}
|
|
if (dataModel == null) {
|
|
return const NoDataFound().center;
|
|
}
|
|
return ListView(
|
|
padding: const EdgeInsets.all(12),
|
|
children: [
|
|
requestDetailCard(context),
|
|
const Divider().defaultStyle(context),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
"Asset Delivery Table",
|
|
style: AppTextStyles.heading6.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.black10),
|
|
),
|
|
Row(
|
|
children: [
|
|
Container(
|
|
height: 24,
|
|
width: 24,
|
|
decoration: const BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
color: AppColor.primary10, // or AppColor.blueStatus(context)
|
|
),
|
|
alignment: Alignment.center,
|
|
child: const Icon(
|
|
Icons.add,
|
|
color: Colors.white,
|
|
size: 16,
|
|
),
|
|
),
|
|
4.width,
|
|
Text(
|
|
"Add more",
|
|
style: AppTextStyles.bodyText.copyWith(
|
|
color: context.isDark ? AppColor.neutral30 : AppColor.neutral50,
|
|
decoration: TextDecoration.underline,
|
|
),
|
|
),
|
|
],
|
|
).onPress(() async {
|
|
await assetDeliveryProvider?.addNewDelivery(requestId: widget.requestId).then((status) async {
|
|
if (status) {
|
|
await assetDeliveryProvider?.getAssetDeliveryTableListById(requestId: widget.requestId);
|
|
}
|
|
});
|
|
}),
|
|
],
|
|
),
|
|
8.height,
|
|
assetDeliveryTableList(context: context, assetDeliveryProvider: provider),
|
|
],
|
|
).toShadowContainer(
|
|
context,
|
|
borderRadius: 20,
|
|
padding: 0,
|
|
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
TextStyle infoTextStyle(context) => AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120);
|
|
|
|
Widget requestDetailCard(BuildContext context) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
'PO No. Internal'.addTranslation,
|
|
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.black10),
|
|
),
|
|
8.height,
|
|
Text(
|
|
widget.poInternal ?? '-',
|
|
style: AppTextStyles.bodyText2.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral120),
|
|
),
|
|
8.height,
|
|
Text(
|
|
'Client Name'.addTranslation,
|
|
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.black10),
|
|
),
|
|
8.height,
|
|
Text(
|
|
dataModel?.clientName ?? '-',
|
|
style: AppTextStyles.bodyText2.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral120),
|
|
),
|
|
// Row(
|
|
// mainAxisSize: MainAxisSize.min,
|
|
// children: [
|
|
// Checkbox(
|
|
// value: dataModel!.isHMG,
|
|
// activeColor: AppColor.neutral120,
|
|
// materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
|
// visualDensity: const VisualDensity(horizontal: -4, vertical: -3),
|
|
// onChanged: (value) {},
|
|
// ),
|
|
// 8.width,
|
|
// Text(
|
|
// 'HMG'.addTranslation,
|
|
// style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.black10),
|
|
// ),
|
|
// ],
|
|
// ),
|
|
8.height,
|
|
if (dataModel?.isHMG == true) ...[
|
|
Text(
|
|
'Operation Units'.addTranslation,
|
|
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.black10),
|
|
),
|
|
8.height,
|
|
Text(
|
|
dataModel?.operatingUnit ?? '-',
|
|
style: AppTextStyles.bodyText2.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral120),
|
|
),
|
|
] else ...[
|
|
Text(
|
|
'Site'.addTranslation,
|
|
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.black10),
|
|
),
|
|
8.height,
|
|
Text(
|
|
dataModel?.site?.siteName ?? '-',
|
|
style: AppTextStyles.bodyText2.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral120),
|
|
),
|
|
],
|
|
8.height,
|
|
Text(
|
|
'PO No.'.addTranslation,
|
|
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.black10),
|
|
),
|
|
8.height,
|
|
//Need to verify this with backend ...
|
|
// widget.poInternal?? '-',
|
|
Text(
|
|
dataModel?.isHMG == true
|
|
? dataModel?.poNumber != null
|
|
? dataModel!.poNumber.toString()
|
|
: '-'
|
|
: dataModel?.poNumber != null
|
|
? dataModel!.poNumber.toString()
|
|
: '-',
|
|
style: AppTextStyles.bodyText2.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral120),
|
|
),
|
|
8.height,
|
|
Text(
|
|
'Warranty Period'.addTranslation,
|
|
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.black10),
|
|
),
|
|
8.height,
|
|
Text(
|
|
dataModel?.warrentyPeriod != null ? dataModel!.warrentyPeriod.toString() : '-',
|
|
style: AppTextStyles.bodyText2.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral120),
|
|
),
|
|
8.height,
|
|
Text(
|
|
'Payment Term'.addTranslation,
|
|
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.black10),
|
|
),
|
|
8.height,
|
|
Text(
|
|
dataModel?.paymentTerm != null ? dataModel!.paymentTerm!.name.toString() : '-',
|
|
style: AppTextStyles.bodyText2.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral120),
|
|
),
|
|
8.height,
|
|
|
|
Text(
|
|
'Payment Terms Amount'.addTranslation,
|
|
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.black10),
|
|
),
|
|
8.height,
|
|
Text(
|
|
dataModel?.paymentTermAmount != null ? dataModel!.paymentTermAmount.toString() : '-',
|
|
style: AppTextStyles.bodyText2.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral120),
|
|
),
|
|
8.height,
|
|
Text(
|
|
'EDD (Estimated Delivery Date)'.addTranslation,
|
|
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.black10),
|
|
),
|
|
8.height,
|
|
Text(
|
|
dataModel?.edd != null ? dataModel!.edd!.toAssetDetailsFormat : '-',
|
|
style: AppTextStyles.bodyText2.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral120),
|
|
),
|
|
8.height,
|
|
Text(
|
|
'Total'.addTranslation,
|
|
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.black10),
|
|
),
|
|
8.height,
|
|
Text(
|
|
dataModel?.total != null ? dataModel!.total.toString() : '-',
|
|
style: AppTextStyles.bodyText2.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral120),
|
|
),
|
|
8.height,
|
|
Text(
|
|
'Total Invoice'.addTranslation,
|
|
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.black10),
|
|
),
|
|
8.height,
|
|
Text(
|
|
dataModel?.totalInvoice != null ? dataModel!.totalInvoice.toString() : '-',
|
|
style: AppTextStyles.bodyText2.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral120),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget assetDeliveryTableList({required BuildContext context, required AssetDeliveryProvider assetDeliveryProvider}) {
|
|
List<AssetDeliveryTableModel> assetDeliveryTableList = assetDeliveryProvider.assetDeliveryTableList;
|
|
return assetDeliveryProvider.isDeliveryTableListLoading
|
|
? SizedBox(height: 200.toScreenHeight, child: const CircularProgressIndicator(color: AppColor.primary10).center)
|
|
: assetDeliveryTableList.isEmpty
|
|
? const NoDataFound().center
|
|
: ListView.separated(
|
|
itemCount: assetDeliveryTableList.length,
|
|
separatorBuilder: (_, __) => 8.height,
|
|
padding: EdgeInsets.zero,
|
|
shrinkWrap: true,
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
itemBuilder: (listContext, itemIndex) {
|
|
AssetDeliveryTableModel model = assetDeliveryTableList[itemIndex];
|
|
return AssetDeliveryTableCard(
|
|
deliveryTableModel: model,
|
|
onCardTap: () {
|
|
//status new
|
|
if (model.status?.value == 1) {
|
|
AssetDeliveryBottomSheet.changeStatusBottomSheet(
|
|
context: context,
|
|
cancelStatusTap: () async {
|
|
showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading());
|
|
await assetDeliveryProvider.changeDeliveryStatusToCancel(itemId: model.id).then((status) async {
|
|
Navigator.pop(context);
|
|
if (status) {
|
|
Navigator.pop(context);
|
|
await assetDeliveryProvider.getAssetDeliveryTableListById(requestId: widget.requestId);
|
|
}
|
|
});
|
|
},
|
|
statusChangeTap: () async {
|
|
showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading());
|
|
await assetDeliveryProvider.changeDeliveryStatus(itemId: model.id).then((status) async {
|
|
Navigator.pop(context);
|
|
if (status) {
|
|
Navigator.pop(context);
|
|
await assetDeliveryProvider.getAssetDeliveryTableListById(requestId: widget.requestId);
|
|
}
|
|
});
|
|
});
|
|
} else {
|
|
Navigator.of(context).push(MaterialPageRoute(
|
|
builder: (_) => DeliveryInspectionFormView(
|
|
deliveryTableModel: model,
|
|
requestModel: dataModel,
|
|
),
|
|
));
|
|
}
|
|
},
|
|
onViewHistoryTap: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => AssetDeliveryHistoryLogView(
|
|
tableItemId: model.id,
|
|
)));
|
|
},
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|