### Navigate to example directory Source: https://github.com/philipphgerber/textf/blob/main/example/advanced/README.md Change the working directory to the core example folder. ```bash cd example/textf_core ``` -------------------------------- ### Navigate to Example Directory Source: https://github.com/philipphgerber/textf/blob/main/example/textf_flex/README.md Change your current directory to the textf_flex example folder. ```bash cd example/textf_flex ``` -------------------------------- ### Run the application Source: https://github.com/philipphgerber/textf/blob/main/example/advanced/README.md Launches the example app on the connected device or emulator. ```bash flutter run ``` -------------------------------- ### Install dependencies Source: https://github.com/philipphgerber/textf/blob/main/example/advanced/README.md Fetches all required packages defined in the project. ```bash flutter pub get ``` -------------------------------- ### Install AI agent skill Source: https://github.com/philipphgerber/textf/blob/main/README.md Commands to install the Textf AI agent skill for coding assistants. ```sh dart pub global activate skills skills get ``` -------------------------------- ### Install Textf dependency Source: https://github.com/philipphgerber/textf/blob/main/README.md Add the package to your Flutter project using the command line. ```sh flutter pub add textf ``` -------------------------------- ### Flanking Rules Examples Source: https://github.com/philipphgerber/textf/blob/main/README.md Demonstrates correct and incorrect usage of formatting markers based on whitespace rules. ```text *italic* ✅ * italic * ❌ **bold** ✅ ** bold ** ❌ ``` -------------------------------- ### Quick Start with textf Source: https://github.com/philipphgerber/textf/blob/main/example/README.md Import and use the Textf widget for basic inline Markdown-like formatting in your Flutter application. Supports bold, italic, code, and links. ```dart import 'package:textf/textf.dart'; Textf( '**Bold**, *italic*, `code`, and [links](https://flutter.dev)', style: TextStyle(fontSize: 16), ) ``` -------------------------------- ### Implement Textf in a widget Source: https://github.com/philipphgerber/textf/blob/main/README.md A complete example showing both Textf and TextfEditingController integrated into a Flutter widget. ```dart import 'package:flutter/material.dart'; import 'package:textf/textf.dart'; class MyWidget extends StatelessWidget { final _controller = TextfEditingController(); @override Widget build(BuildContext context) { return Column( children: [ // Drop-in for Text Textf( '**Bold**, *italic*, `code`, and [links](https://flutter.dev)', style: TextStyle(fontSize: 16), ), // Drop-in for TextEditingController TextField(controller: _controller), ], ); } } ``` -------------------------------- ### Initialize project structure Source: https://github.com/philipphgerber/textf/blob/main/example/advanced/README.md Ensures platform-specific directories are generated without overwriting existing source code. ```bash flutter create . ``` -------------------------------- ### Project directory structure Source: https://github.com/philipphgerber/textf/blob/main/example/advanced/README.md Overview of the file organization within the textf_core directory. ```bash textf_core ├── lib │ ├── main.dart │ ├── screens │ │ ├── basic_formatting_screen.dart │ │ ├── chat_example_screen.dart │ │ ├── complex_formatting_screen.dart │ │ ├── home_screen.dart │ │ ├── nested_formatting_screen.dart │ │ ├── notification_example_screen.dart │ │ ├── screenshot_screen.dart │ │ ├── theme_example_screen.dart │ │ └── url_example_screen.dart │ └── widgets │ └── example_card.dart ├── README.md ├── analysis_options.yaml ├── assets │ └── fonts │ ├── RobotoMono-Italic-VariableFont_wght.ttf │ └── RobotoMono-VariableFont_wght.ttf └── pubspec.yaml ``` -------------------------------- ### Implement Live Formatting in Flutter Source: https://context7.com/philipphgerber/textf/llms.txt Demonstrates various configurations for TextfEditingController including marker visibility, prefilled text, and runtime toggling. ```dart import 'package:flutter/material.dart'; import 'package:textf/textf.dart'; class LiveFormattingExample extends StatefulWidget { @override State createState() => _LiveFormattingExampleState(); } class _LiveFormattingExampleState extends State { // Basic controller - markers always visible final _basicController = TextfEditingController(); // Smart hide - markers hide when cursor leaves formatted span final _smartController = TextfEditingController( markerVisibility: MarkerVisibility.whenActive, ); // With initial text final _prefilledController = TextfEditingController( text: 'Hello **bold** and *italic* world!', ); // Custom max length for large text protection final _limitedController = TextfEditingController( maxLiveFormattingLength: 2500, // Default: 5000 ); @override void dispose() { _basicController.dispose(); _smartController.dispose(); _prefilledController.dispose(); _limitedController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Column( children: [ // Basic usage TextField( controller: _basicController, decoration: InputDecoration( labelText: 'Type with **bold** or *italic*', hintText: 'Try: **hello** *world* `code`', ), ), // Smart marker visibility TextField( controller: _smartController, decoration: InputDecoration(labelText: 'Smart hide mode'), ), // Access plain text (markers stripped) ElevatedButton( onPressed: () { final plainText = _basicController.plainText; print('Plain text: $plainText'); // If text is "**Hello** world", plainText is "Hello world" }, child: Text('Get Plain Text'), ), // Toggle marker visibility at runtime ElevatedButton( onPressed: () { _basicController.markerVisibility = _basicController.markerVisibility == MarkerVisibility.always ? MarkerVisibility.whenActive : MarkerVisibility.always; }, child: Text('Toggle Marker Visibility'), ), ], ); } } ``` -------------------------------- ### Basic textf Usage Source: https://github.com/philipphgerber/textf/blob/main/example/README.md Demonstrates the basic usage of the Textf widget to render text with simple Markdown formatting like bold. ```dart Textf('Hello **World**!') ``` -------------------------------- ### Initialize TextfEditingController Source: https://github.com/philipphgerber/textf/blob/main/README.md Use TextfEditingController as a drop-in replacement for standard text controllers to enable live formatting. ```dart final controller = TextfEditingController(); TextField(controller: controller) ``` ```dart TextfEditingController(text: 'Hello **bold**') ``` -------------------------------- ### Configure pubspec.yaml Dependencies Source: https://github.com/philipphgerber/textf/blob/main/example/textf_flex/README.md Ensure your pubspec.yaml includes the flex_color_scheme package and a local path dependency for textf. ```yaml # example/textf_flex_example/pubspec.yaml dependencies: flutter: sdk: flutter flex_color_scheme: ^7.3.1 # Or latest textf: path: ../../ # Path to the main textf package ``` -------------------------------- ### Basic Textf Widget Usage Source: https://github.com/philipphgerber/textf/blob/main/README.md Demonstrates using the Textf widget as a drop-in replacement for the standard Text widget. ```dart Textf( '**Bold**, *italic*, ~~strike~~, ++underline++, ==highlight==, ' '`code`, ^super^, ~sub~, [link](https://flutter.dev)', style: TextStyle(fontSize: 16), textAlign: TextAlign.center, maxLines: 3, overflow: TextOverflow.ellipsis, ) ``` -------------------------------- ### Reference formatting syntax Source: https://context7.com/philipphgerber/textf/llms.txt A comprehensive overview of supported formatting markers including bold, italic, links, and placeholders. ```dart import 'package:flutter/material.dart'; import 'package:textf/textf.dart'; class SyntaxReferenceExample extends StatelessWidget { @override Widget build(BuildContext context) { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ // Bold: **text** or __text__ Textf('**bold** or __bold__'), // Italic: *text* or _text_ Textf('*italic* or _italic_'), // Bold + Italic: ***text*** or ___text___ Textf('***bold italic*** or ___bold italic___'), // Strikethrough: ~~text~~ Textf('~~strikethrough~~'), // Underline: ++text++ Textf('++underline++'), // Highlight: ==text== Textf('==highlight=='), // Inline code: `text` Textf('`inline code`'), // Superscript: ^text^ Textf('E = mc^2^'), // Subscript: ~text~ Textf('H~2~O'), // Links: [display](url) Textf('[Flutter](https://flutter.dev)'), // Links with formatting Textf('[**bold link**](https://example.com)'), // Placeholders: {key} Textf( 'Icon: {icon}', placeholders: {'icon': WidgetSpan(child: Icon(Icons.star))}, ), // Nested formatting (max 2 levels) Textf('**Bold _with italic_ nested**'), // Flanking rules: markers must not have adjacent whitespace Textf('*valid* but * invalid * (spaces prevent formatting)'), ], ); } } ``` -------------------------------- ### Enable SelectionArea support Source: https://github.com/philipphgerber/textf/blob/main/README.md Wrap Textf in a SelectionArea widget to allow users to select formatted text. ```dart SelectionArea( child: Textf('Select **this** formatted text!'), ) ``` -------------------------------- ### Configure global styles with TextfOptions Source: https://context7.com/philipphgerber/textf/llms.txt Use TextfOptions to define consistent formatting for all descendant Textf widgets. Styles merge down the tree, while callbacks follow nearest-ancestor-wins logic. ```dart import 'package:flutter/material.dart'; import 'package:textf/textf.dart'; class StyleConfigurationExample extends StatelessWidget { @override Widget build(BuildContext context) { return TextfOptions( // Custom format styles boldStyle: TextStyle( fontWeight: FontWeight.w900, color: Colors.deepOrange, ), italicStyle: TextStyle( fontStyle: FontStyle.italic, color: Colors.purple, ), strikethroughStyle: TextStyle( decoration: TextDecoration.lineThrough, decorationColor: Colors.red, decorationThickness: 2, ), underlineStyle: TextStyle( decoration: TextDecoration.underline, decorationStyle: TextDecorationStyle.wavy, decorationColor: Colors.blue, ), highlightStyle: TextStyle( backgroundColor: Colors.yellow.shade200, color: Colors.black87, ), codeStyle: TextStyle( fontFamily: 'monospace', backgroundColor: Colors.grey.shade200, color: Colors.pink.shade700, ), // Link styling and callbacks linkStyle: TextStyle( color: Colors.teal, fontWeight: FontWeight.w600, decoration: TextDecoration.none, ), linkHoverStyle: TextStyle( decoration: TextDecoration.underline, ), linkMouseCursor: SystemMouseCursors.click, // Link tap handler onLinkTap: (url, displayText) { print('Tapped link: $url (text: $displayText)'); // launchUrl(Uri.parse(url)); }, // Link hover handler (web/desktop) onLinkHover: (url, displayText, {required isHovering}) { print('Hover $url: $isHovering'); }, // Super/subscript configuration scriptFontSizeFactor: 0.6, // Default: 0.6 (60% of base size) superscriptBaselineFactor: -0.4, // Vertical offset for superscript subscriptBaselineFactor: 0.2, // Vertical offset for subscript child: Column( children: [ Textf('**Custom bold** and *custom italic* styling.'), Textf('Visit [our site](https://example.com) for more.'), Textf('Formula: E = mc^2^ and H~2~O'), // Nested TextfOptions - styles merge TextfOptions( boldStyle: TextStyle(fontWeight: FontWeight.w500), // Merges with parent color child: Textf('**Orange + medium weight** (merged styles)'), ), ], ), ); } } ``` -------------------------------- ### Create Textf widgets using string extensions Source: https://context7.com/philipphgerber/textf/llms.txt Use the .textf() extension to convert strings into Textf widgets directly. The .stripFormatting() method is useful for extracting plain text for accessibility or search. ```dart import 'package:flutter/material.dart'; import 'package:textf/textf.dart'; class StringExtensionExample extends StatelessWidget { @override Widget build(BuildContext context) { return Column( children: [ // Direct inline usage '**Status:** All systems operational'.textf(), // With style parameters 'Hello, **World**!'.textf( style: TextStyle(fontSize: 18), textAlign: TextAlign.center, ), // From localized strings (ARB files) // AppLocalizations.of(context).welcomeMessage.textf() // Strip formatting for plain text (search, analytics, accessibility) Builder(builder: (context) { final formatted = '**Hello** [Flutter](https://flutter.dev)!'; final plain = formatted.stripFormatting(); // plain == "Hello Flutter!" return Semantics( label: plain, // Use plain text for screen readers child: formatted.textf(), ); }), // All Textf parameters available 'Long **formatted** text with overflow...'.textf( maxLines: 1, overflow: TextOverflow.ellipsis, ), ], ); } } ``` -------------------------------- ### TextfOptions Configuration Source: https://github.com/philipphgerber/textf/blob/main/README.md Configures global formatting styles and link interaction behavior for descendant Textf widgets. ```APIDOC ## TextfOptions ### Description An InheritedWidget that configures all descendant Textf widgets and TextfEditingController instances with consistent styles and link handling. ### Parameters - **boldStyle** (TextStyle) - Optional - Style for **bold** text - **italicStyle** (TextStyle) - Optional - Style for *italic* text - **codeStyle** (TextStyle) - Optional - Style for `code` text - **onLinkTap** (Function) - Optional - Callback for link interaction: (url, displayText) => void ### Request Example TextfOptions( boldStyle: TextStyle(fontWeight: FontWeight.w900), onLinkTap: (url, _) => print('Tapped: $url'), child: YourWidget(), ) ``` -------------------------------- ### Live Formatting in Text Fields with textf Source: https://github.com/philipphgerber/textf/blob/main/example/README.md Demonstrates using TextfEditingController with a TextField to enable live Markdown-like formatting as the user types. Supports features like bold and italic. ```dart final controller = TextfEditingController(); TextField( controller: controller, decoration: InputDecoration(hintText: 'Try **bold** or *italic*'), ) ``` -------------------------------- ### Using String Extensions Source: https://github.com/philipphgerber/textf/blob/main/README.md Applies formatting directly to strings using the .textf() extension and cleans text with .stripFormatting(). ```dart // Directly in a widget tree '**Status:** All systems operational'.textf() // With style parameters 'Hello, **$username**!'.textf(style: TextStyle(fontSize: 18)) // From a localized string AppLocalizations.of(context).welcomeMessage.textf() '**Hello** [Flutter](.)!'.stripFormatting() // Returns: "Hello Flutter!" ``` -------------------------------- ### Import Textf package Source: https://github.com/philipphgerber/textf/blob/main/README.md Include the package in your Dart files to access the library components. ```dart import 'package:textf/textf.dart'; ``` -------------------------------- ### Implement TextfEditingController Source: https://github.com/philipphgerber/textf/blob/main/skills/textf-usage/SKILL.md Use TextfEditingController to enable live styling within a TextField as the user types. ```dart final controller = TextfEditingController(); TextField( controller: controller, // styles render as user types maxLines: null, ) ``` -------------------------------- ### Using textf String Extension Source: https://github.com/philipphgerber/textf/blob/main/example/README.md Applies textf formatting to a string using its extension method. Allows for concise application of styles directly to strings. ```dart '**Bold** text'.textf(style: TextStyle(fontSize: 18)) ``` -------------------------------- ### Implement Textf Widget Source: https://github.com/philipphgerber/textf/blob/main/skills/textf-usage/SKILL.md Use the Textf widget as a drop-in replacement for Text to support inline formatting and custom placeholders. ```dart Textf( '**Bold**, [link](https://dart.dev), {icon}', style: TextStyle(fontSize: 16), placeholders: {'icon': WidgetSpan(child: Icon(Icons.star))}, ) ``` -------------------------------- ### TextfEditingController Usage Source: https://github.com/philipphgerber/textf/blob/main/README.md A controller for TextField or TextFormField that renders live formatting as the user types. ```APIDOC ## TextfEditingController ### Description A drop-in replacement for TextEditingController that adds visual styling to plain text input without affecting the underlying stored value. ### Parameters - **text** (String) - Optional - Initial content - **markerVisibility** (MarkerVisibility) - Optional - Controls visibility of formatting markers (always, whenActive) - **maxLiveFormattingLength** (int) - Optional - Threshold for disabling formatting to preserve performance ### Request Example final controller = TextfEditingController( markerVisibility: MarkerVisibility.whenActive, maxLiveFormattingLength: 2500 ); TextField(controller: controller) ``` -------------------------------- ### Enable live formatting in TextField Source: https://github.com/philipphgerber/textf/blob/main/README.md Use TextfEditingController to enable real-time formatting within a TextField widget. ```dart final controller = TextfEditingController(); TextField(controller: controller); ``` -------------------------------- ### Nesting Formatting Markers Source: https://github.com/philipphgerber/textf/blob/main/README.md Shows the limit of two levels of nesting for formatting markers. ```dart Textf('**Bold with _italic_ inside.**') // ✅ two levels — works Textf('**_`three levels`_**') // ⚠️ third level renders as literal `three levels` ``` -------------------------------- ### Merge style properties in TextfOptions Source: https://github.com/philipphgerber/textf/blob/main/README.md Demonstrates how style properties like color and font weight merge down the widget tree. ```dart TextfOptions( boldStyle: TextStyle(color: Colors.red), // parent: red color child: TextfOptions( boldStyle: TextStyle(fontWeight: FontWeight.w900), // child: heavy weight child: Textf('**Red AND heavy**'), // both apply ✅ ), ) ``` -------------------------------- ### Configure TextfOptions Source: https://github.com/philipphgerber/textf/blob/main/skills/textf-usage/SKILL.md Use TextfOptions to define scoped styles and callbacks that apply to all child Textf widgets. ```dart TextfOptions( onLinkTap: (url, text) => print('Tapped $url'), boldStyle: const TextStyle(fontWeight: FontWeight.w900), italicStyle: const TextStyle(fontStyle: FontStyle.italic, color: Colors.blue), child: Column( children: [ Textf('**Bold** and _italic_ inherit styles'), TextfOptions( boldStyle: const TextStyle(color: Colors.red), // overrides only color child: Textf('**Red Bold**'), ), ], ), ) ``` -------------------------------- ### Integrate with themes Source: https://context7.com/philipphgerber/textf/llms.txt Textf automatically uses ThemeData colors, but custom styles can be applied using TextfOptions. ```dart import 'package:flutter/material.dart'; import 'package:textf/textf.dart'; class ThemeIntegrationExample extends StatelessWidget { @override Widget build(BuildContext context) { final isDark = Theme.of(context).brightness == Brightness.dark; return Column( children: [ // Automatic theme colors Textf('Links use [theme primary](https://example.com) color.'), Textf('Code uses `theme surface` colors.'), // Theme-aware custom styling TextfOptions( highlightStyle: TextStyle( backgroundColor: isDark ? Colors.yellow.shade700.withOpacity(0.3) : Colors.yellow.shade200, ), child: Textf('==Theme-aware== highlight.'), ), ], ); } } ``` -------------------------------- ### Implement Textf Widget for Inline Formatting Source: https://context7.com/philipphgerber/textf/llms.txt Use the Textf widget as a drop-in replacement for the standard Text widget to render formatted text with markers. ```dart import 'package:flutter/material.dart'; import 'package:textf/textf.dart'; class FormattedTextExample extends StatelessWidget { @override Widget build(BuildContext context) { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ // Basic formatting with all supported markers Textf( '**Bold**, *italic*, ~~strikethrough~~, ++underline++, ' '==highlight==, `code`, ^super^, ~sub~', style: TextStyle(fontSize: 16), ), // Links with nested formatting Textf( 'Visit [**Flutter**](https://flutter.dev) for documentation.', style: TextStyle(fontSize: 14), textAlign: TextAlign.center, ), // All standard Text properties work Textf( 'This **long text** demonstrates *maxLines* and overflow. ' 'Additional content is truncated with an ellipsis.', maxLines: 2, overflow: TextOverflow.ellipsis, ), // Nested formatting (max 2 levels) Textf('**Bold with _nested italic_ inside.**'), // Scientific notation Textf('Einstein: E = mc^2^, Water: H~2~O'), ], ); } } ``` -------------------------------- ### textf with Link Callbacks and Styles Source: https://github.com/philipphgerber/textf/blob/main/example/README.md Configures TextfOptions to handle link taps with a callback and apply custom styles to links. This allows for interactive links within the text. ```dart TextfOptions( onLinkTap: (url, displayText) => launchUrl(Uri.parse(url)), linkStyle: TextStyle(color: Colors.blue), child: Textf('[Tap me](https://example.com)'), ) ``` -------------------------------- ### Enable SelectionArea for Textf Source: https://context7.com/philipphgerber/textf/llms.txt Wrap Textf widgets within a SelectionArea to enable native text selection capabilities. ```dart import 'package:flutter/material.dart'; import 'package:textf/textf.dart'; class SelectionExample extends StatelessWidget { @override Widget build(BuildContext context) { return SelectionArea( child: Column( children: [ Textf('Select **this formatted** text!'), Textf('*Italic* and `code` are also selectable.'), ], ), ); } } ``` -------------------------------- ### Handle link taps in Textf Source: https://github.com/philipphgerber/textf/blob/main/README.md Wrap Textf with TextfOptions to define custom behavior when a link is tapped. ```dart TextfOptions( onLinkTap: (url, displayText) { // Open in browser, push a route, or handle internally debugPrint('Tapped: $url'); }, child: Textf('Visit [Flutter](https://flutter.dev)'), ) ``` -------------------------------- ### Textf Cache Management Source: https://github.com/philipphgerber/textf/blob/main/README.md Utility to manage memory usage for parsed span trees. ```APIDOC ## Textf.clearCache ### Description Clears the LRU cache used for parsed span trees to free memory in low-memory situations. ### Method Static Method ### Request Example Textf.clearCache(); ``` -------------------------------- ### Set max live formatting length Source: https://github.com/philipphgerber/textf/blob/main/README.md Limit the number of characters processed for live formatting to prevent UI performance issues. ```dart TextfEditingController(maxLiveFormattingLength: 2500) // default: 5000 ``` -------------------------------- ### Embed Inline Widgets with Placeholders Source: https://context7.com/philipphgerber/textf/llms.txt Use the placeholders parameter to map keys in the text to custom InlineSpan widgets like icons or images. ```dart import 'package:flutter/material.dart'; import 'package:textf/textf.dart'; class PlaceholderExample extends StatelessWidget { @override Widget build(BuildContext context) { return Column( children: [ // Basic widget placeholders Textf( 'Built with {flutter} and {dart}. Made with {love}.', placeholders: { 'flutter': WidgetSpan( child: Image.asset('assets/flutter.png', width: 18, height: 18), ), 'dart': WidgetSpan( child: Image.asset('assets/dart.png', width: 18, height: 18), ), 'love': WidgetSpan( child: Icon(Icons.favorite, color: Colors.red, size: 18), ), }, ), // Icons with alignment Textf( 'Press {add_btn} to add a new {user_icon} user.', placeholders: { 'add_btn': WidgetSpan( alignment: PlaceholderAlignment.middle, child: Icon(Icons.add_circle, color: Colors.blue, size: 20), ), 'user_icon': WidgetSpan( alignment: PlaceholderAlignment.middle, child: Icon(Icons.person, color: Colors.green, size: 20), ), }, ), // Status indicator with custom widget Textf( 'Status: {status}', placeholders: { 'status': WidgetSpan( child: Container( padding: EdgeInsets.symmetric(horizontal: 8, vertical: 2), decoration: BoxDecoration( color: Colors.green, borderRadius: BorderRadius.circular(4), ), child: Text('Online', style: TextStyle(color: Colors.white, fontSize: 12)), ), ), }, ), ], ); } } ``` -------------------------------- ### Display formatted text with Textf Source: https://github.com/philipphgerber/textf/blob/main/README.md Use the Textf widget as a drop-in replacement for the standard Text widget to render inline formatting. ```dart Textf('Hello **Flutter**. Build for ==any screen==!'); ``` -------------------------------- ### Configure global TextfOptions Source: https://github.com/philipphgerber/textf/blob/main/README.md Use TextfOptions as an InheritedWidget to apply consistent styles and link handlers across the widget tree. ```dart TextfOptions( boldStyle: TextStyle(fontWeight: FontWeight.w900, color: Colors.deepOrange), codeStyle: TextStyle(fontFamily: 'monospace', color: Colors.pink), onLinkTap: (url, _) => debugPrint('Link tapped: $url'), child: YourWidget(), ) ``` -------------------------------- ### textf with Widget Placeholders Source: https://github.com/philipphgerber/textf/blob/main/example/README.md Integrates custom Flutter widgets as placeholders within text using Textf. This allows for dynamic content insertion, such as icons. ```dart Textf( 'Rate this app {star}', placeholders: { 'star': WidgetSpan(child: Icon(Icons.star, color: Colors.amber)), }, ) ``` -------------------------------- ### Handling Malformed Markers Source: https://github.com/philipphgerber/textf/blob/main/README.md Illustrates how unclosed markers are rendered as plain text without affecting subsequent formatting. ```dart Textf('**unclosed and *italic*') // renders: **unclosed and italic (italic still applies correctly) ``` -------------------------------- ### Configure marker visibility Source: https://github.com/philipphgerber/textf/blob/main/README.md Control how formatting markers appear during editing using MarkerVisibility. ```dart TextfEditingController(markerVisibility: MarkerVisibility.whenActive) ``` ```dart controller.markerVisibility = MarkerVisibility.always; ``` -------------------------------- ### Override theme defaults with TextfOptions Source: https://github.com/philipphgerber/textf/blob/main/README.md Use TextfOptions to customize link styles while maintaining theme integration. ```dart TextfOptions( linkStyle: TextStyle(color: Colors.teal, fontWeight: FontWeight.w600), child: Textf('A [custom colored](https://example.com) link.'), ) ``` -------------------------------- ### Customizing textf Styles Source: https://github.com/philipphgerber/textf/blob/main/example/README.md Utilizes TextfOptions to define custom styles for various formatting types like bold, code, and highlight. This enables extensive customization of text appearance. ```dart TextfOptions( boldStyle: TextStyle(fontWeight: FontWeight.w900), codeStyle: TextStyle(fontFamily: 'monospace'), highlightStyle: TextStyle(backgroundColor: Colors.yellow), child: Textf('Style **everything** your way'), ) ``` -------------------------------- ### Manage Textf cache Source: https://context7.com/philipphgerber/textf/llms.txt Clear the internal LRU cache manually to free memory, particularly useful in low-memory scenarios. ```dart import 'package:textf/textf.dart'; // Clear cache to free memory (e.g., in didReceiveMemoryWarning) Textf.clearCache(); ``` -------------------------------- ### Embedding Widget Placeholders Source: https://github.com/philipphgerber/textf/blob/main/README.md Inserts custom Flutter widgets into text using the placeholders map. ```dart Textf( 'Made with {heart} using {flutter}', placeholders: { 'heart': WidgetSpan(child: Icon(Icons.favorite, color: Colors.red)), 'flutter': WidgetSpan(child: FlutterLogo(size: 16)), }, ) ``` -------------------------------- ### Override callbacks with nearest-ancestor-wins Source: https://github.com/philipphgerber/textf/blob/main/README.md Shows how nested callback properties resolve to the closest ancestor in the tree. ```dart TextfOptions( onLinkTap: (url, _) => debugPrint('root handler'), child: TextfOptions( onLinkTap: (url, _) => debugPrint('inner handler'), // this one wins child: Textf('[tap me](https://example.com)'), ), ) ``` -------------------------------- ### Apply custom styles to TextField Source: https://github.com/philipphgerber/textf/blob/main/README.md Wrap a TextField with TextfOptions to customize the appearance of formatted text elements. ```dart TextfOptions( boldStyle: TextStyle(fontWeight: FontWeight.w900, color: Colors.deepOrange), codeStyle: TextStyle(fontFamily: 'monospace', color: Colors.pink), child: TextField( controller: TextfEditingController(), decoration: InputDecoration(labelText: 'Formatted input'), ), ) ``` -------------------------------- ### Escaping Formatting Markers Source: https://github.com/philipphgerber/textf/blob/main/README.md Uses backslashes to treat formatting markers as literal characters. ```dart Textf(r'\**not bold\** and \{not_a_placeholder}') // renders: **not bold** and {not_a_placeholder} ``` -------------------------------- ### Escape formatting characters in Dart Source: https://context7.com/philipphgerber/textf/llms.txt Use backslashes to treat formatting markers as literal characters. Raw strings are recommended for cleaner syntax. ```dart import 'package:flutter/material.dart'; import 'package:textf/textf.dart'; class EscapingExample extends StatelessWidget { @override Widget build(BuildContext context) { return Column( children: [ // Escape asterisks Textf(r'Literal asterisks: \*not bold\*'), // Output: Literal asterisks: *not bold* // Escape underscores Textf(r'Literal underscores: \_not italic\_'), // Output: Literal underscores: _not italic_ // Escape tildes Textf(r'Literal tildes: \~\~not strikethrough\~\~'), // Output: Literal tildes: ~~not strikethrough~~ // Escape backtick Textf(r'Literal backtick: \`not code\`'), // Output: Literal backtick: `not code` // Escape backslash itself Textf(r'Literal backslash: \\'), // Output: Literal backslash: \ // Escape placeholders Textf(r'\{not_a_placeholder}'), // Output: {not_a_placeholder} // Star rating example Textf(r'Rating: \*\*\*\*\* (5 stars)'), // Output: Rating: ***** (5 stars) // Math expression (not formatted due to spacing) Textf('Result: 2 * 3 = 6'), // Spaces prevent formatting ], ); } } ``` -------------------------------- ### Clear Textf cache Source: https://github.com/philipphgerber/textf/blob/main/README.md Manually clear the internal LRU cache to free up memory. ```dart Textf.clearCache(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.