myanmar_kit library

myanmar_kit is a Flutter package for rendering and editing Myanmar text mixed with Latin text.

The package focuses on practical text handling for real apps:

  • Myanmar-aware text sizing with MMText, MMRichText, and MMSelectableText
  • Grapheme-safe text editing with MMTextField
  • Ambient font configuration with MMTextConfig
  • Zawgyi detection and conversion helpers
  • Myanmar digit conversion, NRC formatting, and light collation helpers
  • Grapheme-aware truncation and line-break helpers

Quick start

Set app-wide defaults with MMTextTheme in ThemeData.extensions, or wrap a subtree with MMTextConfig if you prefer an inherited widget:

MaterialApp(
  theme: ThemeData(
    extensions: [
      MMTextTheme(
        myanmarFont: 'Noto Sans Myanmar',
        latinFont: 'Roboto',
      ),
    ],
  ),
  home: Scaffold(
    body: Center(
      child: MMText(
        text: 'Hello မြန်မာ',
        fontSize: 18,
      ),
    ),
  ),
);

For rich text, use MMText.rich or MMRichText. For editing, use MMTextField so Myanmar grapheme clusters stay intact. MMTextConfig remains available for local overrides and runtime inspection. Use MMSelectableText when the content should remain selectable.

See the example app for a news-style demo with live MMTextConfig controls and mixed-script article content.

Classes

MMRichText
A rich-text wrapper that applies Myanmar font scaling to a top-level span.
MMSelectableText
A selectable text widget that scales Myanmar script runs to match Latin text.
MMText
A drop-in text widget that scales Myanmar script runs to match Latin text.
MMTextConfig
Ambient configuration for myanmar_kit text widgets.
MMTextField
A text field that keeps Myanmar grapheme clusters intact when editing.
MMTextTheme
Theme-level configuration for myanmar_kit text widgets.
MyanmarGraphemeFormatter

Functions

compareMyanmar(String a, String b) int
Compares strings using a lightweight Myanmar-aware sort key.
formatNrc(String input) String
Normalizes separators, spacing, and casing in an NRC number.
graphemeLength(String text) int
Returns the number of user-perceived grapheme clusters in text.
insertBreakHints(String text, {String hint = '\u200B'}) String
Inserts optional break hints into Myanmar text.
isLikelyZawgyi(String text) bool
Returns whether text is likely encoded in Zawgyi.
isValidNrc(String input) bool
Returns whether input looks like a valid Myanmar NRC number.
safeTruncate(String text, int maxGraphemes, {String ellipsis = '…'}) String
Truncates text to maxGraphemes grapheme clusters.
toArabicDigits(String input) String
Converts Myanmar digits to ASCII digits.
toGraphemeClusters(String text) List<String>
Returns the grapheme clusters of text as a list.
toMyanmarDigits(String input) String
Converts ASCII digits to Myanmar digits.
unicodeToZawgyi(String text) String
Converts common Unicode Myanmar sequences to Zawgyi.
zawgyiConfidence(String text) double
Heuristic Zawgyi detection utilities.
zawgyiToUnicode(String text) String
Converts common Zawgyi sequences to Unicode Myanmar.