Last active
April 11, 2025 13:40
-
-
Save bizz84/accc69b941a6903cfe4e312f68779ba9 to your computer and use it in GitHub Desktop.
Helper widget to show native-looking URLs on Flutter web
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/gestures.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:url_launcher/link.dart'; | |
/// Helper widget to show native-looking URLs on Flutter web | |
class URLTextWidget extends StatelessWidget { | |
const URLTextWidget({ | |
super.key, | |
required this.uri, | |
this.overflow = TextOverflow.ellipsis, | |
this.maxLines = 3, | |
this.style, | |
}); | |
final Uri uri; | |
final TextOverflow? overflow; | |
final int? maxLines; | |
final TextStyle? style; | |
@override | |
Widget build(BuildContext context) { | |
return Link( | |
uri: uri, | |
builder: (BuildContext context, FollowLink? followLink) => Text.rich( | |
TextSpan( | |
text: uri.toString(), | |
// Follow the URL link on tap | |
recognizer: TapGestureRecognizer()..onTap = followLink, | |
// Customize the cursor style | |
mouseCursor: SystemMouseCursors.click, | |
// Make it look like a web link | |
style: TextStyle( | |
color: Theme.of(context).colorScheme.primary, | |
decoration: TextDecoration.underline, | |
decorationColor: Theme.of(context).colorScheme.primary, | |
), | |
), | |
overflow: overflow, | |
maxLines: maxLines, | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment