https://github.com/bytedance/realrichtext

A Tricky Solution for Implementing Inline-Image-In-Text Feature in Flutter.

https://github.com/bytedance/realrichtext

Science Score: 10.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    1 of 5 committers (20.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.6%) to scientific vocabulary

Keywords

flutter inline-images rich-text
Last synced: 5 months ago · JSON representation

Repository

A Tricky Solution for Implementing Inline-Image-In-Text Feature in Flutter.

Basic Info
  • Host: GitHub
  • Owner: bytedance
  • License: other
  • Language: Dart
  • Default Branch: master
  • Homepage:
  • Size: 307 KB
Statistics
  • Stars: 657
  • Watchers: 16
  • Forks: 85
  • Open Issues: 16
  • Releases: 0
Archived
Topics
flutter inline-images rich-text
Created about 7 years ago · Last pushed over 6 years ago
Metadata Files
Readme Changelog License

README.md

RealRichText

A Tricky Solution for Implementing Inline-Image-In-Text Feature in Flutter.

Getting Started

According to the related Flutter Issues(#2022) , Inline-Image-In-Text is a long-time(2 years) missing feature since RichText(or the underlying Paragraph) does only support pure text. But we can solve this problem in a simple/tricky way:

  1. Regard the images as a particular blank TextSpan, convert image's width and height to textspan's letterSpacing and fontSize. the origin paragraph will do the layout operation and leave the desired image space for us.
  2. Override the paint function,calculate the right offset via the getOffsetForCaret() api to draw the image over the space.

For more details, please refer to the source code.

Usage

The only thing you have to do is converting your origin text to a TextSpan/ImageSpan List first.

```Dart import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:realrichtext/realrichtext.dart';

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

class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); }

class MyAppState extends State { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar( title: const Text('Plugin example app'), ), body: Center( child: RealRichText([ TextSpan( text: "A Text Link", style: TextStyle(color: Colors.red, fontSize: 14), recognizer: TapGestureRecognizer() ..onTap = () { debugPrint("Link Clicked."); }, ), ImageSpan( AssetImage("packages/realrichtext/images/emoji9.png"), imageWidth: 24, imageHeight: 24, ), ImageSpan(AssetImage("packages/realrichtext/images/emoji10.png"), imageWidth: 24, imageHeight: 24, margin: EdgeInsets.symmetric(horizontal: 10)), TextSpan( text: "哈哈哈", style: TextStyle(color: Colors.yellow, fontSize: 14), ), TextSpan( text: "@Somebody", style: TextStyle( color: Colors.black, fontSize: 14, fontWeight: FontWeight.bold), recognizer: TapGestureRecognizer() ..onTap = () { debugPrint("Link Clicked"); }, ), TextSpan( text: " #RealRichText# ", style: TextStyle(color: Colors.blue, fontSize: 14), recognizer: TapGestureRecognizer() ..onTap = () { debugPrint("Link Clicked"); }, ), TextSpan( text: "showing a bigger image", style: TextStyle(color: Colors.black, fontSize: 14), ), ImageSpan(AssetImage("packages/realrichtext/images/emoji10.png"), imageWidth: 24, imageHeight: 24, margin: EdgeInsets.symmetric(horizontal: 5)), TextSpan( text: "and seems working perfect……", style: TextStyle(color: Colors.black, fontSize: 14), ), ]), ), ), ); } } ```

Note

ImageSpan must set the width & height properties.

if your image's width or height is not specific, you can wrap two RealRichText in a StatefulWidget, one for showing placeholder image and the other for showing the actual image when it is ready.

Owner

  • Name: Bytedance Inc.
  • Login: bytedance
  • Kind: organization
  • Location: Singapore

GitHub Events

Total
  • Watch event: 2
  • Fork event: 1
Last Year
  • Watch event: 2
  • Fork event: 1

Committers

Last synced: about 1 year ago

All Time
  • Total Commits: 22
  • Total Committers: 5
  • Avg Commits per committer: 4.4
  • Development Distribution Score (DDS): 0.455
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
limengyun2008 l****8@g****m 12
Li Mengyun l****n@b****m 7
David Zhang d****g@s****u 1
DavidYang d****1@f****m 1
zdwchang z****g@g****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: about 1 year ago

All Time
  • Total issues: 26
  • Total pull requests: 5
  • Average time to close issues: 7 days
  • Average time to close pull requests: 20 days
  • Total issue authors: 18
  • Total pull request authors: 4
  • Average comments per issue: 1.15
  • Average comments per pull request: 1.0
  • Merged pull requests: 2
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • 2dxgujun (4)
  • zucchiniEvader (2)
  • charlesYun (2)
  • badboy-tian (2)
  • liubobo (1)
  • BeanWei (1)
  • JohnsonChung (1)
  • ibrokemypie (1)
  • lsp9876 (1)
  • Windymonkeys (1)
  • hyz1992 (1)
  • LoveTheSkyBlue (1)
  • ENUUI (1)
  • Mericusta (1)
  • Thomsen (1)
Pull Request Authors
  • 2dxgujun (2)
  • DavidYang1121 (1)
  • LinXiaoTao (1)
  • OnTheThirdDay (1)
Top Labels
Issue Labels
Pull Request Labels

Dependencies

ios/real_rich_text.podspec cocoapods
  • Flutter >= 0
example/android/app/build.gradle maven
  • junit:junit 4.12 testImplementation
example/pubspec.yaml pub
  • flutter_test --- !ruby/hash:ActiveSupport::HashWithIndifferentAccess sdk: flutter development
  • real_rich_text --- !ruby/hash:ActiveSupport::HashWithIndifferentAccess path: "../" development
  • cupertino_icons ^0.1.2
  • flutter --- !ruby/hash:ActiveSupport::HashWithIndifferentAccess sdk: flutter
pubspec.yaml pub
  • flutter --- !ruby/hash:ActiveSupport::HashWithIndifferentAccess sdk: flutter