decoratable_text 0.2.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 50

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,
    ),
  ],
),

0.2.2 #

  • Update README and example

0.2.1 #

  • Fix useless text splitting when decorationOptions is empty

0.2.0 #

  • Add decoration option for ripple effect
  • Change DecoratableText to subclass of StatelessWidget

0.1.0 #

  • Initial release

example/lib/main.dart

import 'package:decoratable_text/decoratable_text.dart';
import 'package:flutter/material.dart';

void main() => runApp(App());

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text("DecoratableText Example")),
        body: DecoratableTextExamples(),
      ),
    );
  }
}

class DecoratableTextExamples extends StatelessWidget {
  static const _linkStyle = TextStyle(color: Colors.blue);
  static const _idStyle = TextStyle(color: Colors.amber);
  static const _tagStyle = TextStyle(color: Colors.teal);

  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: Alignment.center,
      padding: const EdgeInsets.all(32.0),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          const DecoratableText(
            text: "url: https://flutter.dev/",
            decorations: [
              DecorationOption(
                pattern: TextPattern.url,
                style: _linkStyle,
                tapAction: TapAction.launchUrl,
                showRipple: true,
              ),
            ],
          ),
          const DecoratableText(
            text: "mail: hogehoge@foomail.com",
            decorations: [
              DecorationOption(
                pattern: TextPattern.mail,
                style: _linkStyle,
                tapAction: TapAction.launchMail,
                showRipple: true,
              ),
            ],
          ),
          const DecoratableText(
            text:
                "You can change the text that matches the pattern. -> https://flutter.dev/",
            decorations: [
              DecorationOption(
                pattern: TextPattern.url,
                displayText: "Tap hare",
                style: _linkStyle,
                tapAction: TapAction.launchUrl,
                showRipple: true,
              ),
            ],
          ),
          const DecoratableText(
            text: "@You can set custom patterns.",
            decorations: [
              DecorationOption(
                pattern: r"@[a-zA-Z0-9]+",
                style: _idStyle,
              ),
            ],
          ),
          DecoratableText(
            text: "You can set custom tap actions. #SnackBar",
            decorations: [
              DecorationOption(
                pattern: r"#[a-zA-Z0-9_]+",
                style: _tagStyle,
                onTap: () => Scaffold.of(context).showSnackBar(
                  const SnackBar(
                    content: Text("Tapped #SnackBar"),
                  ),
                ),
                showRipple: true,
              ),
            ],
          ),
          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,
              ),
            ],
          ),
        ],
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  decoratable_text: ^0.2.2

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:decoratable_text/decoratable_text.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
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]
50
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform windows

Because:

  • package:decoratable_text/decoratable_text.dart that imports:
  • package:decoratable_text/src/decoratable_text.dart that imports:
  • package:url_launcher/url_launcher.dart that declares support for platforms: android, ios, linux, macos, web

Package not compatible with SDK dart

Because:

  • decoratable_text that is a package requiring null.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
url_launcher ^5.4.5 5.5.0
Transitive dependencies
collection 1.14.12 1.14.13
flutter_web_plugins 0.0.0
meta 1.1.8 1.2.2
platform_detect 1.4.0
plugin_platform_interface 1.0.2
pub_semver 1.4.4
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
url_launcher_linux 0.0.1+1
url_launcher_macos 0.0.1+7
url_launcher_platform_interface 1.0.7
url_launcher_web 0.1.2
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test