selectable_autolink_text 1.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 81

Selectable Autolink Text #

pub package

Generate inline links that can be selected, clicked and long pressed in text for Flutter

Example

Install #

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

Usage #

Basic #

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),
      onTap: (url) => print('🍅Tap: $url'),
      onLongPress: (url) => print('🍕LongPress: $url'),
    );    
  }
}

Advanced #

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
Selectable Autolink Text https://github.com/housmart/flutter_selectable_autolink_text
for Flutter https://flutter.dev
tel:012-3456-7890
email mail@example.com''',
      style: TextStyle(color: Colors.black87),
      linkStyle: TextStyle(color: Colors.purpleAccent),
      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);
      },
    );
  }
}

Customized #

import 'package:selectable_autolink_text/selectable_autolink_text.dart';

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return SelectableAutoLinkText(
      'Custom link @screen_name. Hello #hash_tag! Like https://twitter.com.',
      style: TextStyle(color: Colors.brown),
      linkStyle: TextStyle(color: Colors.orangeAccent),
      linkRegExpPattern: '(@[\\w]+|#[\\w]+|${AutoLinkUtils.urlRegExpPattern})',
      onTransformDisplayLink: AutoLinkUtils.shrinkUrl,
      onTap: (url) => print('🍒Tap: $url'),
      onLongPress: (url) => print('🍩LongPress: $url'),
      onDebugMatch: (match) =>
          print('DebugMatch:[${match.start}-${match.end}]`${match.group(0)}`'),
    );
  }
}

More advanced #

import 'package:selectable_autolink_text/selectable_autolink_text.dart';

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final blueStyle = const TextStyle(color: Colors.blueAccent);
    final pinkStyle = const TextStyle(color: Colors.pinkAccent);
    final bold1Style = const TextStyle(fontWeight: FontWeight.bold, fontSize: 16);
    final bold2Style = const TextStyle(fontWeight: FontWeight.bold, fontSize: 14);
    final italic2Style = const TextStyle(fontStyle: FontStyle.italic, fontSize: 14);
    final regExpPattern = r'\[([^\]]+)\]\(([\S]+)\)';
    final regExp = RegExp(regExpPattern);
    
    return SelectableAutoLinkText(
     '[More advanced usage](bold1)\n'
     '\n'
     '[This is a link text](https://google.com)\n'
     '[This text is bold](bold2)\n'
     'This text is normal\n'
     '[This text is italic](italic2)\n'
     '[This text is pink](pink)\n',
     linkRegExpPattern: regExpPattern,
     onTransformDisplayTextAttr: (s) {
       final match = regExp.firstMatch(s);
       if (match?.groupCount == 2) {
         final text1 = match.group(1);
         final text2 = match.group(2);
         switch (text2) {
           case 'bold1':
             return TextAttribute(text1, style: bold1Style);
           case 'bold2':
             return TextAttribute(text1, style: bold2Style);
           case 'italic2':
             return TextAttribute(text1, style: italic2Style);
           case 'pink':
             return TextAttribute(text1, style: pinkStyle);
           default:
             if (text2.startsWith('http')) {
               return TextAttribute(text1, style: blueStyle, link: text2);
             } else {
               return TextAttribute(text1);
             }
         }
       }
       return TextAttribute(s);
     },
     onTap: (url) => launch(url, forceSafariVC: false),
     onLongPress: (url) => Share.share(url),
   );
  }
}

[1.1.0] - 2019-11-03

  • Add More advanced usage

[1.0.1] - 2019-10-18

  • Modify AutoLinkUtils.shrinkUrl

[1.0.0+3] - 2019-09-23

  • Update CHANGELOG.md

[1.0.0+2] - 2019-09-22

  • Update README.md

[1.0.0+1] - 2019-09-22

  • Initial release.

example/README.md

example of selectable_autolink_text #

Generate inline links that can be selected, clicked and long pressed in text for Flutter

Example

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  selectable_autolink_text: ^1.1.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:selectable_autolink_text/selectable_autolink_text.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
62
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
81
Learn more about scoring.

We analyzed this package on Nov 11, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8