How to customize individual text in Flutter TextFields or TextFormFields in flutter











up vote
-1
down vote

favorite












I'm trying to style text as the user types into the TextField or TextFormField. For example links get underlined or emails get highlighted. Is there a way to do this? This is the approach I took, but I am having trouble formatting the string as shown in the code



class _MyCustomFormState extends State<MyCustomForm> {

final myController = TextEditingController();

@override
void initState() {
super.initState();

myController.addListener(_textListener);

}

_textListener(){

//Checks if the new string typed is an email and highlights it

List<String> _stringList = _controller.text.split(" ");
String _lastString = _stringList.last;

if(_isEmail(_lastString)){

//Format _lastString (this is the problem)

}

//Remove the last string and add the formatted version
_stringList.removeLast();
_stringList.add(_lastString);
_controller.text = _stringList.join(" ");
}

Widget _textField(){
return TextFormField(
keyboardType: TextInputType.multiline,
maxLines: null,
controller: _controller,);
}

}









share|improve this question
























  • Please specify what you have tried and if possible paste your code for reference.
    – Arnold Parge
    Nov 19 at 16:07










  • For underlined links you can use TextStyle. For highlightning you can use RichText, if I understood you right
    – Andrey Turkovsky
    Nov 19 at 16:34










  • @ArnoldParge I have attached the approach I am using.
    – T.Abs
    Nov 20 at 20:40










  • @AndreyTurkovsky that would work if I was assigning a style to the widget. However I am only trying to format one word in a string as shown in the sample code (just attached)
    – T.Abs
    Nov 20 at 20:41















up vote
-1
down vote

favorite












I'm trying to style text as the user types into the TextField or TextFormField. For example links get underlined or emails get highlighted. Is there a way to do this? This is the approach I took, but I am having trouble formatting the string as shown in the code



class _MyCustomFormState extends State<MyCustomForm> {

final myController = TextEditingController();

@override
void initState() {
super.initState();

myController.addListener(_textListener);

}

_textListener(){

//Checks if the new string typed is an email and highlights it

List<String> _stringList = _controller.text.split(" ");
String _lastString = _stringList.last;

if(_isEmail(_lastString)){

//Format _lastString (this is the problem)

}

//Remove the last string and add the formatted version
_stringList.removeLast();
_stringList.add(_lastString);
_controller.text = _stringList.join(" ");
}

Widget _textField(){
return TextFormField(
keyboardType: TextInputType.multiline,
maxLines: null,
controller: _controller,);
}

}









share|improve this question
























  • Please specify what you have tried and if possible paste your code for reference.
    – Arnold Parge
    Nov 19 at 16:07










  • For underlined links you can use TextStyle. For highlightning you can use RichText, if I understood you right
    – Andrey Turkovsky
    Nov 19 at 16:34










  • @ArnoldParge I have attached the approach I am using.
    – T.Abs
    Nov 20 at 20:40










  • @AndreyTurkovsky that would work if I was assigning a style to the widget. However I am only trying to format one word in a string as shown in the sample code (just attached)
    – T.Abs
    Nov 20 at 20:41













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I'm trying to style text as the user types into the TextField or TextFormField. For example links get underlined or emails get highlighted. Is there a way to do this? This is the approach I took, but I am having trouble formatting the string as shown in the code



class _MyCustomFormState extends State<MyCustomForm> {

final myController = TextEditingController();

@override
void initState() {
super.initState();

myController.addListener(_textListener);

}

_textListener(){

//Checks if the new string typed is an email and highlights it

List<String> _stringList = _controller.text.split(" ");
String _lastString = _stringList.last;

if(_isEmail(_lastString)){

//Format _lastString (this is the problem)

}

//Remove the last string and add the formatted version
_stringList.removeLast();
_stringList.add(_lastString);
_controller.text = _stringList.join(" ");
}

Widget _textField(){
return TextFormField(
keyboardType: TextInputType.multiline,
maxLines: null,
controller: _controller,);
}

}









share|improve this question















I'm trying to style text as the user types into the TextField or TextFormField. For example links get underlined or emails get highlighted. Is there a way to do this? This is the approach I took, but I am having trouble formatting the string as shown in the code



class _MyCustomFormState extends State<MyCustomForm> {

final myController = TextEditingController();

@override
void initState() {
super.initState();

myController.addListener(_textListener);

}

_textListener(){

//Checks if the new string typed is an email and highlights it

List<String> _stringList = _controller.text.split(" ");
String _lastString = _stringList.last;

if(_isEmail(_lastString)){

//Format _lastString (this is the problem)

}

//Remove the last string and add the formatted version
_stringList.removeLast();
_stringList.add(_lastString);
_controller.text = _stringList.join(" ");
}

Widget _textField(){
return TextFormField(
keyboardType: TextInputType.multiline,
maxLines: null,
controller: _controller,);
}

}






flutter






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 at 22:22

























asked Nov 19 at 16:04









T.Abs

11




11












  • Please specify what you have tried and if possible paste your code for reference.
    – Arnold Parge
    Nov 19 at 16:07










  • For underlined links you can use TextStyle. For highlightning you can use RichText, if I understood you right
    – Andrey Turkovsky
    Nov 19 at 16:34










  • @ArnoldParge I have attached the approach I am using.
    – T.Abs
    Nov 20 at 20:40










  • @AndreyTurkovsky that would work if I was assigning a style to the widget. However I am only trying to format one word in a string as shown in the sample code (just attached)
    – T.Abs
    Nov 20 at 20:41


















  • Please specify what you have tried and if possible paste your code for reference.
    – Arnold Parge
    Nov 19 at 16:07










  • For underlined links you can use TextStyle. For highlightning you can use RichText, if I understood you right
    – Andrey Turkovsky
    Nov 19 at 16:34










  • @ArnoldParge I have attached the approach I am using.
    – T.Abs
    Nov 20 at 20:40










  • @AndreyTurkovsky that would work if I was assigning a style to the widget. However I am only trying to format one word in a string as shown in the sample code (just attached)
    – T.Abs
    Nov 20 at 20:41
















Please specify what you have tried and if possible paste your code for reference.
– Arnold Parge
Nov 19 at 16:07




Please specify what you have tried and if possible paste your code for reference.
– Arnold Parge
Nov 19 at 16:07












For underlined links you can use TextStyle. For highlightning you can use RichText, if I understood you right
– Andrey Turkovsky
Nov 19 at 16:34




For underlined links you can use TextStyle. For highlightning you can use RichText, if I understood you right
– Andrey Turkovsky
Nov 19 at 16:34












@ArnoldParge I have attached the approach I am using.
– T.Abs
Nov 20 at 20:40




@ArnoldParge I have attached the approach I am using.
– T.Abs
Nov 20 at 20:40












@AndreyTurkovsky that would work if I was assigning a style to the widget. However I am only trying to format one word in a string as shown in the sample code (just attached)
– T.Abs
Nov 20 at 20:41




@AndreyTurkovsky that would work if I was assigning a style to the widget. However I am only trying to format one word in a string as shown in the sample code (just attached)
– T.Abs
Nov 20 at 20:41

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378523%2fhow-to-customize-individual-text-in-flutter-textfields-or-textformfields-in-flut%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378523%2fhow-to-customize-individual-text-in-flutter-textfields-or-textformfields-in-flut%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'