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.
128 lines
5.1 KiB
Dart
128 lines
5.1 KiB
Dart
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:test_sa/extensions/context_extension.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/asset_delivery_module/provider/asset_delivery_provider.dart';
|
|
import 'package:test_sa/modules/cm_module/cm_request_utils.dart';
|
|
import 'package:test_sa/modules/cm_module/views/components/action_button/footer_action_button.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_lazy_loading.dart';
|
|
import 'package:test_sa/new_views/common_widgets/default_app_bar.dart';
|
|
import 'package:test_sa/views/widgets/images/multi_image_picker.dart';
|
|
|
|
class AssetDeliveryAttachmentView extends StatefulWidget {
|
|
///Need to check which parm need here.
|
|
final int? lineId;
|
|
final int? tableItemId;
|
|
final int? requestId;
|
|
final bool? isHmg;
|
|
|
|
const AssetDeliveryAttachmentView({
|
|
super.key,
|
|
this.lineId,
|
|
this.requestId,
|
|
this.tableItemId,
|
|
this.isHmg,
|
|
});
|
|
|
|
@override
|
|
State<AssetDeliveryAttachmentView> createState() => _AssetDeliveryAttachmentViewState();
|
|
}
|
|
|
|
class _AssetDeliveryAttachmentViewState extends State<AssetDeliveryAttachmentView> {
|
|
List<GenericAttachmentModel> _attachments = [];
|
|
bool isLoading = false;
|
|
late AssetDeliveryProvider assetDeliveryProvider;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
assetDeliveryProvider = Provider.of<AssetDeliveryProvider>(context, listen: false);
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
getInitialData();
|
|
});
|
|
}
|
|
|
|
void getInitialData() async {
|
|
///get previoues Attachment from Apis.
|
|
isLoading = true;
|
|
setState(() {});
|
|
_attachments = await assetDeliveryProvider.getAttachments(tableItemId: widget.tableItemId);
|
|
isLoading = false;
|
|
setState(() {});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
|
appBar: DefaultAppBar(
|
|
title: 'Attachments'.addTranslation,
|
|
onBackPress: () {
|
|
Navigator.pop(context);
|
|
},
|
|
),
|
|
body: isLoading
|
|
? const CircularProgressIndicator(color: AppColor.primary10).center
|
|
: Column(
|
|
children: [
|
|
AttachmentPicker(
|
|
label: context.translation.attachments,
|
|
attachment: _attachments,
|
|
buttonColor: AppColor.primary10,
|
|
onlyImages: false,
|
|
showAsListView: true,
|
|
// showAsGrid: true,
|
|
buttonIcon: 'quotation_icon'.toSvgAsset(color: AppColor.primary10),
|
|
onChange: (attachment) {},
|
|
)
|
|
.toShadowContainer(
|
|
context,
|
|
borderRadius: 20,
|
|
padding: 12,
|
|
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
)
|
|
.expanded,
|
|
FooterActionButton.footerContainer(
|
|
context: context,
|
|
child: AppFilledButton(
|
|
buttonColor: AppColor.primary10,
|
|
label: 'Save'.addTranslation,
|
|
maxWidth: true,
|
|
onPressed: () async {
|
|
List<GenericAttachmentModel> attachement = [];
|
|
for (var item in _attachments) {
|
|
String fileName =
|
|
CMRequestUtils.isLocalUrl(item.name ?? '') ? ("${item.name ?? ''.split("/").last}|${base64Encode(File(item.name ?? '').readAsBytesSync())}") : item.name ?? '';
|
|
attachement.add(GenericAttachmentModel(id: item.id ?? 0, name: fileName));
|
|
}
|
|
showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading());
|
|
Map<String, dynamic> payLoad = {
|
|
'assetDeliveryExternalDeliveryId': widget.tableItemId,
|
|
'attachments': attachement,
|
|
};
|
|
await assetDeliveryProvider.saveAttachment(payload: payLoad).then((status) async {
|
|
Navigator.pop(context);
|
|
if (status) {
|
|
///Need to verify need to stay on this page and refresh or go back..
|
|
Navigator.pop(context);
|
|
// assetDeliveryProvider.getDeliveryLinesListById(
|
|
// itemId: widget.tableItemId,
|
|
// );
|
|
}
|
|
});
|
|
}),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|