decoratable_text 0.2.2

Flutter Android iOS web

Decorate a part of the text, such as changing the style and setting a tap action.

decoratable_text #

Decorate a part of the text, such as changing the style and setting a tap action.

Installing #

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

Usage #

  • Decorate url text
...
const DecoratableText(
  text: "url: https://flutter.dev/",
  decorations: [
    DecorationOption(
      pattern: TextPattern.url,
      style: TextStyle(color: Colors.blue),
      tapAction: TapAction.launchUrl,
      showRipple: true,
    ),
  ],
),
...
  • Decorate mail text
...
const DecoratableText(
  text: "mail: hogehoge@foomail.com",
  decorations: [
    DecorationOption(
      pattern: TextPattern.mail,
      style: TextStyle(color: Colors.blue),
      tapAction: TapAction.launchMail,
      showRipple: true,
    ),
  ],
),
...
  • Decorate url text and change url display
const DecoratableText(
  text:
      "You can change the text that matches the pattern. -> https://flutter.dev/",
  decorations: [
    DecorationOption(
      pattern: TextPattern.url,
      displayText: "Tap hare",
      style: TextStyle(color: Colors.blue),
      tapAction: TapAction.launchUrl,
      showRipple: true,
    ),
  ],
),
  • Decorate any text
DecoratableText(
  text: "You can set custom tap actions. #SnackBar",
  decorations: [
    DecorationOption(
      pattern: r"#[a-zA-Z0-9_]+",
      style: TextStyle(color: Colors.teal),
      onTap: () => Scaffold.of(context).showSnackBar(
        const SnackBar(
          content: Text("Tapped #SnackBar"),
        ),
      ),
      showRipple: true,
    ),
  ],
),
  • Decorate multiple texts
const DecoratableText(
  text:
      "You can set multiple decoration options. \nFlutter: https://flutter.dev/ #flutter \nDart: https://dart.dev/ #dart",
  decorations: [
    DecorationOption(
      pattern: r"#[a-zA-Z0-9_]+",
      style: _tagStyle,
    ),
    DecorationOption(
      pattern: TextPattern.url,
      style: _linkStyle,
      tapAction: TapAction.launchUrl,
      showRipple: true,
    ),
  ],
),
1
likes
110
pub points
31%
popularity

Decorate a part of the text, such as changing the style and setting a tap action.

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

strk956@gmail.com

License

MIT (LICENSE)

Dependencies

flutter, url_launcher

More

Packages that depend on decoratable_text