Add text field with text paragraph in Flutter - flutter

I am trying to add a text field inside the paragraph in flutter but not getting success below screen shot what I want to achive.
I am trying the below code
RichText(
text: TextSpan(
text: "“",
style: TextStyle(
color:
const Color(0xff56A1D5),
fontSize: 20.sp),
children: <InlineSpan>[
WidgetSpan(
child: Text(
"I want to talk with you about ",
textAlign: TextAlign.center,
style: TextStyle(
color: const Color(
0xff506274),
fontSize: 20.sp),
),
),
const WidgetSpan(
child: SizedBox(
width: 120,
child: TextField(
decoration:
InputDecoration(
isDense: true,
contentPadding:
EdgeInsets.all(0),
),
),
),
),
WidgetSpan(
child: Text(
"(the actions, attitude, or behavior)",
textAlign: TextAlign.center,
style: TextStyle(
color: const Color(
0xff506274),
fontSize: 20.sp),
),
),
],
),
),
But My output is look like below.
Can anyone show me where I am going to wrong or How can I achieve the same as the above image without leaving extra space?
Thanks in advance.

Your code is perfectly right. as (the actions, attitude, or behavior) this text does not fit in the screen it came into a new line. For checking this reduce your text then you may understand the issue.
Your code output when I run your code:
Desktop:
Mobile:

Related

How to align the icon relative to the text in RichText?

I have a text located in RichText, n how much later I want to make it clickable, there is an icon next to the text. The problem is that the icon does not align correctly relative to the text, this is especially noticeable when its size increases. How do I make the icon and text to be on the same line in the center ? Align centered doesn't help
RichText(
textAlign: TextAlign.center,
text: TextSpan(
children: [
TextSpan(text: 'Next ', style: richBotton),
WidgetSpan(
child: Icon(Icons.arrow_forward_ios, color: Colors.grey, size: 11,)
),
],
),
),
for styles
final richBotton = const TextStyle(color: Color.fromARGB(255, 117, 117, 117), fontSize: 11,);
final text = const TextStyle(color: Colors.grey, fontSize: 11);
Screen
My code
With alignment: PlaceholderAlignment.Middle
With alignment: PlaceholderAlignment.Top
With alignment: PlaceholderAlignment.Bottom
You can include alignment: PlaceholderAlignment.middle on WidgetSpan.
RichText(
textAlign: TextAlign.center,
text: TextSpan(
children: [
TextSpan(
text: 'Next ',
),
WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: Icon(
Icons.arrow_forward_ios,
color: Colors.grey,
size: 11,
)),
],
),
),

How can I modify the size of my TextButton so that it is equal to it's child Text widget's height in Flutter?

I am creating an App Login page using Flutter framework and I want the the TextButton as well as the "Forgot password?" text to be horizontally aligned in the screen, but the following code displays the button below the "Forgot Password?" text. I tried modifying the button's height and width parameters as well as modifying the spacing in the Wrap widget but I still didn't get the expected outcome. Wrapping the TextButton with SizedBox widget too didn't worked as it hid the button from the screen. Is there any other way to get the desired outcome?
Part of the screen where the TextButton and "Forgot password?" text is displayed
Wrap(
children: [
Text(
"Forgot password?",
style: GoogleFonts.poppins(
color: Colors.white,
fontSize: 16.0,
),
),
TextButton(
onPressed: () {},
child: Text(
"Click here",
style: GoogleFonts.poppins(
color: Colors.white,
fontSize: 16.0,
decoration: TextDecoration.underline,
),
),
),
],
),
if you want to Align your two buttons horizontally, just wrap them with a Row widget, userSizedbox to adjust space between them, and if necessary wrap the Row with Padding to adjust the location of buttons like;
Padding(
padding: const EdgeInsets.only(left: 10, right: 10),
child: Row(
children: [
Text(
"Forgot password?",
style: GoogleFonts.poppins(
color: Colors.white,
fontSize: 16.0,
),
),
SizedBox(height: 10,),
TextButton(
onPressed: () {},
child: Text(
"Click here",
style: GoogleFonts.poppins(
color: Colors.white,
fontSize: 16.0,
decoration: TextDecoration.underline,
),
),
),
],
),
),
Try to below code hope its helpful to you. Wrap your Text and TextButton widget inside Row().
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Text(
"Forgot password?",
),
TextButton(
onPressed: () {
//Write here your onPressed function call
print('Button Pressed!');
},
child: Text(
"Click here",
),
),
],
),
Your Result Screen->
There is another approach to overcome this with RichText, TextSpan and TapGestureRecognizer.
To use TapGestureRecognizer, you will have to import 'package:flutter/gestures.dart'
RichText(
text: TextSpan(
text: "Forgot password? ",
style: GoogleFonts.poppins(
color: Colors.white,
fontSize: 16.0,
),
children: [
TextSpan(
text: "Click here",
style: GoogleFonts.poppins(
color: Colors.white,
fontSize: 16.0,
decoration: TextDecoration.underline,
),
recognizer: TapGestureRecognizer()
..onTap = () => {},
),
],
),
)
You can use this instead of using a TextButton.
Result is as below.

How to produce Flutter Text Field that underline incorrect words with suggestion provided?

A picture is worth a thousand words, let me show you what I tried to achieve:
The solution could be using Flutter built-in widget or third-party widget.
Anyone?
You could use the Text.rich() method (or the RichText Widget) to achieve what you want.
The following snippet corresponds to your screenshot.
return Scaffold(
body: Center(
child: Text.rich(
TextSpan(
text: 'I lost ',
style: TextStyle(fontSize: 24),
children: <TextSpan>[
TextSpan(
text: 'Password.',
style: TextStyle(
decoration: TextDecoration.underline,
)),
TextSpan(
text: ' ',),
TextSpan(
text: 'What do?',
style: TextStyle(
decoration: TextDecoration.underline,
)),
// can add more TextSpans here...
],
),
),
),
);

Overflowing comment text not in alignment

I want to achieve following layout
There is profile picture, followed by username and followed by comment.But if the comment is too long it should starting coming below the username and not from the profile picture.
Following is my code
Row(
children: [
const CircleAvatar(
backgroundImage: NetworkImage(
'https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcTTul_FjIE5w2p_VarQyzwaZ1mkOYjQRXcNCA&usqp=CAU'),
radius: 16,
),
const SizedBox(
width: 10,
),
Text(
'UserName',
style: GoogleFonts.tenorSans(
color: Colors.black),
),
Text(
'The Dram Club is a platform that endeavours to bring whisky enthusiassts & aficionados together for people to enjoy their whiskes',
style: GoogleFonts.tenorSans(
color: Colors.black,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.italic),
)
],
)
For the above code the comment text gets cuts off if its large so instead of using Row I decided to use Wrap but that is moving my enter comment in a new Row. I just tried wrapping the username and comment text in a Wrap but nothing happens. I tried using Flexible and Expanded widget as well
You can use this code.
Row(
children: [
const CircleAvatar(
backgroundImage: NetworkImage(
'https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcTTul_FjIE5w2p_VarQyzwaZ1mkOYjQRXcNCA&usqp=CAU'),
radius: 16,
),
const SizedBox(
width: 10,
),
Flexible(
child: RichText(
text: TextSpan(
children: <TextSpan>[
TextSpan(text: 'Username ', style: TextStyle(fontSize: 18, color: Colors.black)),
TextSpan(text: 'The Dram Club is a platform that endeavours to bring whisky enthusiassts & aficionados together for people to enjoy their whiskes', style: TextStyle( color: Colors.black, fontSize: 16)),
],
),
),
)
],
),
Use RichText class, in this you can add multiple text with different styles. So the idea is
To have a single text, with different styles, one for UserName and other for Comment
children: [
CircleAvatar(
backgroundImage: NetworkImage('https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcTTul_FjIE5w2p_VarQyzwaZ1mkOYjQRXcNCA&usqp=CAU'),
radius: 16,
),
SizedBox(
width: 10,
),
// here for User name and Comment
RichText(
text: TextSpan(
text: 'UserName ', // <-- Username text
style: GoogleFonts.tenorSans(color: Colors.black), // <-- User name style
children: <TextSpan>[
// your comment code
TextSpan(text: 'The Dram Club is a platform that endeavours to bring whisky enthusiassts & aficionados together for people to enjoy their whiskes',
style: GoogleFonts.tenorSans(color: Colors.black,fontWeight: FontWeight.bold, fontStyle: FontStyle.italic)))
]
)
)
]

Flutter: Links in long text like Privacy policy and Tems of Service

I'm trying to make privacy policy and terms of service link.
Widget privacyPolicyLinkAndTermsOfService() {
return Container(
child: Center(
child: Text(
'By continuing, you agree to our Terms of Service and Privacy Policy.',
style: TextStyle(
fontSize: 14.0,
),
),
),
);
In this way the text doesn't overflow but I cannot make a part of text link. So I tried to use Row and separate the text and the link part as children.
However, the text overflows when I use Row and separate text as children.
How can I prevent them from overflowing while making a part of text link?
Use RichText class to link parts of text. It's constructor text.rich allows us to style different parts of the text. Below is the working code that only shows links for Terms of Service and Privacy Policy which user can tap on to open respective links and rest of the text is plain text:
Widget privacyPolicyLinkAndTermsOfService() {
return Container(
alignment: Alignment.center,
padding: EdgeInsets.all(10),
child: Center(
child: Text.rich(
TextSpan(
text: 'By continuing, you agree to our ', style: TextStyle(
fontSize: 16, color: Colors.black
),
children: <TextSpan>[
TextSpan(
text: 'Terms of Service', style: TextStyle(
fontSize: 16, color: Colors.black,
decoration: TextDecoration.underline,
),
recognizer: TapGestureRecognizer()
..onTap = () {
// code to open / launch terms of service link here
}
),
TextSpan(
text: ' and ', style: TextStyle(
fontSize: 18, color: Colors.black
),
children: <TextSpan>[
TextSpan(
text: 'Privacy Policy', style: TextStyle(
fontSize: 18, color: Colors.black,
decoration: TextDecoration.underline
),
recognizer: TapGestureRecognizer()
..onTap = () {
// code to open / launch privacy policy link here
}
)
]
)
]
)
)
),
);
}
Above code is rendered in UI as:
TapGestureRecognizer() method requires you to import below file:
import 'package:flutter/gestures.dart';
Hope this answers your question.