easy_rich_text_ontap 0.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 46

easy_rich_text_ontap #

这个包由easy_rich_text包修改而来,将原包中的EasyRichTextPattern新增了onTap事件,接收其自身的targetString为参数

This widget split string into multiple TextSpan by defining a List of EasyRichTextPattern();

The EasyRichTextPattern is a class defines the text pattern you want to format.

查看原包

Getting Started #

Installing: #

dependencies:
  easy_rich_text: '^0.1.1'

Simple example:

alt text

String str1 = "This is a EasyRichText example. I want blue font. I want bold font. I want italic font. ";

EasyRichText(
  str1,
  patternList: [
    EasyRichTextPattern(
      targetString: 'blue',
      style: TextStyle(color: Colors.blue),
    ),
    EasyRichTextPattern(
      targetString: 'bold',
      style: TextStyle(fontWeight: FontWeight.bold),
    ),
    EasyRichTextPattern(
      targetString: 'italic',
      style: TextStyle(fontStyle: FontStyle.italic),
      onTap: (String str){
          print(str);   // italic
      },
    ),
  ],
),

Default Style:

alt text

String str2 = "This is a EasyRichText example with default grey font. I want blue font here.";

EasyRichText(
  str2,
  defaultStyle: TextStyle(color: Colors.grey),
  patternList: [
    EasyRichTextPattern(
      targetString: 'blue',
      style: TextStyle(color: Colors.blue),
    ),
    EasyRichTextPattern(
      targetString: 'bold',
      style: TextStyle(fontWeight: FontWeight.bold),
    ),
  ],
),

superscript and subscript.

alt text

String str3 = "This is a EasyRichText example. I want blue superscript font here. I want no blue font here";

EasyRichText(
  str3,
  patternList: [
    EasyRichTextPattern(
        targetString: 'blue',
        stringBeforeTarget: 'want',
        style: TextStyle(color: Colors.blue),
        superScript: true),
  ],
  textAlign: TextAlign.justify,
),

All RichText properties accessible: textAlign, maxLines, overflow, etc.

alt text

String str4 = "This is a EasyRichText example. I want blue font here. TextOverflow.ellipsis, TextAlign.justify, maxLines: 1";

EasyRichText(
  str4,
  patternList: [
    EasyRichTextPattern(
      targetString: 'blue',
      stringBeforeTarget: 'want',
      style: TextStyle(color: Colors.blue),
    ),
  ],
  textAlign: TextAlign.justify,
  maxLines: 1,
  overflow: TextOverflow.ellipsis,
),

Known issues

Conflict when one target string is included in another target string

alt text

String str6 = "This is a EasyRichText example. I want whole sentence blue. I want whole sentence bold.";

EasyRichText(
  str6,
  patternList: [
    EasyRichTextPattern(
      targetString: 'blue',
      style: TextStyle(color: Colors.blue),
    ),
    EasyRichTextPattern(
      targetString: 'I want whole sentence blue',
      style: TextStyle(fontWeight: FontWeight.bold),
    ),
    EasyRichTextPattern(
      targetString: 'I want whole sentence bold',
      style: TextStyle(fontWeight: FontWeight.bold),
    ),
  ],
),
not all characters support superscript and subscript

Characters do not support superscript: q z C F Q S X Y Z.

Only these characters support subscript: e h i j k l m n o p r s t u v x.

[0.0.1] - 2019-11-18. #

[0.0.2] - 2019-11-18. #

  • initial EasyRichText release.

[0.1.0] - 2019-11-19. #

  • update readme

[0.2.0] - 2019-11-07 #

  • use List

[0.2.1] - 2019-12-07 #

  • Update readme

[0.2.2] - 2019-12-07 #

  • Update readme

[0.1.1] - 2020-04-16 #

  • 为EasyRichTextPattern增加点击事件支持

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:easy_rich_text_ontap/easy_rich_text.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'EasyRichText Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'EasyRichText Demo'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    String str1 =
        "This is a EasyRichText example. I want blue font. I want bold font. I want italic font. ";
    String str2 =
        "This is a EasyRichText example with default grey font. I want blue font here.";
    String str3 =
        "This is a EasyRichText example. I want blue superscript font here. I want no blue font here";
    String str4 =
        "This is a EasyRichText example. I want blue font here. TextOverflow.ellipsis, TextAlign.justify, maxLines: 1";
    String str6 =
        "This is a EasyRichText example. I want whole sentence blue. I want whole sentence bold.";
    return Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: <Widget>[
              EasyRichText(
                str1,
                patternList: [
                  EasyRichTextPattern(
                    targetString: 'blue',
                    style: TextStyle(color: Colors.blue),
                  ),
                  EasyRichTextPattern(
                    targetString: 'bold',
                    style: TextStyle(fontWeight: FontWeight.bold),
                  ),
                  EasyRichTextPattern(
                    targetString: 'italic',
                    style: TextStyle(fontStyle: FontStyle.italic),
                  ),
                ],
              ),
              EasyRichText(
                str2,
                defaultStyle: TextStyle(color: Colors.grey),
                patternList: [
                  EasyRichTextPattern(
                    targetString: 'blue',
                    style: TextStyle(color: Colors.blue),
                  ),
                  EasyRichTextPattern(
                    targetString: 'bold',
                    style: TextStyle(fontWeight: FontWeight.bold),
                  ),
                ],
              ),
              EasyRichText(
                str3,
                patternList: [
                  EasyRichTextPattern(
                      targetString: 'blue',
                      stringBeforeTarget: 'want',
                      style: TextStyle(color: Colors.blue),
                      superScript: true),
                ],
                textAlign: TextAlign.justify,
              ),
              EasyRichText(
                str4,
                patternList: [
                  EasyRichTextPattern(
                    targetString: 'blue',
                    stringBeforeTarget: 'want',
                    style: TextStyle(color: Colors.blue),
                  ),
                ],
                textAlign: TextAlign.justify,
                maxLines: 1,
                overflow: TextOverflow.ellipsis,
              ),
              EasyRichText(
                str6,
                patternList: [
                  EasyRichTextPattern(
                    targetString: 'blue',
                    style: TextStyle(color: Colors.blue),
                  ),
                  EasyRichTextPattern(
                    targetString: 'I want whole sentence blue',
                    style: TextStyle(fontWeight: FontWeight.bold),
                  ),
                  EasyRichTextPattern(
                    targetString: 'I want whole sentence bold',
                    style: TextStyle(fontWeight: FontWeight.bold),
                    onTap: (String str){
                      print(str);
                    }
                  ),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  easy_rich_text_ontap: ^0.1.1

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:easy_rich_text_ontap/easy_rich_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]
80
Overall:
Weighted score of the above. [more]
46
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

because of import path [easy_rich_text_ontap] that is in a package requiring null.

Health suggestions

Fix lib/src/easy_rich_text.dart. (-0.50 points)

Analysis of lib/src/easy_rich_text.dart reported 1 hint:

line 102 col 12: The value of the local variable 'ontap' isn't used.

Format lib/easy_rich_text.dart.

Run flutter format to format lib/easy_rich_text.dart.

Format lib/src/easy_rich_text_pattern.dart.

Run flutter format to format lib/src/easy_rich_text_pattern.dart.

Maintenance issues and suggestions

The description contains too many non-ASCII characters. (-20 points)

The site uses English as its primary language. The value of the description field in your package's pubspec.yaml field should primarily contain characters used in English.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.1
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test