Arabic Justified Text

๐Ÿ“ Arabic Justified Text

Beautiful Arabic text justification using Kashida (ู€) instead of spaces

pub package License: MIT

Table of Contents

๐ŸŒŸ Overview

Arabic Justified Text is a Flutter package that provides beautiful text justification for Arabic text using Kashida (ู€) instead of adding extra spaces between words. This creates a more natural and aesthetically pleasing appearance for justified Arabic text.

โœจ Features

  • โœ… Smart Kashida Distribution - Intelligently distributes Kashida across words
  • โœ… Diacritics Support - Properly handles Arabic diacritics (Tashkeel)
  • โœ… Mixed Text Support - Works with Arabic and English text together
  • โœ… Line Break Support - Respects \n characters in text
  • โœ… Theme Integration - Inherits default text styles from your app theme
  • โœ… RichText Support - Advanced styling with ArabicJustifiedRichText
  • โœ… Sacred Text Handling - Automatically excludes "Allah" (ุงู„ู„ู‘ูฐู‡) from Kashida
  • โœ… Customizable Exclusions - Add your own words to exclude from Kashida
  • โœ… Performance Optimized - Efficient text processing
  • โœ… RTL/LTR Support - Configurable text direction (RTL by default)

๐Ÿ“ฆ Installation

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

dependencies:
  arabic_justified_text: ^1.0.2

Then run:

flutter pub get

๐Ÿš€ Quick Start

Basic Usage

import 'package:arabic_justified_text/arabic_justified_text.dart';

ArabicJustifiedText(
  'ููŠ ุนุงู„ู… ุงู„ุชูƒู†ูˆู„ูˆุฌูŠุง ุงู„ุญุฏูŠุซุฉุŒ ุฃุตุจุญุช ุชุทุจูŠู‚ุงุช ุงู„ู‡ุงุชู ุงู„ู…ุญู…ูˆู„ ุฌุฒุกุงู‹ ุฃุณุงุณูŠุงู‹ ู…ู† ุญูŠุงุชู†ุง ุงู„ูŠูˆู…ูŠุฉ.',
)

With Custom Style

ArabicJustifiedText(
  'ุงู„ู†ุต ุงู„ุนุฑุจูŠ ู‡ู†ุง',
  style: TextStyle(
    fontSize: 18,
    fontWeight: FontWeight.bold,
    color: Colors.blue,
  ),
)

With All Options

ArabicJustifiedText(
  'ุฃุดู‡ุฏ ุฃู† ู„ุง ุฅู„ู‡ ุฅู„ุง ุงู„ู„ู‘ูฐู‡ุŒ ูˆุฃู† ู…ุญู…ุฏู‹ุง ุฑุณูˆู„ ุงู„ู„ู‘ูฐู‡',
  style: TextStyle(fontSize: 16, height: 1.8),
  enableKashida: true,
  maxLines: 5,
  overflow: TextOverflow.ellipsis,
  textAlign: TextAlign.justify,
  textDirection: TextDirection.rtl,
  excludedWords: ['ู…ุญู…ุฏุง', 'ุฑุณูˆู„'], // Optional: exclude specific words
)

๐Ÿ“– Parameters

ArabicJustifiedText

For simple text with single style.

Parameter Type Default Description
text String required The text to display
style TextStyle? null Text style (inherits from theme if null)
maxLines int? null Maximum number of lines
overflow TextOverflow? null How to handle text overflow
textDirection TextDirection TextDirection.rtl Text direction (RTL/LTR)
textAlign TextAlign TextAlign.justify Text alignment
enableKashida bool true Enable/disable Kashida justification
excludedWords List<String>? null Words to exclude from Kashida

ArabicJustifiedRichText

For complex text with multiple styles.

Parameter Type Default Description
textSpan InlineSpan required The text span to display
maxLines int? null Maximum number of lines
overflow TextOverflow? null How to handle text overflow
textDirection TextDirection TextDirection.rtl Text direction (RTL/LTR)
textAlign TextAlign TextAlign.justify Text alignment
enableKashida bool true Enable/disable Kashida justification
excludedWords List<String>? null Words to exclude from Kashida

๐Ÿ’ก Examples

1. Simple Text

ArabicJustifiedText(
  'ู…ุฑุญุจุงู‹ ุจูƒ ููŠ ุนุงู„ู… ุงู„ุจุฑู…ุฌุฉ ุงู„ุฌู…ูŠู„',
)

2. Text with Diacritics (Tashkeel)

ArabicJustifiedText(
  'ุจูุณู’ู…ู ุงู„ู„ูŽู‘ู‡ู ุงู„ุฑูŽู‘ุญู’ู…ูŽูฐู†ู ุงู„ุฑูŽู‘ุญููŠู…ู',
  style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
)

3. Multi-line Text with Line Breaks

ArabicJustifiedText(
  '''ุงู„ุณุทุฑ ุงู„ุฃูˆู„ ู…ู† ุงู„ู†ุต
ุงู„ุณุทุฑ ุงู„ุซุงู†ูŠ ู…ู† ุงู„ู†ุต
ุงู„ุณุทุฑ ุงู„ุซุงู„ุซ ู…ู† ุงู„ู†ุต''',
  style: TextStyle(fontSize: 16, height: 2.0),
)

4. Mixed Arabic and English

ArabicJustifiedText(
  'ุงุณุชุฎุฏู… Flutter ู„ุจู†ุงุก ุชุทุจูŠู‚ุงุช mobile ุฑุงุฆุนุฉ',
  style: TextStyle(fontSize: 18),
)

5. With Maximum Lines

ArabicJustifiedText(
  'ู†ุต ุทูˆูŠู„ ุฌุฏุงู‹ ูŠุญุชูˆูŠ ุนู„ู‰ ุงู„ูƒุซูŠุฑ ู…ู† ุงู„ูƒู„ู…ุงุช ูˆุงู„ุฌู…ู„...',
  maxLines: 3,
  overflow: TextOverflow.ellipsis,
)

6. Toggle Kashida On/Off

bool useKashida = true;

ArabicJustifiedText(
  'ุงู„ู†ุต ุงู„ุนุฑุจูŠ ู‡ู†ุง',
  enableKashida: useKashida,
)

๐Ÿ•Œ Special Features

Respectful Handling of Sacred Words

The package automatically excludes the word (ุงู„ู„ู‘ูฐู‡) and its variations from Kashida application, preserving its traditional appearance.

// The word "ุงู„ู„ู‘ูฐู‡" will never automatically receive Kashida
ArabicJustifiedText('ุจุณู… ุงู„ู„ู‘ูฐู‡ ุงู„ุฑุญู…ู† ุงู„ุฑุญูŠู…')
// Result: ุจู€ุณู€ู… ุงู„ู„ู‘ูฐู‡ ุงู„ู€ุฑุญู…ู€ู† ุงู„ู€ุฑุญูŠู€ู… (ุงู„ู„ู‘ูฐู‡ remains unchanged)

Automatically excluded variations:

  • ุงู„ู„ู‘ูฐู‡ุŒ ุงู„ู„ูŽู‘ู‡ุŒ ูฑู„ู„ู‘ูฐู‡ุŒ ู„ู„ู‘ูฐู‡ุŒ ูˆู„ู„ู‘ูฐู‡ุŒ ูˆุงู„ู„ู‘ูฐู‡ุŒ ุจุงู„ู„ู‘ูฐู‡ุŒ ุชุงู„ู„ู‘ูฐู‡

Custom Word Exclusions

You can exclude additional words from Kashida application:

ArabicJustifiedText(
  'ุงู„ู„ู‡ู… ุตู„ ูˆุณู„ู… ูˆุจุงุฑูƒ ุนู„ู‰ ู†ุจูŠู†ุง ู…ุญู…ุฏ ูˆุนู„ู‰ ุขู„ู‡ ูˆุตุญุจู‡ ุฃุฌู…ุนูŠู†',
  excludedWords: ['ู…ุญู…ุฏ', 'ุงู„ู„ู‡ู…'],
)

Use cases:

  • ๐Ÿ“– Religious texts (prophets' names, sacred terms)
  • ๐Ÿ“š Brand names or proper nouns
  • โœ๏ธ Technical terms that should remain unchanged

๐ŸŽจ Advanced Usage

Using ArabicJustifiedRichText

โš ๏ธ Important: ArabicJustifiedRichText currently does not support WidgetSpan. If your text contains widgets (icons, images, etc.), the Kashida justification will be disabled and it will fall back to standard RichText rendering.

For complex text with multiple styles, colors, or interactions:

ArabicJustifiedRichText(
  enableKashida: true,
  textSpan: TextSpan(
    style: TextStyle(fontSize: 18),
    children: [
      TextSpan(text: 'ุงู„ู†ุต ุงู„ุนุงุฏูŠ '),
      TextSpan(
        text: 'ุงู„ู†ุต ุงู„ุนุฑูŠุถ',
        style: TextStyle(fontWeight: FontWeight.bold, color: Colors.blue),
      ),
      TextSpan(text: ' ุงู„ู…ุฒูŠุฏ ู…ู† ุงู„ู†ุต'),
    ],
  ),
)

๐Ÿค Contributing

Contributions are welcome! Here's how you can help:

  1. ๐Ÿ› Report Bugs - Open an issue describing the bug
  2. ๐Ÿ’ก Suggest Features - Share your ideas for improvements
  3. ๐Ÿ”ง Submit Pull Requests - Fix bugs or add features
  4. ๐Ÿ“– Improve Documentation - Help make docs better
  5. โญ Star the Repo - Show your support!

๐Ÿ“‹ Roadmap

  • WidgetSpan support for ArabicJustifiedRichText - Allow mixing text and widgets with Kashida
  • Add more customization options for Kashida density
  • Performance improvements for very long texts
  • Support for other RTL languages (Persian, Urdu)

๐Ÿ› Known Issues

  • Last word wrapping with certain fonts (e.g., Amiri Quran) - With some Quranic fonts, the last word of a line may wrap to the next line due to Kashida width calculations. This happens because Kashida characters in Quranic fonts are wider than in regular fonts
  • WidgetSpan not supported in ArabicJustifiedRichText - If you need to mix text with widgets (icons, images), use enableKashida: false or use standard RichText
  • Very long words might overflow on narrow screens (use maxLines to handle)
  • Performance may vary with extremely long texts (>10,000 characters)

โญ Show Your Support

If you find this package useful, please consider giving it a โญ on GitHub!

Made with โค๏ธ for the Arabic Flutter Community

Report Bug ยท Request Feature