simple_rich_text 1.0.31

  • Readme
  • Changelog
  • Example
  • Installing
  • 69

simple_rich_text #

Easily format Flutter text with simple format characters:

r'_/this is all three_/ (bold, underlined, and /italicized/). {push:home}Click to navigate to home screen'

Screenshot

Format Characters #

characterformat effect
asterisk (*)bold
slash (/)italicize
underscore (_)underline

Attributes #

Attribute pairs are placed in curly brackets immediately after first character marker. Each pair is separated by a semicolon (;). Each pair has syntax name:value.

keymeaning
colorred, green, blue, black, white, grey, etc
poppop the navigation stack
pushpush the value onto the navigation stack
replreplace the top route on the navigation stack

Features #

  • support text hyperlinks to other screens by preceding formatted text with route inside curly brackets: e.g., "... {calendar}go to calendar screen".

Sample Inputs: #

'this is /italic/'

'this is *bold*'

'*_/this is all three*_/ (*bold*, _underlined_, and /italicized/)'

'you can quote characters to NOT format a word \*bold\*'

'this is _underline_'

'go to _{/myroute}home_ page'

'this is ~important~(red).'

'this is _*bold and underlined*_.'

Requirements #

Ancestor MUST have textDirection set (required by internal RichText widget), either through MaterialApp widget or explicitly wrapped by a Directionality widget:

Directionality(
    child: SimpleRichText(text: 'Peter', term: 't'),
    textDirection: TextDirection.ltr)

Pull Requests #

Pull requests are welcome!

Usage #

Add a new dependency line to your project/pubspec.yaml file:

dependencies:
  ...
  simple_rich_text: ^1.0.28      # use latest version

Don't forget to flutter pub get.

Examples #

See the example directory.

Changelog #

Version 1.0.31 (2020-02-18) #

  • added color attributes
  • added push and pop nagivation attributes

Version 1.0.28 (2020-02-18) #

  • fixed route bug

Version 1.0.24 (2020-02-18) #

  • fixed route bug

Version 1.0.22 (2020-02-18) #

  • fixed lint errors

Version 1.0.21 (2020-02-18) #

  • renamed project

Version 1.0.20 (2020-02-18) #

  • initial version

example/lib/main.dart

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

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(new MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
//    String text = null;
//    String text = 'no format characters';
//    String text = r'format characters: \*\/\_';
//    String text = '_entire string_';
//    String text = '*/_fully loaded!_*/';
//    String text = 'first *bold*.';
//    String text = r'test*\_quoted\_*.';
//    String text = r'don't*close';
//    String text = r'_start at beginning and do not close';
//    String text = r'/Deanna/ is /awesome/!';
//    String text = r'_back__to back_';
//    String text = r'go to _{route}home_ page';
    String text =
        r'*_/this is all three*_/ (*{color:red}bold*, _{color:green}underlined_, and /{color:pink}italicized/). _{push:home;color:blue}Click to navigate to home screen_';
    return new MaterialApp(
      home: Scaffold(
          backgroundColor: Colors.grey,
          // , chars: r"[*]"
          body: Center(
              child: SimpleRichText(
                  text: text, style: TextStyle(color: Colors.yellow)))),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  simple_rich_text: ^1.0.31

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

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

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Dependencies

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