-
Notifications
You must be signed in to change notification settings - Fork 28.9k
Closed
Labels
P1High-priority issues at the top of the work listHigh-priority issues at the top of the work lista: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemsc: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterf: material designflutter/packages/flutter/material repository.flutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.waiting for customer responseThe Flutter team cannot make further progress on this issue until the original reporter respondsThe Flutter team cannot make further progress on this issue until the original reporter responds
Description
I don't need a passage editor like Zefyr which has styles like BOLD and ITALIC, what I want is a text field in which I can insert plain text, inline image(faces/emoji), block image, mention symbol(@) and topic symbol(#topic#).
It can be implemented on Android by SpannableString. I hope I can do it on Flutter, too.
So anyone knows how to do this?
rohanchandra, simc, Jethro87, pinyin, sullenel and 52 moremr-mamali, brianschardt, TeddyLourson, mindeng, antonygunawan94 and 3 moreSp4Rx, jamesblasco, lxrite, rohanchandra, gliese667c and 17 more
Metadata
Metadata
Assignees
Labels
P1High-priority issues at the top of the work listHigh-priority issues at the top of the work lista: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemsc: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterf: material designflutter/packages/flutter/material repository.flutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.waiting for customer responseThe Flutter team cannot make further progress on this issue until the original reporter respondsThe Flutter team cannot make further progress on this issue until the original reporter responds
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
HansMuller commentedon Jun 21, 2019
cc @GaryQian
GaryQian commentedon Jun 27, 2019
Text.rich
supports building text from a tree ofInlineSpan
s, which in turn support any of the properties inTextStyle
. We have recently added support for inline widgets. Simply include aWidgetSpan
in yourInlineSpan
tree. This includes images, as well as any other arbitrary widget. You can add a @ symbol and make it linkable by adding aGestureRecognizer
in aTextSpan
.Please refer to our (master channel) docs for more info.
janheinrichmerker commentedon Jul 12, 2019
@GaryQian I don't think you've fully understood the issue.
There is
Text.rich()
which allows for formatting aTextWidget
, but there is noTextField
which could be styled like that.GaryQian commentedon Jul 12, 2019
Ahh I see, my bad! I don't think there is a built in way right now, but the building blocks are there, it is a matter of assembling them such that we allow inputting custom
InlineSpan
trees into a text field.Sp4Rx commentedon Jul 24, 2019
Could you elaborate about the implementation? @GaryQian
GaryQian commentedon Jul 24, 2019
So what kind of functionality would you require for this "Rich TextField"? We currently have the InlineSpan tree API that allows you to build a tree of InlineSpan objects that inherit TextStyles.
Would the functionality of being able to append independently styled InlineSpans to the contents of the TextField be sufficient?
Sp4Rx commentedon Jul 25, 2019
As I can see from InlineSpan example that it can have multiple
TextField
with different styles. But I want a singleTextField
where I can insert different styles just like RichText. For example take Facebook's or any major platform's@mention
. In java I have done this with SpannableString like @nullptrjzz mentioned.GaryQian commentedon Jul 26, 2019
Well since we don't have this explicit capability yet, it would be helpful if you could provide pseudo/fake sample code on how you would like the API to work.
There are a couple of ways this could work, one of them being keeping a stack of TextStyles and push/pop methods. Any text inserted through keyboard or through a manual method would then have the style the top TextStyle in the stack. This system would be very similar to our existing ParagraphBuilder works.
Other approaches could be either more or less structured, but it would be very helpful to have examples of the kind of code you want to be able to write to achieve what you want. Feel free to make up methods/classes/API! This way, we can add the functionality that would best fit your (and other's uses)
Sp4Rx commentedon Jul 27, 2019
Flutter has a class called Chip. I don't know it is the right question to ask or not, is it possible to insert
Chip
inTextField
?As flutter don't provide inserting styling by positions like SpannableString so I can think of the pseudo code similar to
RichText
67 remaining items
GaryQian commentedon Jul 20, 2021
@jasonhoo95 This particular issue is actually more difficult to solve depending on what you want. Currently, the background color is drawn as part of the text layout and painting, while the selection highlight is drawn separately. We are presented with two options: Draw highlight behind the text (including the bg) or over the text (including bg). For most cases, drawing behind is correct as we want the text to remain readable. However, in this case, the bg just ends up obscuring the highlight.
You could try modifying RenderEditable to paint the highlight after the text and playing with the opacity, but it would still obscure the text. Slipping the highlight between the text and the bg is a fairly complex change that modifies the layout engine and I don't think there is enough demand for that capability to justify it as of now.
jasonhoo95 commentedon Jul 22, 2021
@GaryQian Hmm but can I ask, in ios native layout engine is possible to set the highlight to overlay above the bg and text am I right? Oo man this is bad, i was really hope to develop an app with rich textfield with flutter, cause flutter it is really easy to use, looks like now is not going to happen, but in the future will u able to fix it with highlight overlay on top bg?
derkro99 commentedon Aug 23, 2021
@Paul-cbt Did you manage to find a solution for this problem?
Edit: It turns out i was using the wrong channel. Using master channel "fixes" this
justin-m-lacy commentedon Sep 1, 2021
I seem to be having this same problem - and most likely for the same reason. I'm using custom widgets for tagged elements in input text but WidgetSpan appears to break TextField because of the dimensions issue.
Arrowsome commentedon Oct 15, 2021
Any update on this issue?
I Wanted to draw a simple rounded background color behind my text and it seems possible using WidgetSpan (or if Paint class supported rounded corners in fill style, which doesn't).
It's 2021 and I can't implement an effect from 2014 in Flutter!
wrteam-priyansh commentedon Nov 17, 2021
Hello @Teio07, can you please share some initial building blocks to build RichTextField with some basic functionality?
Thanks
hwasoocho commentedon Feb 13, 2022
Any progress on this issue?
Renzo-Olivares commentedon Mar 17, 2022
I made a simple example to show that
WidgetSpans
render inside of aTextField
inline with other text. Core support for this was added in #83537 . Is this what this issue is asking for? If not please explain further.yohom commentedon Mar 18, 2022
@Renzo-Olivares
The
buildTextSpan
renders WidgetSpan successfully in a TextField, but the cursor can not locate to the last position. When you try to move the cursor to the last position, the cursor jumps to the first position.My
flutter doctor
:Screenrecorder-2022-03-18-09-00-36-63.mp4
Renzo-Olivares commentedon Mar 18, 2022
@yohom thanks for trying it out. I was able to reproduce your issue on stable as well. It is fixed on the master branch (video below).
screen-20220318-130824.mp4
I'll close this for now since core support for a WidgetSpan in a TextField/RenderEditable is there. If there are more specific issues with WidgetSpan inside of a TextField I encourage anyone to open a more targeted issue.
github-actions commentedon Apr 1, 2022
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -v
and a minimal reproduction of the issue.