How I can make outlined text for Text widget? It's like stroke effect
You could try this option: https://stackoverflow.com/a/53211151/1534666
Copy of answer:
I was also looking for this, wasn't able to find it. But I did find a workaround using 4 shadows in the TextStyle:
Text("Border test",
style: TextStyle(
inherit: true,
fontSize: 48.0,
color: Colors.pink,
shadows: [
Shadow( // bottomLeft
offset: Offset(-1.5, -1.5),
color: Colors.white
),
Shadow( // bottomRight
offset: Offset(1.5, -1.5),
color: Colors.white
),
Shadow( // topRight
offset: Offset(1.5, 1.5),
color: Colors.white
),
Shadow( // topLeft
offset: Offset(-1.5, 1.5),
color: Colors.white
),
]
),
);
I also opened an Issue on GitHub: https://github.com/flutter/flutter/issues/24108
UPD:
I wouldn't call it the best solution, but it works
Stack(
children: <Widget>[
Text(
'TEXT',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.purple,
fontWeight: FontWeight.bold,
fontSize: 36.0),
),Text(
'TEXT',
textAlign: TextAlign.center,
style: TextStyle(
foreground: Paint()..color = Colors.white..style = PaintingStyle.stroke..strokeWidth = 1.0,
fontWeight: FontWeight.bold,
fontSize: 36.0),
),
],
);
In TextStyle you can't define both color and foreground, so I've tried to use Stack with two identical Texts with different decorations.
As I said - not the best solution, but maybe it'll be suitable for someone
style: GoogleFonts.londrinaOutline(),
This is simple but not perfect....!
Use bordered_text package
BorderedText(
strokeColor: Colors.white,
strokeWidth: 6,
child: Text(
'Bordered Text',
style: const TextStyle(
fontSize: 130,
fontWeight: FontWeight.bold,
color: blackColor
),
),
),
Related
I'm new to flutter want to create below send again text as a button. How can I do that? appreciate your help on this.
Align(
alignment: Alignment.bottomLeft,
child: Text(
'send again ',
style: TextStyle(
height: 1.2,
fontFamily: 'Dubai',
fontSize: 13,
color: Colors.blue,
fontWeight: FontWeight.w500,
)
)
)
You can use the TextButton widget for this
TextButton(
style: TextButton.styleFrom(
TextStyle(
height: 1.2,
fontFamily: 'Dubai',
fontSize: 13,
color: Colors.blue,
fontWeight: FontWeight.w500,
),
),
onPressed: () {},
child: const Text('Send again'),
or you can just wrap your Text widget with gestureDetector
Align(
alignment: Alignment.bottomLeft,
child: GestureDetector(
onTap: () {}
Text(
'send again ',
style: TextStyle(
height: 1.2,
fontFamily: 'Dubai',
fontSize: 13,
color: Colors.blue,
fontWeight: FontWeight.w500,
)
))
)
Align(
alignment: Alignment.bottomLeft,
child: InkWell(
onTap: () {
// add action here whatever you want.
},
child: Text('send again ',
style: TextStyle(
height: 1.2,
fontFamily: 'Dubai',
fontSize: 13,
color: Colors.blue,
fontWeight: FontWeight.w500,
)
),
)
)
In Flutter almost everything is a Widget. That means even a gesture detector is a widget.
Knowing that, and being able to create a Text widget you are half way there to your destination. You need to just wrap your Text widget with a TextButton that expects its child property to be a Widget and you could provide your Text widget as the child of the TextButton.
Here is the documentation for TextButton and that even includes a very good video on how to use TextButtons in Flutter.
This might work ,
TextButton(
child: Text('send again'),
style: TextButton.styleFrom(
primary: Colors.teal,
onPrimary: Colors.white,
textStyle: TextStyle(
color: Colors.black,
fontSize: 40,
fontStyle: FontStyle.italic
),
),
onPressed: () {
print('Pressed');
},
)
You can use buttons available in flutter like MaterialButton, TextButton, ElevatedButton, etc. or you can use InkWell or GestureDetector
Align(
alignment: Alignment.bottomLeft,
child: GestureDetector(
onTap: () {},
child: Text('send again ',
style: TextStyle(
height: 1.2,
fontFamily: 'Dubai',
fontSize: 13,
color: Colors.blue,
fontWeight: FontWeight.w500,
)),
))
Or
Align(
alignment: Alignment.bottomLeft,
child: InkWell(
onTap: () {},
child: Text('send again ',
style: TextStyle(
height: 1.2,
fontFamily: 'Dubai',
fontSize: 13,
color: Colors.blue,
fontWeight: FontWeight.w500,
)),
))
Or
Align(
alignment: Alignment.bottomLeft,
child: MaterialButton(
onPressed: (){},
child: Text('send again ',
style: TextStyle(
height: 1.2,
fontFamily: 'Dubai',
fontSize: 13,
color: Colors.blue,
fontWeight: FontWeight.w500,
)),
))
I have created a mobile application and I was using a font family called Baloo Paaji 2 from google and I have faced an issue of extra spacing created between my 2 text widgets. Below you can see the image of the view.
The text I am talking about is the Welcome! Lakshya Jain. The space between the 2 is way too much. There is no SizedBox or Padding added to the text widget. I tried using 2 different methods to see if the method was the problem. The 2 different methods are shown below.
Method 1
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Welcome !",
style: TextStyle(
color: Colors.white,
fontFamily: "BalooPaaji",
fontSize: 18.0,
fontWeight: FontWeight.w600,
),
),
Text(
userData.fullName,
style: TextStyle(
color: Colors.white,
fontFamily: "BalooPaaji",
fontSize: 24.0,
fontWeight: FontWeight.w900,
),
),
],
),
Method 2
Text.rich(
TextSpan(
text: "Welcome !\n",
style: TextStyle(
color: Colors.white,
fontFamily: "BalooPaaji",
fontSize: 18.0,
fontWeight: FontWeight.w600,
),
children: [
TextSpan(
text: userData.fullName,
style: TextStyle(
color: Colors.white,
fontFamily: "BalooPaaji",
fontSize: 24.0,
fontWeight: FontWeight.w900,
),
),
],
),
),
Now I used another method which fixed this issue but created another one.
The Method 3 Screenshot is as follows.
Now the spacing issue is fixed but it created as the text has moved down a little. I want it to be center without the huge gap.
The code for this method is as followed.
Stack(
alignment: Alignment.topLeft,
clipBehavior: Clip.none,
children: [
Text(
"Welcome !",
style: TextStyle(
color: Colors.white,
fontFamily: "BalooPaaji",
fontSize: 18.0,
fontWeight: FontWeight.w600,
),
),
Positioned(
top: 20.0,
child: Text(
userData.fullName,
style: TextStyle(
color: Colors.white,
fontFamily: "BalooPaaji",
fontSize: 24.0,
fontWeight: FontWeight.w900,
),
),
),
],
),
The full code for the whole header is as followed
class HomeHeader extends StatelessWidget {
#override
Widget build(BuildContext context) {
// Get User UID
final user = Provider.of<MyAppUser>(context);
return Stack(
clipBehavior: Clip.none,
children: [
Container(
padding: EdgeInsets.symmetric(horizontal: 15.0),
width: MediaQuery.of(context).size.width,
height: 230.0,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color.fromRGBO(255, 18, 54, 1.0),
Color.fromRGBO(255, 164, 29, 1.0),
],
),
borderRadius: BorderRadius.only(
bottomRight: Radius.circular(59.0),
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
StreamBuilder(
stream: DatabaseService(uid: user.uid).userData,
builder: (context, snapshot) {
UserDataCustomer userData = snapshot.data;
return Row(
children: [
ClipOval(
child: CachedNetworkImage(
height: 70,
width: 70,
imageUrl: userData.profilePicture,
),
),
SizedBox(
width: 10.0,
),
Stack(
alignment: Alignment.topLeft,
clipBehavior: Clip.none,
children: [
Text(
"Welcome !",
style: TextStyle(
color: Colors.white,
fontFamily: "BalooPaaji",
fontSize: 18.0,
fontWeight: FontWeight.w600,
),
),
Positioned(
top: 20.0,
child: Text(
userData.fullName,
style: TextStyle(
color: Colors.white,
fontFamily: "BalooPaaji",
fontSize: 24.0,
fontWeight: FontWeight.w900,
),
),
),
],
),
// Column(
// mainAxisAlignment: MainAxisAlignment.center,
// crossAxisAlignment: CrossAxisAlignment.start,
// children: [
// Text(
// "Welcome !",
// style: TextStyle(
// color: Colors.white,
// fontFamily: "BalooPaaji",
// fontSize: 18.0,
// fontWeight: FontWeight.w600,
// ),
// ),
// Text(
// userData.fullName,
// style: TextStyle(
// color: Colors.white,
// fontFamily: "BalooPaaji",
// fontSize: 24.0,
// fontWeight: FontWeight.w900,
// ),
// ),
// ],
// ),
// Text.rich(
// TextSpan(
// text: "Welcome !\n",
// style: TextStyle(
// color: Colors.white,
// fontFamily: "BalooPaaji",
// fontSize: 18.0,
// fontWeight: FontWeight.w600,
// ),
// children: [
// TextSpan(
// text: userData.fullName,
// style: TextStyle(
// color: Colors.white,
// fontFamily: "BalooPaaji",
// fontSize: 24.0,
// fontWeight: FontWeight.w900,
// ),
// ),
// ],
// ),
// ),
],
);
},
),
StreamBuilder(
stream: FirebaseFirestore.instance
.collection("Users Database")
.doc(user.uid)
.collection("Cart")
.snapshots(),
builder: (context, snapshot) {
int totalItems = 0;
if (snapshot.connectionState == ConnectionState.active) {
List documents = snapshot.data.docs;
totalItems = documents.length;
}
return GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => CartScreen(),
),
);
},
child: Container(
height: 40.0,
width: 40.0,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(
10.0,
),
),
child: Center(
child: Text(
"$totalItems" ?? "0",
style: TextStyle(
fontSize: 20.0,
fontFamily: "BalooPaaji",
fontWeight: FontWeight.w600,
color: Colors.black,
),
),
),
),
);
},
),
],
),
),
Positioned(
top: 200.0,
child: SearchBar(
width: MediaQuery.of(context).size.width * 0.83,
hintText: "Location",
),
),
],
);
}
}
Someone please help me and fix this issue as soon as possible.
I guess you are trying to reduce gap / padding between the 2 lines. If that is so, then the easiest way is to wrap them inside container and give it a fixed height. Check below.
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: 20, // assign height as per your choice
child: Text(
"Welcome !",
style: TextStyle(
color: Colors.white,
fontFamily: "BalooPaaji",
fontSize: 18.0,
fontWeight: FontWeight.w600,
),
),
),
Container(
height: 26, // assign height as per your choice
child: Text(
userData.fullName,
style: TextStyle(
color: Colors.white,
fontFamily: "BalooPaaji",
fontSize: 24.0,
fontWeight: FontWeight.w900,
),
),
),
],
),
NOTE: you can also give height inside the Text widget
Text(
userData.fullName,
style: TextStyle(
color: Colors.white,
fontFamily: "BalooPaaji",
fontSize: 24.0,
fontWeight: FontWeight.w900,
height: 1.2, // assign height to fontSize ratio as per your choice
),
),
Try to change :
This : fontWeight: FontWeight.w600,
To : fontWeight: FontWeight.w500,
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
I am using WavyAnimatedTextKit() from the animated_text_kit package to write the word "BROKEN" on my app's welcome screen.
Container(
margin: EdgeInsets.only(bottom: 60, top: 30),
height: 40,
child: WavyAnimatedTextKit(
isRepeatingAnimation: false,
text: ["BROKEN"],
textStyle: TextStyle(
fontSize: 35.0,
fontWeight: FontWeight.w700,
color: Colors.white,
),
),
),
After it's written on the screen, I would like to rotate animate the "K" by 180 degrees to the right.
I couldn't find a solution so far to rotate only a single character. Most solutions I found would only rotate the entire widget / Text.
Any ideas / solutions to animate a rotating character after the word is written on screen?
Thanks
Try to split the text into 3 part side by side:
Row(children:[
WavyAnimatedTextKit(
isRepeatingAnimation: false,
text: ["BRO"],
textStyle: TextStyle(
fontSize: 35.0,
fontWeight: FontWeight.w700,
color: Colors.white,
),
),
RotatedBox(
quarterTurns: 2,
child:
WavyAnimatedTextKit(
isRepeatingAnimation: false,
text: ["K"],
textStyle: TextStyle(
fontSize: 35.0,
fontWeight: FontWeight.w700,
color: Colors.white,
),
),
),
WavyAnimatedTextKit(
isRepeatingAnimation: false,
text: ["EN"],
textStyle: TextStyle(
fontSize: 35.0,
fontWeight: FontWeight.w700,
color: Colors.white,
),
),
],),
I'm having an issue with this, I need a CircleAvatar with a Radius of 35, but anything above 27, placed in a ListTile makes it an ellipse, constraining the height. In the container above it is displayed properly with Radius 40. Any ideas?
Card(
elevation: 0,
child: ListTile(
leading: CircleAvatar(
radius: 27,
backgroundImage: AssetImage('images/sophia_hs.jpg'),
),
title:
Text("Sophia Daniels",
style: TextStyle(
fontFamily: 'Roboto',
color: Colors.black,
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
subtitle:
Text("Casting Director",
style: TextStyle(
fontFamily: 'Roboto',
color: Colors.black,
fontSize: 16,
fontWeight: FontWeight.normal,
),
),
),
),
Container(
height: 120,
color: Color(0xffffd504),
child: Center(
child: ListTile(
leading: CircleAvatar(
radius: 40,
backgroundImage: AssetImage('images/sophia_hs.jpg'),
),
dense: false,
title: Text("Sophia Daniels",
style: TextStyle(
fontFamily: 'Roboto',
color: Colors.black,
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
subtitle: Text("Casting Director",
style: TextStyle(
fontFamily: 'Roboto',
color: Colors.black,
fontSize: 16,
fontWeight: FontWeight.normal,
),
),
),
),
),
enter image description here
Try to edit the height of the container and make it bigger than 120.
You could also try Image.Asset() to load images from assets. They have more ability to fit the image according to it's size.
As a workaround, wrap the "CircleAvatar" with radius greater than 27 and "ListTile" in a row as shown below:
Row(
children: [
CircleAvatar(
radius: 32,
backgroundImage: AssetImage('images/sophia_hs.jpg'),
),
Flexible(
child: ListTile(
title: Text(
"Sophia Daniels",
style: TextStyle(
fontFamily: 'Roboto',
color: Colors.black,
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
subtitle: Text(
"Casting Director",
style: TextStyle(
fontFamily: 'Roboto',
color: Colors.black,
fontSize: 16,
fontWeight: FontWeight.normal,
),
),
),
),
],
),
ListTile should be enclosed in a Flexible to avoid "BoxConstraints forces an infinite width" error.