import 'package:flutter/material.dart'; import 'package:flutter_svg/svg.dart'; import 'package:provider/provider.dart'; import 'package:test_sa/controllers/providers/api/asset_transfer_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/string_extensions.dart'; import 'package:test_sa/extensions/widget_extensions.dart'; import 'package:test_sa/models/device/asset_transfer.dart'; import 'package:test_sa/views/app_style/colors.dart'; import 'package:test_sa/views/app_style/sizing.dart'; import 'package:test_sa/views/pages/device_transfer/update_device_transfer.dart'; import 'package:test_sa/views/widgets/loaders/app_loading.dart'; import 'package:test_sa/views/widgets/loaders/loading_manager.dart'; import '../../../extensions/text_extensions.dart'; import '../../../models/enums/user_types.dart'; import '../../../new_views/app_style/app_color.dart'; import '../../../new_views/common_widgets/default_app_bar.dart'; import '../../widgets/requests/request_status.dart'; class DeviceTransferDetails extends StatefulWidget { final AssetTransfer model; const DeviceTransferDetails({Key key, this.model}) : super(key: key); @override State createState() => _DeviceTransferDetailsState(); } class _DeviceTransferDetailsState extends State { AssetTransfer _model; UserProvider _userProvider; bool _isLoading = false; final GlobalKey _formKey = GlobalKey(); final GlobalKey _scaffoldKey = GlobalKey(); @override void initState() { _model = widget.model; super.initState(); } Future _getDeviceTransfer() async { _model = await Provider.of(context).getRequestById(assetTransferId: widget.model.id); } @override Widget build(BuildContext context) { return Scaffold( appBar: DefaultAppBar(title: context.translation.deviceTransferDetails), key: _scaffoldKey, body: SafeArea( child: FutureBuilder( future: _getDeviceTransfer(), builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { return const ALoading(); } else { _userProvider = Provider.of(context); return Form( key: _formKey, child: LoadingManager( isLoading: _isLoading, isFailedLoading: false, stateCode: 200, onRefresh: () async {}, child: Column( children: [ _buildDetailsCard( Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Text(context.translation.transferDetails, style: AppTextStyles.heading5.copyWith(color: const Color(0xFF3B3D4A))), 8.height, Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ _buildTextWidget('${context.translation.assetName} : ${_model.assetName}'), _buildTextWidget('${context.translation.assetNumber} : ${_model.assetNumber}'), _buildTextWidget('${context.translation.model} : ${_model.modelName}'), _buildTextWidget('${context.translation.sn} : ${_model.assetSerialNo}'), ], ), 8.height, ], ).expanded, Column( crossAxisAlignment: CrossAxisAlignment.end, children: [ /// TBD // Row( // children: [ // /// TBD // // StatusLabel( // // label: "", // // id: 0, // // textColor: AColors.getPriorityStatusTextColor(0), // // backgroundColor: AColors.getPriorityStatusColor(0)), // 8.width, // // /// TBD // //StatusLabel(label: '', textColor: AColors.getRequestStatusTextColor(0), backgroundColor: AColors.getRequestStatusColor(0)), // ], // ), 1.width, Text(widget.model.createdOn != null ? widget.model.createdOn.toServiceRequestCardFormat : "", textAlign: TextAlign.end, style: AppTextStyles.tinyFont.copyWith(color: const Color(0xFF3B3D4A))), ], ), ], ).paddingAll(14), ), // sender card _buildCard( isSender: true, site: _model.senderSiteName ?? "", /// TBD unit: _model.senderDepartmentName ?? "", comment: _model.senderComment ?? "", /// TBD statusLabel: _model.senderMachineStatusName != null ? StatusLabel( label: _model.senderMachineStatusName, id: _model.senderMachineStatusId, textColor: AColors.getRequestStatusTextColor(getIdstatus(_model.senderMachineStatusName)), backgroundColor: AColors.getRequestStatusColor(getIdstatus(_model.senderMachineStatusName))) : null, ), // receiver card _buildCard( isSender: false, site: _model.destSiteName ?? "", /// TBD unit: _model.destDepartmentName ?? "", comment: _model.receiverComment ?? "", /// TBD statusLabel: _model.receiverMachineStatusName != null ? StatusLabel( label: _model.receiverMachineStatusName ?? "", id: _model.receiverMachineStatusId, textColor: AColors.getRequestStatusTextColor(getIdstatus(_model.receiverMachineStatusName)), backgroundColor: AColors.getRequestStatusColor(getIdstatus(_model.receiverMachineStatusName))) : null, ), ], ), ), ); } }, ), ), ); } _buildDetailsCard(Widget widget) { return widget.paddingOnly(top: 14, start: 14, end: 14); } _buildTextWidget(String text) { return Text( text, style: AppTextStyles.bodyText.copyWith(color: Color(0xFF757575)), ); } _buildCard({@required String site, @required String unit, @required String comment, @required bool isSender, StatusLabel statusLabel}) { return Container( decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(AppStyle.getBorderRadius(context)), ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ statusLabel ?? Container(), 8.height, Text(isSender ? context.translation.senderDetails : context.translation.receiverDetails, style: AppTextStyles.heading5.copyWith(color: const Color(0xFF3B3D4A))), ], ), if ((_userProvider.user?.type == UsersTypes.engineer) && (isSender ? _model.senderMachineStatusName != "Closed" : _model.receiverMachineStatusName != "Closed")) CircleAvatar( radius: 25, backgroundColor: AppColor.neutral30, child: CircleAvatar( radius: 24, backgroundColor: Colors.white, child: Padding( padding: const EdgeInsets.only(left: 3.0), child: SvgPicture.asset('assets/images/update.svg'), ), ), ).onPress(isSender ? () { Navigator.of(context).push(MaterialPageRoute(builder: (_) => UpdateDeviceTransfer(model: _model, isSender: isSender))); } : () { Navigator.of(context).push(MaterialPageRoute(builder: (_) => UpdateDeviceTransfer(model: _model, isSender: isSender))); }), ], ), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ _buildTextWidget('${context.translation.site} : $site'), _buildTextWidget('${context.translation.unite} : $unit'), 8.height, const Divider(color: Color(0xFFEAF1F4), height: 1, thickness: 1), 8.height, _buildTextWidget(comment), ], ), 8.height, ], ).paddingAll(14), ).paddingOnly(top: 14, start: 14, end: 14); } int getIdstatus(String status) { switch (status) { case "Closed": return 3; break; case "Open": return 1; break; case "In Progress": return 2; break; } } }