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/API/server_manager.dart';
import 'package:shlink_app/views/short_url_edit_view.dart'; import 'package:shlink_app/views/short_url_edit_view.dart';
import 'package:shlink_app/widgets/url_tags_list_widget.dart'; import 'package:shlink_app/widgets/url_tags_list_widget.dart';
import 'package:url_launcher/url_launcher.dart';
import '../globals.dart' as globals; import '../globals.dart' as globals;
class URLDetailView extends StatefulWidget { class URLDetailView extends StatefulWidget {
@ -127,8 +128,8 @@ class _URLDetailViewState extends State<URLDetailView> {
), ),
), ),
_ListCell(title: "Short Code", content: shortURL.shortCode), _ListCell(title: "Short Code", content: shortURL.shortCode),
_ListCell(title: "Short URL", content: shortURL.shortUrl), _ListCell(title: "Short URL", content: shortURL.shortUrl, isUrl: true),
_ListCell(title: "Long URL", content: shortURL.longUrl), _ListCell(title: "Long URL", content: shortURL.longUrl, isUrl: true),
_ListCell( _ListCell(
title: "Creation Date", content: shortURL.dateCreated), title: "Creation Date", content: shortURL.dateCreated),
const _ListCell(title: "Visits", content: ""), const _ListCell(title: "Visits", content: ""),
@ -173,12 +174,14 @@ class _ListCell extends StatefulWidget {
{required this.title, {required this.title,
required this.content, required this.content,
this.sub = false, this.sub = false,
this.last = false}); this.last = false,
this.isUrl = false});
final String title; final String title;
final dynamic content; final dynamic content;
final bool sub; final bool sub;
final bool last; final bool last;
final bool isUrl;
@override @override
State<_ListCell> createState() => _ListCellState(); State<_ListCell> createState() => _ListCellState();
@ -190,64 +193,74 @@ class _ListCellState extends State<_ListCell> {
return SliverToBoxAdapter( return SliverToBoxAdapter(
child: Padding( child: Padding(
padding: EdgeInsets.only(top: 16, bottom: widget.last ? 30 : 0), padding: EdgeInsets.only(top: 16, bottom: widget.last ? 30 : 0),
child: Container( child: GestureDetector(
padding: const EdgeInsets.only(top: 16, left: 8, right: 8), onTap: () async {
decoration: BoxDecoration( Uri? parsedUrl = Uri.tryParse(widget.content);
border: Border( if (widget.isUrl
top: BorderSide( && parsedUrl != null
color: MediaQuery.of(context).platformBrightness == && await canLaunchUrl(parsedUrl)) {
Brightness.dark launchUrl(parsedUrl);
? Colors.grey[800]! }
: Colors.grey[300]!)), },
), child: Container(
child: Row( padding: const EdgeInsets.only(top: 16, left: 8, right: 8),
mainAxisAlignment: MainAxisAlignment.spaceBetween, decoration: BoxDecoration(
children: [ border: Border(
Row( top: BorderSide(
children: [ color: MediaQuery.of(context).platformBrightness ==
if (widget.sub) Brightness.dark
Padding( ? Colors.grey[800]!
padding: const EdgeInsets.only(right: 4), : Colors.grey[300]!)),
child: SizedBox( ),
width: 20, child: Row(
height: 6, mainAxisAlignment: MainAxisAlignment.spaceBetween,
child: Container( children: [
decoration: BoxDecoration( Row(
borderRadius: BorderRadius.circular(8), children: [
color: Theme.of(context).brightness == Brightness.dark if (widget.sub)
? Colors.grey[700] Padding(
: Colors.grey[300], padding: const EdgeInsets.only(right: 4),
child: SizedBox(
width: 20,
height: 6,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
color: Theme.of(context).brightness == Brightness.dark
? Colors.grey[700]
: Colors.grey[300],
),
), ),
), ),
), ),
), Text(
Text( widget.title,
widget.title, style: const TextStyle(fontWeight: FontWeight.bold),
style: const TextStyle(fontWeight: FontWeight.bold), )
) ],
], ),
), if (widget.content is bool)
if (widget.content is bool) Icon(widget.content ? Icons.check : Icons.close,
Icon(widget.content ? Icons.check : Icons.close, color: widget.content ? Colors.green : Colors.red)
color: widget.content ? Colors.green : Colors.red) else if (widget.content is int)
else if (widget.content is int) Text(widget.content.toString())
Text(widget.content.toString()) else if (widget.content is String)
else if (widget.content is String) Expanded(
Expanded( child: Text(
child: Text( widget.content,
widget.content, textAlign: TextAlign.end,
textAlign: TextAlign.end, overflow: TextOverflow.ellipsis,
overflow: TextOverflow.ellipsis, maxLines: 1,
maxLines: 1, ),
), )
) else if (widget.content is DateTime)
else if (widget.content is DateTime) Text(DateFormat('yyyy-MM-dd - HH:mm').format(widget.content))
Text(DateFormat('yyyy-MM-dd - HH:mm').format(widget.content)) else
else const Text("N/A")
const Text("N/A") ],
], ),
), ),
), )
)); ));
} }
} }