How can I have a text as a place holder until onTap() happen? (onTap is on another page)
Align(
alignment: Alignment.center,
child: Text(//Default value goes here
widget.categoryTitle,//this string comes from another page it changes on every onTap()
style: TextStyle(
color: Colors.black,
fontSize: 17.0,
fontWeight: FontWeight.bold,
),
),
),
Right now if no onTap happens the Text is holding a white blank space, How to replace it with a default/initial value?
Or you can also use shorter version for conditional expressions
Align(
alignment: Alignment.center,
child: Text(
widget.categoryTitle ?? "Your Default Text Here",
style: TextStyle(
color: Colors.black,
fontSize: 17.0,
fontWeight: FontWeight.bold,
),
),
),
expr1 ?? expr2,
If expr1 (widget.categoryTitle) is non-null, returns its value; otherwise, evaluates and returns the value of expr2 ("Your Default Text Here")
Add Ternary operator and assign values as per text
Align(
alignment: Alignment.center,
child: Text(//Default value goes here
widget.categoryTitle.isEmpty? "Default Text": widget.categoryTitle,
style: TextStyle(
color: Colors.black,
fontSize: 17.0,
fontWeight: FontWeight.bold,
),
),
),
Related
For this ListTile the text is center aligned vertially. I would like to top align the text. What would be the best way to handle that? is it possible with a ListTile?
child: ListTile(
onTap: () {
NavigationService.instance.navigateToReplacement(Transactions.route);
},
trailing: Text(NumberFormat.simpleCurrency().format(item.balance),
style: const TextStyle(
fontSize: GlobalUI.listHeaderFontSize,
fontWeight: FontWeight.normal,
),
),
title: Text(item.name,
style: const TextStyle(
fontSize: GlobalUI.listHeaderFontSize,
fontWeight: FontWeight.normal,
),),
),
you can wrap your Text widget around an Align widget
Align(
alignment: Alignment.topCenter,
child: ...//your text widget
);
The first word is underlined but if you look closely, the text overlaps a part of the colored shape/part. It is not just under the text.
Here is what I am trying to achieve:
Here's my current code:
text: TextSpan(children: <TextSpan>[
TextSpan(
text: "Welcome",
style: TextStyle(
color: HSColors.darkBlue,
decoration: TextDecoration.underline,
decorationColor: HSColors.cream,
decorationThickness: 5.h,
fontSize: 30.sp,
fontWeight: FontWeight.w700,
height: 1.1,
letterSpacing: -0.03),
),
TextSpan(
text: " to Veritas Monitoring Services",
style: TextStyle(
color: HSColors.darkBlue,
fontSize: 30.sp,
fontWeight: FontWeight.w700,
height: 1.1,
letterSpacing: -0.03),
)
]),
),
Here is what it currently looks like:
Moreover, if I use other text, it overlaps and looks like this:
You need to work with decorationThickness value.
decorationThickness: 5.h,
I have lower the decorationThickness value to
decorationThickness: 0.2.h,
Here's the result on iPhone 12 simulator
You can acheive this using Stack as shown below. Set the behind container's height and width as per your need. Thanks
Stack(
alignment: Alignment.bottomLeft,
children: [
Container(
height: 15,
width: 130,
color: Colors.amber,
),
Text("Welcome",
style: TextStyle(
color: Colors.black,
fontSize: 30,
fontWeight: FontWeight.w700,
height: 1.1,
letterSpacing: -0.03),
),
],
),
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:
In the following code I'd like to align the name 'Jonny Bas' and '#coder' to leftmost
body: Column(
children: [
Center(
child:Text(
'Information',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
),
SizedBox(height: 100),
Text(
'Praveen Kumar',
style: TextStyle(
fontSize: 30,
fontWeight: FontWeight.bold,
color:Colors.black,
),
),
Text(
'Coding star- 4',
style: TextStyle(
fontSize: 30,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
],
),
backgroundColor: Colors.grey,
);
}
You can use 'Align' widget or 'positioned' widget if you want to make change in only one or two widget but if want to give all of widgets the same alignment of parent widget column then you can use MainAxisAlignment and CrossAxisAlignment with specified attributes of left/right/etc...
Check the documentation links below for more info on how to use them,
https://api.flutter.dev/flutter/widgets/Align-class.html
https://api.flutter.dev/flutter/widgets/Positioned-class.html
Sometimes, the text widget does a line break, and sometimes don't. I tried to add overflow and maxline but it doesn't work.
This is the code:
Text(
ArticleData().articleBank[index].articleTitle,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20.0,
color: Colors.black,
),
),
This is what, I will try to build:
You can use FittedBox class.
Scales and positions its child within itself according to fit. The fit and alignment arguments must not be null.
FittedBox(
Key key,
fit: BoxFit.none,
alignment: Alignment.center,
child: Text(
ArticleData().articleBank[index].articleTitle,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20.0,
color: Colors.black,
),
),
)