フラッタ付きシンプルなマークダウンエディタの構築
私は現在Goryonと呼ばれるアプリに取り組んでいる- twtxtモバイルアプリ.アプリのいくつかの機能の一つは、それはあなたのTwitterの(あなたのTwitterのメッセージのようなkindaを構成することができますが、それはMarkdownを使用することができます).
そのためには
テキストを太字にするには、次のようにします.
我々の建物
始めましょう
そのためには
TextEditingController
に接続されているTextField
が必要になるでしょう_textController = TextEditingController()
....
TextFormField(
autofocus: true,
maxLines: 8,
controller: _textController
)
それから、私はマークダウン構文でテキストボックスで強調表示されたテキストを囲む機能をつくりました void _surroundTextSelection(String left, String right) {
final currentTextValue = _textController.value.text;
final selection = _textController.selection;
final middle = selection.textInside(currentTextValue);
final newTextValue = selection.textBefore(currentTextValue) +
'$left$middle$right' +
selection.textAfter(currentTextValue);
_textController.value = _textController.value.copyWith(
text: newTextValue,
selection: TextSelection.collapsed(
offset: selection.baseOffset + left.length + middle.length,
),
);
}
左側は左側の文字列です.右側は右側の文字列です.テキストを太字にするには、次のようにします.
_surroundTextSelection('**', '**')
コードブロックの追加_surroundTextSelection('```
', '
```')
画像の追加_surroundTextSelection('![](https://', ')'),
このrepoのフルコードをチェックしてください.それは今のすべてです!Reference
この問題について(フラッタ付きシンプルなマークダウンエディタの構築), 我々は、より多くの情報をここで見つけました https://dev.to/dooven/building-a-simple-markdown-editor-with-flutter-4oi9テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol