I am trying to make space between TextSpan
What is the best way to add space between TextSpan?
child: RichText(
text: TextSpan(
children: [
TextSpan(
text: 'Don\'t have an Account?',
style: TextStyle(
color: Colors.white,
fontSize: 15.0,
fontWeight: FontWeight.w400,
),
),
TextSpan(
text: 'Sign Up',
style: TextStyle(
color: Colors.white,
fontSize: 15.0,
fontWeight: FontWeight.bold,
),
),
],
),
),
SizedBox widget can be used in between two widgets to add space between two widgets.
use the SizedBox by wrapping it with a WidgetSpan widgit
child: RichText(
text: TextSpan(
children: [
TextSpan(
text: 'Don\'t have an Account?',
style: TextStyle(
color: Colors.white,
fontSize: 15.0,
fontWeight: FontWeight.w400,
),
),
WidgetSpan(
child: SizedBox(width: 10),
),
TextSpan(
text: 'Sign Up',
style: TextStyle(
color: Colors.white,
fontSize: 15.0,
fontWeight: FontWeight.bold,
),
),
],
),
),
If you like to get maximum space between text, you might go for Row widget. For x amount of space inside RichText you can use
TextSpan(...),
WidgetSpan(child: SizedBox(width: x)),
TextSpan(...),
RichText(
text: const TextSpan(
children: [
TextSpan(
text: 'Don\'t have an Account?',
style: TextStyle(
color: Color.fromARGB(255, 0, 0, 0),
fontSize: 15.0,
fontWeight: FontWeight.w400,
),
),
WidgetSpan(child: SizedBox(width: 10)), ///this
TextSpan(
text: 'Sign Up',
style: TextStyle(
color: Color.fromARGB(255, 0, 0, 0),
fontSize: 15.0,
fontWeight: FontWeight.bold,
),
),
],
),
),
You can use the height property on the TextStyle to create some spacing:
RichText(
text: TextSpan(
children: [
TextSpan(
text: 'Don\'t have an Account?',
style: TextStyle(
height: 1.5, //USE THIS PROPERTY
color: Colors.white,
fontSize: 15.0,
fontWeight: FontWeight.w400,
),
),
SizedBox(height: 10),
TextSpan(
text: 'Sign Up',
style: TextStyle(
color: Colors.white,
fontSize: 15.0,
fontWeight: FontWeight.bold,
),
),
],
),
),
More info in the docs: https://api.flutter.dev/flutter/painting/TextStyle/height.html
Related
My code prints device characteristics. But if the text is too long, then the text is displayed ugly(as in the photo 1). I tried to fix it in different ways, but only title changes for me, trailing remains unchanged.
Can it be done in this way, if the text is long, then title is displayed in one line, and the next trailing (as in the photo 2)?
body: SingleChildScrollView(
child: Align(
alignment: Alignment.topCenter,
child: Column(
children: [
Container(
constraints: const BoxConstraints(maxWidth: 800),
decoration: BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.circular(5.0),
),
child: Card(
child: Column(
children: [
ListTile(
title: const Text('Brand:', style: TextStyle(fontWeight: FontWeight.w400, fontSize: 25)),
trailing: Text('${device.brand} ', style: const TextStyle(fontWeight: FontWeight.w400, fontSize: 20 ))),
const Divider(color: Colors.black, endIndent: 10, indent: 10),
ListTile(
title: const Text('Operation system:', style: TextStyle(fontWeight: FontWeight.w400, fontSize: 25)),
trailing: Text('${device.operation_system} ', style: const TextStyle(fontWeight: FontWeight.w400, fontSize: 20 ))),
const Divider(color: Colors.black, endIndent: 10, indent: 10),
ListTile(
title: const Text('Version of OS:', style: TextStyle(fontWeight: FontWeight.w400, fontSize: 25)),
trailing: Text('${device.version_OS} ', style: const TextStyle(fontWeight: FontWeight.w400, fontSize: 20 ))),
const Divider(color: Colors.black, endIndent: 10, indent: 10),
],
),
),
),
]
)
)
)
One option would be to remove trailing from ListTile and use RichText and TextSpan for title like so:
ListTile(
title: RichText(
text: TextSpan(
style: Theme.of(context).textTheme.headline6,
children: [
const TextSpan(
text: 'Version of OS: ',
style: TextStyle(
fontWeight: FontWeight.w400,
fontSize: 25,
),
),
TextSpan(
text: '${device.version_OS}',
style: TextStyle(
fontWeight: FontWeight.w400,
fontSize: 20,
),
),
],
),
),
),
Try below code hope its helpful to you.
Card(
child: ListTile(
leading: Text(
'Version of OS',
style: TextStyle(
fontWeight: FontWeight.w400,
fontSize: 20,
overflow:TextOverflow.ellipsis,
),),
title: Text('Your version with version 1.0'),
trailing: Text('Nokia'),
),
),
I want to set a black heart between "m" and "ms". and also I want to use "TextAlign.justify". if I use "TextAlign.center" then it's working fine. but if I use "TextAlign.justify" so the black heart is not set in the correct place. If I remove the "WidgetSpan" widget and add "TextSpan" for a black heart so also it's working. but I want to add bottom padding.
Please guys help me.
Thanks
Text.rich(
TextSpan(
children: <InlineSpan>[
TextSpan(
text: MyString.txtAboutUs ,
style: TextStyle(
fontSize: FontSize.size14,
fontFamily: MyFont.poppins_regular)),
TextSpan(
text: " m",
children: <InlineSpan>[
WidgetSpan(
baseline: TextBaseline.ideographic,
alignment: PlaceholderAlignment.top,
child: Container(
padding: EdgeInsets.only(bottom: 3),
child: Text("🖤", style: TextStyle(
fontSize: FontSize.size8,
fontFamily: MyFont.poppins_regular) ),
)
),
TextSpan(
text: "ms ",
style: TextStyle(
fontSize: FontSize.size14,
fontFamily: MyFont.poppins_medium,
color: Colors.black,
fontWeight: FontWeight.bold)),
],
style: TextStyle(
fontSize: FontSize.size14,
fontFamily: MyFont.poppins_medium,
color: Colors.black,
fontWeight: FontWeight.bold)),
TextSpan(
text: MyString.txtAboutImmediately,
style: TextStyle(
fontSize: FontSize.size14,
fontFamily: MyFont.poppins_regular)),
],
),
textAlign: TextAlign.justify,
),
Try to below simple Text Widget
Text('you add 🖤 here'),
// OR
Text('you add \u{2764} here} '),
Updated Answer using RichText
Center(
child: Text.rich(
TextSpan(
children: <TextSpan>[
TextSpan(
text: 'You add ',
style: TextStyle(
fontSize: 10.0,
color: Colors.black,
),
),
TextSpan(
text: '🖤',
),
TextSpan(
text: 'Here',
),
],
),
textAlign: TextAlign.center,
style: TextStyle(fontSize: 10.0,),
),
),
Screen like
replace padding with transform.
WidgetSpan(
baseline: TextBaseline.ideographic,
alignment: PlaceholderAlignment.top,
child: Container(
transform: Matrix4.translationValues(0, -3, 0),
margin: EdgeInsets.only(bottom: 8),
child: Text(
"🖤",
style: TextStyle(
// fontSize: FontSize.size8,
// fontFamily: MyFont.poppins_regular,
),
),
),
),
Im trying getting some space in Richttext. First heres my code
title: RichText(
text: TextSpan(
text: _snapshot.data['username'], // _snapshot.data['username']
style: TextStyle(fontWeight: FontWeight.bold, color: Colors.black),
children: <TextSpan>[
TextSpan(
//"${comment.data()['comment']}"
text: "${comment.data()['comment']}",
style: TextStyle(
fontWeight: FontWeight.normal,
),
)
],
),
)
And what I want is some space between the this
text: TextSpan(
text: _snapshot.data['username'], // _snapshot.data['username']
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black,
)
And this
children: <TextSpan>[
TextSpan(
//"${comment.data()['comment']}"
text: "${comment.data()['comment']}",
style: TextStyle(
fontWeight: FontWeight.normal,
),
],
),
Hope anyone can help. If you need a picture how it looks at the moment please leave a comment
You can use a SizedBox like below :
RichText(
text: TextSpan(
text: "Test:",
style: TextStyle(fontWeight: FontWeight.bold, color: Colors.black),
children: <InlineSpan>[
WidgetSpan(
alignment: PlaceholderAlignment.baseline,
baseline: TextBaseline.alphabetic,
child: SizedBox(width: 10)),
TextSpan(
text: "Data",
style: TextStyle(
fontWeight: FontWeight.normal,
),
)
],
),
)
Is there a way to achieve the following results in Flutter where the underline below text will be nicely hidden by the padding around letters that overflow it, such as 'g', 'q', 'y', etc?
Emulator (current):
Design (desired):
Font: Spartan
The best way I found to achieve that was to use text stroke and Stack to create the underline effect. Here is the code:
Align(
alignment: Alignment.centerLeft,
child: Container(
padding: EdgeInsets.symmetric(vertical: 6.0),
child: Stack(
children: [
Positioned(
bottom: 2,
left: 0,
right: 0,
child: Container(height: 1.0, color: const Color(0xFF2F3543)),
),
Text(
"Forgot password?",
style: TextStyle(
fontWeight: FontWeight.w300,
inherit: true,
fontSize: 13.0,
foreground: Paint()
..style = PaintingStyle.stroke
..strokeWidth = 2
..color = Colors.white,
),
),
Text(
"Forgot password?",
style: TextStyle(
color: const Color(0xFF2F3543),
fontWeight: FontWeight.w300,
inherit: true,
fontSize: 13.0,
),
)
],
),
),
)
And the screenshot of the results
EDIT
The first one looks working but not looks good and the second one working fine but p word not that good.
When you dont want to add underline just write decoration:TextDecoration.none.
Text.rich(
TextSpan(
text: 'For ',
style: TextStyle(decoration: TextDecoration.underline, fontSize: 25),
children: <TextSpan>[
TextSpan(text: 'g',style:TextStyle(decoration: TextDecoration.none)),
TextSpan( text: ' ',style:TextStyle(decoration: TextDecoration.underline, decorationThickness: 1)),
TextSpan( text: ' p',style:TextStyle(decoration: TextDecoration.none,)),
TextSpan( text: 'assword?',style:TextStyle(decoration: TextDecoration.underline)),
//you can add more text span here
],
),
),
Row(
children: <Widget>[
Text('For', style: TextStyle(decoration: TextDecoration.underline, fontSize: 25)),
Text('g', style: TextStyle(decoration: TextDecoration.none, fontSize: 25)),
Text('ot', style: TextStyle(decoration: TextDecoration.underline, fontSize: 25)),
Text(' ', style: TextStyle(decoration: TextDecoration.underline, fontSize: 25)),
Text('p', style: TextStyle(decoration: TextDecoration.none, fontSize: 25)),
Text('assword', style: TextStyle(decoration: TextDecoration.underline, fontSize: 25)),
],
)
Working example image
How do I create the picture below in flutter. I tried using Richtext and widget span (clickable icon) but getting an error with widget span.. Is there another method to do this with a different layout without widgetspan
here my code
Expanded(
child: RichText(
text: new TextSpan(
children: [
TextSpan(
text:
'Email me career-related updates and job opportunities. company ',
style: TextStyle(
color: Palette.DARK_BLUE, fontSize: 16.0),
),
TextSpan(
text: 'privacy policy',
style: TextStyle(
color: Palette.DARK_BLUE,
fontSize: 16.0,
decoration: TextDecoration.underline),
recognizer: TapGestureRecognizer()
..onTap = () {
launch('https://www.google.com');
},
),
TextSpan(
text: ' and ',
style: TextStyle(
color: Palette.DARK_BLUE, fontSize: 16.0),
),
TextSpan(
text: 'terms of use ',
style: TextStyle(
color: Palette.DARK_BLUE,
fontSize: 16.0,
decoration: TextDecoration.underline),
recognizer: TapGestureRecognizer()
..onTap = () {
launch('https://www.google.com/');
},
),
WidgetSpan(
child: Container(
child: Icon(
Icons.info_outline,
color: Colors.red,
),
),
)
],
),
),
),