Center Text in a Flutter Column - flutter

I am looking for help in centering the "mytitle" text in a column.
I tried centerTitle: true, between 'mytitle' and 'overflow', but it did not work:
Card(
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
child:
Text(
mytitle,
overflow: TextOverflow.ellipsis,
style: CustomTheme.bodyText1.override(
fontFamily: 'Noto Sans',
fontSize: 24,
color: txtcolor),
)
)
]
)
)
)

try to use crossAxisAlignment as follow:
Container(
alignment: Alignment.center,
Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
child:
Text(
mytitle,
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
style: CustomTheme.bodyText1.override(
fontFamily: 'Noto Sans',
fontSize: 24,
color: txtcolor),
)
)
]
)
)
for more information see this. In summary, you can set the layout of Column in two directions. The first one is the vertical axis (MainAxis) and the second one is the horizontal (crossAxis) direction. Row has the same feature but its mainAixs and crossAxis is opposite.

Related

How to align text in flutter

I am trying to align the name to the left side but it is not working. Always displays in the center suppose I use text-align. So, How to resolve this issue?
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Name",
maxLines: 1,
overflow: TextOverflow.ellipsis,
softWrap: false,
textAlign: TextAlign.left,
style: const TextStyle(fontSize: 16,color: Colors.black,fontWeight: FontWeight.bold,),
),
const SizedBox( width: 160,
child:Text(
"mynameee#gmail.com",
maxLines: 3,
overflow: TextOverflow.ellipsis,
softWrap: true,
style: const TextStyle(
fontSize: 12,
color: Colors.black,
),
),),
],
),
In column widget add this line :
crossAxisAlignment: CrossAxisAlignment.start
and remove :
mainAxisAlignment: MainAxisAlignment.center,
Add this to column:
crossAxisAlignment: CrossAxisAlignment.start,
Warp your column with Container and then inside the container enter below line:
alignment:Alignment.center
add Container for the text and give it alignment
Like this:
Container(
alignment: Alignment.centerLeft,
child:Text('text here')
)
And you want display the name and email together use Row
Like this:
Row(
mainAxisAlignment: MainAxisAlignment.start,
children:[
Text("name:"),
Text("Example#gmail.com"),
]
)
And the output well be like this:
Name: Example#gmail.com
Container(
alignment: Alignment.centerLeft,
child:Text('text here',textalign:center)
)

I want to align the starting place of two texts

I have one "row" and two "text" widgets inside. I want to align the starting place of two texts. ie "m. name" and "m105" should line up.
Container(
child: Row(
children: [
Container(
child: Align(
alignment: Alignment.topLeft,
child: Text(
"M. Adı: ",
style: TextStyle(fontWeight: FontWeight.bold),
),
),
),
// SizedBox(
// width: 20,
// ),
Expanded(
child: Text(
"$productName",
overflow: TextOverflow.ellipsis,
maxLines: 3,
softWrap: true,
),
),
],
),
),
Try
Row() widget attribute
crossAxisAlignment: CrossAxisAlignment.start
Text() widget attribute
textAlign: TextAlign.start,
/// Try something like that
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
"M. Adı: ",
style: TextStyle(fontWeight: FontWeight.bold),
),
),
SizedBox(width: 5),
Flexible(
child: Text(
"$productName",
textAlign: TextAlign.start,
),
),
],
),
Add crossAxisAlignment: CrossAxisAlignment.center, to your Row widget it should be aligned as you desired or still if it doesnt works just try changing center with other values check which one works for you...
and even after adding above property to your Row widget then you would have to remove alignment of topleft in your text of m.name

Flutter: Text overflow for a Text inside a Column not working

Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(showing.title, style: browseTitle, overflow: TextOverflow.ellipsis,),
Text(showing.dates, style: browseInfo),
SizedBox(
height: 20,
),
Text('Posted by: ' + showing.email, style: browseInfo),
],
),
This code produces this:
But the problem is that the textoverflow I put inside the text doesn't seem to be applying and the text keeps overflowing. How do I solve this so that the text doesn't overflow and it turns into an ellipsis?
CheckOut this work perfect
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: MediaQuery.of(context).size.width,
child: Text(
showing.title,
style: browseTitle,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
Text(showing.dates, style: browseInfo),
SizedBox(height: 20),
Text('Posted by: ' + showing.email, style: browseInfo),
],
),

Center certain elements vertically in a Row widget

I have the following Widget tree of a ListView item:
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Align(
child: Assets.images.select.image(height: 20, width: 20),
),
),
Expanded(
flex: 4,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(right: 16),
child: Text(
food.name,
style: GoogleFonts.cabin(
color: Theme.of(context).primaryColor,
fontSize: FontSize.medium.size,
fontWeight: FontWeight.w700),
),
),
Container(
margin: EdgeInsets.only(top: 4),
child: Text(
"100 g",
style: GoogleFonts.cabin(
color: Color(0xFF777777),
fontSize: FontSize.small.size,
fontWeight: FontWeight.w500),
),
),
],
),
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Align(
alignment: Alignment.centerRight,
child: Text(
"${food.carbohydratesPerGram} g / HC",
style: GoogleFonts.cabin(
color: Theme.of(context).primaryColor,
fontSize: FontSize.medium.size,
fontWeight: FontWeight.w400),
),
),
],
),
)
],
)
But it turns out like this:
I tried putting the ball in a column with "mainAxisAlignment" set to "mainAxisAlignment.center"
How can I get the ball on the left vertically centered in the row?
You can use crossAxisAlignment.
When you are in a row element the main is horizontal axis and the cross is vertical axis
When you are ina column the main is verticla axis and the cross is horizontal axis.
So in your Row element to center element in vertical axis you need to use
crossAxisAlignment: CrossAxisAlignment.center
Managed to get it somewhat working: instead of using an image widget, I used an IconButton widget and it magically worked
Add alignment: Alignment.center to you Assets.images.
Expanded(
child: Align(
alignment: Alignment.center, // This Here
child: Assets.images.select.image(height: 20, width: 20),
),
),
And I think your row is taking the height of your whole screen. If that is the case your image will come to the center of the screen coz your row is on the whole screen make sure that is not the case.

How to align text with 2 lines with a text of one line in flutter

So, I want the row with a string of 2 lines ("Some long string with 2 lines heres") to be properly aligned with the string of 1 line: ("Name:"), but I want to do this WITHOUT checking the string length.
This is my code for the row:
Row(
children: <Widget>[
Text(
title,
style: Theme.of(context).textTheme.headline6.copyWith(height: 1.24),
),
Spacer(),
Container(
width: 242.0,
alignment: Alignment.bottomRight,
child: Text(
text,
textAlign: TextAlign.end,
maxLines: 2,
style: Theme.of(context).textTheme.bodyText1.apply(
color: kGrey,
),
),
),
],
);
As for the result I want, here's an image example:
Use crossAxisAlignment Row parameter to align the text to start crossAxisAlignment: CrossAxisAlignment.start
Solution-
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
title,
style: Theme.of(context)
.textTheme
.headline6
.copyWith(height: 1.24),
),
Spacer(),
Container(
width: 242.0,
alignment: Alignment.bottomRight,
child: Text(
text,
textAlign: TextAlign.end,
maxLines: 2,
style: Theme.of(context).textTheme.bodyText1.apply(
color: kGrey,
),
),
),
],
),
Hope this will help you If you have any doubts ask in comment.