typeset 3.0.0-beta.1
typeset: ^3.0.0-beta.1 copied to clipboard
Flutter inline text formatter for chat-style markup with plug-and-play usage and granular configuration for rendering, links, and editing.
TypeSet #
TypeSet is a Flutter text-formatting package for chat-style inline markup.
It is designed around two goals:
- Plug-and-play adoption: start with one widget.
- Granular control: tune rendering, linking, and editing behavior when needed.
Why TypeSet #
- Familiar inline formatting syntax.
- Works for backend-driven message rendering.
- Consistent API for display and editing.
- Configurable AutoLink policy for safer link handling.
Install #
dependencies:
typeset: ^3.0.0-beta.1
flutter pub get
This is currently a pre-release build (
beta). Use stable constraints for production once3.0.0is published.
Quick start (plug-and-play) #
import 'package:typeset/typeset.dart';
const TypeSet('Hello *world* from _TypeSet_.');
Formatting syntax #
| Style | Syntax |
|---|---|
| Bold | *text* |
| Italic | _text_ |
| Underline | __text__ |
| Strikethrough | ~text~ |
| Monospace | `text` |
| Escape | \*literal asterisk\* |
Note on link behavior:
- Raw URLs such as
https://flutter.devandwww.example.comare detected and rendered with link style when AutoLink is enabled.- Tap/click handling is opt-in through
TypeSetAutoLinkConfig.linkRecognizerBuilder.- If no recognizer is provided, links are rendered as styled text without interaction.
Under the hood #
For parser/rendering internals and algorithm details, see doc/UNDER_THE_HOOD.md.
Custom configuration #
TypeSet uses TypeSetConfig to centralize behavior.
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:typeset/typeset.dart';
final customConfig = TypeSetConfig(
style: const TypeSetStyle(
boldStyle: TextStyle(fontWeight: FontWeight.w900),
italicStyle: TextStyle(fontStyle: FontStyle.italic, color: Color(0xFF6A1B9A)),
underlineStyle: TextStyle(decorationThickness: 3),
markerColor: Color(0xFF8D8D8D),
linkStyle: TextStyle(
color: Color(0xFF0B5FFF),
decoration: TextDecoration.underline,
),
monospaceStyle: TextStyle(
fontFamily: 'Courier',
backgroundColor: Color(0xFFEFF3FF),
),
),
autoLinkConfig: TypeSetAutoLinkConfig(
allowedSchemes: {'https'},
allowedDomains: RegExp(r'^flutter\\.dev$'),
linkRecognizerBuilder: (text, url) =>
TapGestureRecognizer()..onTap = () {
// Route the URL with your app's navigation/link strategy.
},
),
);
TypeSet(
'Read *docs* at https://flutter.dev',
config: customConfig,
);
Set defaults (scoped or app-wide) #
TypeSet starts with TypeSetConfig.defaults().
Use scoped defaults for part of the widget tree:
TypeSetConfigProvider(
config: TypeSetConfig.defaults().copyWith(
autoLinkConfig: TypeSetAutoLinkConfig.httpsOnly,
),
child: const TypeSet('Visit https://dart.dev'),
);
You can also set global defaults at app startup:
TypeSetGlobalConfig.instance = TypeSetConfig.defaults();
TypeSet(config: ...) and TypeSetEditingController(config: ...) always allow per-usage overrides when needed.
Editing experience #
Use TypeSetEditingController for real-time formatted previews in TextField.
final controller = TypeSetEditingController(
text: 'Use *bold* and __underline__',
config: TypeSetConfig(
style: const TypeSetStyle(markerColor: Color(0xFF9E9E9E)),
),
);
Add context menu actions:
TextField(
controller: controller,
contextMenuBuilder: (context, editableTextState) {
return AdaptiveTextSelectionToolbar.buttonItems(
anchors: editableTextState.contextMenuAnchors,
buttonItems: [
...getTypesetContextMenus(
editableTextState: editableTextState,
styleTypes: const [
StyleTypeEnum.bold,
StyleTypeEnum.italic,
StyleTypeEnum.underline,
],
),
...editableTextState.contextMenuButtonItems,
],
);
},
)
Migration #
Version 3.0.0 includes breaking changes.
- Read MIGRATION.md
- Review CHANGELOG.md
Example app #
Run the package example:
cd example
flutter run
Contributing #
See CONTRIBUTING.md for contribution and release guidelines.
License #
Apache-2.0. See LICENSE.
