made urls in short url detail view clickable

This commit is contained in:
Adrian Baumgart 2024-03-31 21:08:58 +02:00
parent b0988fcb3d
commit 0594452584
No known key found for this signature in database

View File

@ -4,6 +4,7 @@ import 'package:intl/intl.dart';
import 'package:shlink_app/API/server_manager.dart';
import 'package:shlink_app/views/short_url_edit_view.dart';
import 'package:shlink_app/widgets/url_tags_list_widget.dart';
import 'package:url_launcher/url_launcher.dart';
import '../globals.dart' as globals;
class URLDetailView extends StatefulWidget {
@ -127,8 +128,8 @@ class _URLDetailViewState extends State<URLDetailView> {
),
),
_ListCell(title: "Short Code", content: shortURL.shortCode),
_ListCell(title: "Short URL", content: shortURL.shortUrl),
_ListCell(title: "Long URL", content: shortURL.longUrl),
_ListCell(title: "Short URL", content: shortURL.shortUrl, isUrl: true),
_ListCell(title: "Long URL", content: shortURL.longUrl, isUrl: true),
_ListCell(
title: "Creation Date", content: shortURL.dateCreated),
const _ListCell(title: "Visits", content: ""),
@ -173,12 +174,14 @@ class _ListCell extends StatefulWidget {
{required this.title,
required this.content,
this.sub = false,
this.last = false});
this.last = false,
this.isUrl = false});
final String title;
final dynamic content;
final bool sub;
final bool last;
final bool isUrl;
@override
State<_ListCell> createState() => _ListCellState();
@ -190,6 +193,15 @@ class _ListCellState extends State<_ListCell> {
return SliverToBoxAdapter(
child: Padding(
padding: EdgeInsets.only(top: 16, bottom: widget.last ? 30 : 0),
child: GestureDetector(
onTap: () async {
Uri? parsedUrl = Uri.tryParse(widget.content);
if (widget.isUrl
&& parsedUrl != null
&& await canLaunchUrl(parsedUrl)) {
launchUrl(parsedUrl);
}
},
child: Container(
padding: const EdgeInsets.only(top: 16, left: 8, right: 8),
decoration: BoxDecoration(
@ -248,6 +260,7 @@ class _ListCellState extends State<_ListCell> {
],
),
),
)
));
}
}