From 0d06d07e0f7e2bd42672e67dc31cee62462bcbce Mon Sep 17 00:00:00 2001
From: Oliver Walters <oliver.henry.walters@gmail.com>
Date: Mon, 20 Jun 2022 15:32:36 +1000
Subject: [PATCH] Adds ability to display "links" uploaded to attachment fields

---
 assets/release_notes.md           |  3 ++-
 lib/widget/attachment_widget.dart | 35 ++++++++++++++++++++++++-------
 2 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/assets/release_notes.md b/assets/release_notes.md
index 4c172f6c..fe7cd9b7 100644
--- a/assets/release_notes.md
+++ b/assets/release_notes.md
@@ -4,7 +4,8 @@
 ### 0.7.3 - June 2022
 ---
 
--
+- Adds ability to display link URLs in attachments view
+- Updated translations
 
 ### 0.7.2 - June 2022
 ---
diff --git a/lib/widget/attachment_widget.dart b/lib/widget/attachment_widget.dart
index 96535539..8437ae7a 100644
--- a/lib/widget/attachment_widget.dart
+++ b/lib/widget/attachment_widget.dart
@@ -9,11 +9,13 @@ import "dart:io";
 
 import "package:flutter/material.dart";
 import "package:font_awesome_flutter/font_awesome_flutter.dart";
+import "package:inventree/app_colors.dart";
 import "package:inventree/inventree/model.dart";
 import "package:inventree/widget/fields.dart";
 import "package:inventree/widget/snacks.dart";
 import "package:inventree/widget/refreshable_state.dart";
 import "package:inventree/l10.dart";
+import "package:url_launcher/url_launcher.dart";
 
 class AttachmentWidget extends StatefulWidget {
 
@@ -114,15 +116,32 @@ class _AttachmentWidgetState extends RefreshableState<AttachmentWidget> {
 
     List<Widget> tiles = [];
 
+    // An "attachment" can either be a file, or a URL
     for (var attachment in attachments) {
-      tiles.add(ListTile(
-        title: Text(attachment.filename),
-        subtitle: Text(attachment.comment),
-        leading: FaIcon(attachment.icon),
-        onTap: () async {
-          await attachment.downloadAttachment();
-        },
-      ));
+
+      if (attachment.filename.isNotEmpty) {
+        tiles.add(ListTile(
+          title: Text(attachment.filename),
+          subtitle: Text(attachment.comment),
+          leading: FaIcon(attachment.icon, color: COLOR_CLICK),
+          onTap: () async {
+            await attachment.downloadAttachment();
+          },
+        ));
+      }
+
+      else if (attachment.link.isNotEmpty) {
+        tiles.add(ListTile(
+          title: Text(attachment.link),
+          subtitle: Text(attachment.comment),
+          leading: FaIcon(FontAwesomeIcons.link, color: COLOR_CLICK),
+          onTap: () async {
+            if (await canLaunch(attachment.link)) {
+              await launch(attachment.link);
+            }
+          }
+        ));
+      }
     }
 
     if (tiles.isEmpty) {