簡體   English   中英

如何為 Flutter 文本字段中的不同文本行設置不同的 colors?

[英]How to set different colors for different lines of text in a Flutter textfield?

在此處輸入圖像描述

我正在嘗試創建一個文本機器人,我需要該機器人的 output 具有不同的顏色。 而且我需要文本是可編輯的,所以它需要在文本字段中。 目前,當我收到 output 時,我將文本字段文本設置為更新后的 output。

文本字段的代碼:

 child: TextField(
                  controller: textFieldController,
                  expands: true,
                  maxLines: null,
                  style: const TextStyle(
                    color: Colors.blue,
                  ),
                  decoration: const InputDecoration(
                    border: InputBorder.none,
                    hintText: 'Enter prompt',
                    hintStyle: TextStyle(
                      color: AppColors.darkText,
                      fontSize: 20,
                    ),
                  ),
                ),

設置TextField文本的代碼

conversationList.add(output);
conversation = conversationList.join("");
textFieldController.clear();
textFieldController.text = conversation;

我已經嘗試過像detectable_text_field這樣的包,但它不起作用,因為 output 發生了變化。

認為你只能使用富文本編輯器。 嘗試使用flutter_quill package。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM