Selectable Autolink Text #

Generate inline links that can be selected and tapped in text for Flutter

https://pub.dev/packages/selectable_autolink_text#-installing-tab-

import 'package:selectable_autolink_text/selectable_autolink_text.dart'; class MyHomePage extends StatelessWidget { @override Widget build(BuildContext context) { return SelectableAutoLinkText( 'Basic https://flutter.dev', linkStyle: TextStyle(color: Colors.blueAccent), highlightedLinkStyle: TextStyle( color: Colors.blueAccent, backgroundColor: Colors.blueAccent.withAlpha(0x33), ), onTap: (url) => launch(url, forceSafariVC: false), onLongPress: (url) => Share.share(url), ); } }

import 'package:selectable_autolink_text/selectable_autolink_text.dart'; import 'package:share/share.dart'; import 'package:url_launcher/url_launcher.dart'; class MyHomePage extends StatelessWidget { @override Widget build(BuildContext context) { return SelectableAutoLinkText( ''' Advanced You can shrink url like https://github.com/miyakeryo/flutter_selectable_autolink_text tel: 012-3456-7890 email: mail@example.com''', style: TextStyle(color: Colors.green[800]), linkStyle: TextStyle(color: Colors.purpleAccent), highlightedLinkStyle: TextStyle( color: Colors.purpleAccent, backgroundColor: Colors.purpleAccent.withAlpha(0x33), ), onTransformDisplayLink: AutoLinkUtils.shrinkUrl, onTap: (url) async { print('🌶Tap: $url'); if (await canLaunch(url)) { launch(url, forceSafariVC: false); } }, onLongPress: (url) { print('🍔LongPress: $url'); Share.share(url); }, ); } }

You can customize link pattern.

import 'package:selectable_autolink_text/selectable_autolink_text.dart'; class MyHomePage extends StatelessWidget { @override Widget build(BuildContext context) { return SelectableAutoLinkText( 'Custom links' '

Hi! @screen_name.' ' If you customize the regular expression, you can make them.' ' #hash_tag', linkStyle: TextStyle(color: Colors.deepOrangeAccent), highlightedLinkStyle: TextStyle( color: Colors.deepOrangeAccent, backgroundColor: Colors.deepOrangeAccent.withAlpha(0x33), ), linkRegExpPattern: '(@[\\w]+|#[\\w]+|${AutoLinkUtils.urlRegExpPattern})', onTransformDisplayLink: AutoLinkUtils.shrinkUrl, onTap: (url) => print('🍒Tap: $url'), onLongPress: (url) => print('🍩LongPress: $url'), ); } }

More advanced usage #