简体   繁体   English

是否可以在 Flutter 中使 RIchText 可编辑?

[英]Is it possible to make RIchText Editable in Flutter?

I have a situtaion where i need to edit a richtext widget.我有一个需要编辑富文本小部件的情况。 Im trying to design a compiler in flutter and syntax should be highlighted for it to be userfriendly.我试图在 flutter 中设计一个编译器,并且应该突出显示语法以使其对用户友好。 The syntax highlighting is working but im not able to edit the richtext.语法突出显示正在工作,但我无法编辑富文本。 I'm just able to copy paste a code and the syntax is changing styles.我只能复制粘贴代码,并且语法正在更改 styles。 I want to be able to edit the Text in RichText我希望能够在 RichText 中编辑文本

Present Code当前代码

RichText(
            textScaleFactor: _baseFontScale,
            text: TextSpan(
              style: TextStyle(fontFamily: 'monospace', fontSize: 12, height: 1.13),
              children: <TextSpan>[
                getSyntax(widget.syntax, widget.syntaxTheme).format(widget.code)
              ],
            ),
          ),

Im currently using stack and placing another textfield in the same place to achieve this but its not going so good.我目前正在使用堆栈并将另一个文本字段放在同一个地方来实现这一点,但它并不那么好。 Any help is appreciated.任何帮助表示赞赏。

see this package -- extended_text_field看到这个 package -- extended_text_field

@pskink, You great answer must be an answer here too, not a comment: @pskink,您的好答案也必须是这里的答案,而不是评论:

It possible to colorize the TextField's content by overriding buildTextSpan method at used TextEditingController: see an example at pskink's answer in related question: https://stackoverflow.com/a/59773962/2064459可以通过在使用的 TextEditingController 上覆盖 buildTextSpan 方法来为 TextField 的内容着色:请参阅 pskink 在相关问题的回答中的示例: https://stackoverflow.com/a/59773962/2064459

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM