attachments method
Widget
attachments(
{ - dynamic component,
- required double parentWidth,
})
Implementation
Widget attachments({var component, required double parentWidth}) {
AttachmentsController controller = AttachmentsController();
return Obx(() {
if (component["files"] != null && controller.pressedBool.isFalse) {
controller.files.addAll(component["files"]);
controller.presentFilesAdded();
}
return SizedBox(
width: (component["cssClass"] != null && component["cssClass"] != "")
? SwitchCase().componentWidthSC(
component["cssClass"],
{
"layout_1by8_col": Get.width * 0.1,
"layout_1_col": Get.width * 0.2,
"layout_2_col": Get.width * 0.4,
"layout_3_col": Get.width * 0.68,
"layout_4_col": Get.width,
},
parentWidth * 0.2)
: parentWidth * 0.2,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
AltComponent().altComponentLabel(
component: component,
label: (component["security"] != null &&
component["security"]["fieldLabel"] != null &&
component["security"]["fieldLabel"] != "")
? component["security"]["fieldLabel"]
: component["name"]),
if (controller.files.isNotEmpty)
for (var file in controller.files)
Padding(
padding: const EdgeInsets.only(bottom: 8),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
child:
Text(file["fileName"], style: attachmentTxtStyle),
),
Text(" (323K)", style: attachmentTxtStyle),
TextButton(
style: ButtonStyle(
overlayColor: MaterialStateProperty.all<Color>(
Colors.transparent),
padding:
MaterialStateProperty.all<EdgeInsetsGeometry>(
EdgeInsets.zero),
minimumSize: MaterialStateProperty.all<Size>(
const Size(20, 20)),
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
alignment: Alignment.centerLeft),
onPressed: () {
controller.files.remove(file);
},
child: Text(" [X]", style: attachmentTxtStyle),
),
],
),
),
TextButton(
onPressed: () {
controller.uploadFile();
},
style: TextButton.styleFrom(
padding: EdgeInsets.zero,
minimumSize: const Size(30, 30),
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
alignment: Alignment.centerLeft),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(componentBorderRadius),
color: Palette.buttonComponentColor),
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: attachmentHorizontalSpacing,
vertical: attachmentVerticalSpacing),
child: Text("Attach file",
style: attachmentButtonComponentTxtStyle),
),
),
),
AltComponent().altComponentInstruction(component: component)
],
),
);
});
}