flutter_pretext 1.0.0
flutter_pretext: ^1.0.0 copied to clipboard
A high-performance text dynamics engine and layout framework for native Flutter. mathematically wraps text natively around geometry, obstacles, and shapes.
Flutter Pretext #
flutter_pretext is a blazingly fast, high-performance text dynamics engine and layout framework natively rebuilt for Flutter.
[Obstacle Wrapping Demo]
It is a direct Dart implementation and port of the groundbreaking JavaScript text dynamics library originally built by @chenglou. All credits for the underlying geometric abstractions, pure-code measuring mechanics, and cursor math layout capabilities go to chenglou/pretext.
This package natively migrates those massive layout capabilities to standard Flutter Widgets without bridging FFI or WebViews.
Why Pretext? #
Flutter's standard Text widgets do an amazing job rendering strings, but custom geometry flow—like wrapping paragraphs beautifully around floating avatars, shrinking chat bubbles accurately, or splitting text evenly into a circular path—has historically been agonizing to compute cleanly on a device without dropping frames.
Pretext calculates lines mathematically behind the scenes before actually laying out the heavy rendering tree.
🌟 Features Available Today #
1. ObstacleTextFlow
Pass in multiple UI widget bounds (like floating Positioned icons) and watch the text shatter and wrap flawlessly around them on both sides instantly.
[Obstacle Wrapping Demo]
2. ShrinkWrapText
Say goodbye to the "dead empty trailing space" bug in chat bubbles! ShrinkWrap computes the absolute geometric longest drawn string line and snaps your container size down perfectly.
[ShrinkWrapText Demo]
3. BalancedText
Say goodbye to awkward orphaned words hanging off your H1 headlines. Drops in a binary-search container to ensure your multi-line headlines have geometrically balanced widths.
[BalancedText Demo]
4. Custom Mathematical Shapes & 60 FPS Animations
You can bind your obstacle arrays to AnimationControllers or custom geometric algorithms like Circular mappings. Text will dynamically flow over moving surfaces without ever dropping a frame.
[CustomShapes Demo]
Quick Start #
Obstacle Layout Flow #
Got a square floating avatar taking up the top left edge? Let text handle it like Word or HTML float:left. Note: You can even use .wrapBothSides = true to drop the avatar in the exact middle of the paragraph!
final prepared = prepare("Your extremely long dynamic text here...", style);
ObstacleTextFlow(
preparedText: prepared,
textStyle: style,
lineHeight: 18 * 1.2,
obstacles: [ Rect.fromLTWH(0, 0, 100, 100) ], // Re-renders precisely around this square.
);
Typographic Balanced Headlines #
Stop leaving one word hanging alone!
BalancedText(
"This Super Long Title Will Splinter Awkwardly Unless You Use Pretext",
titleStyle,
/* lineHeight */ 40,
)
Special Thanks #
This repository would not exist without the genius foundations of chenglou/pretext. His commitment to performance boundary pushing was instrumental.