How to align specific elements to the left inside a Column Widget - flutter

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

Related

Text is shifted vertically in Flutter

I have the following code:
AutoSizeText.rich(
TextSpan(children: [
const TextSpan(
text: "\$",
style: TextStyle(
color: Colors.white,
fontSize: 45,
height: 1.0,
letterSpacing: .0,
fontWeight: FontWeight.w600,
),
),
TextSpan(
text: widget.budget.truncate().toString(),
style: const TextStyle(
color: Colors.white,
fontSize: 90,
),
),
TextSpan(
text: ".${widget.budget.toStringAsFixed(2).split(".")[1]}",
style: const TextStyle(
color: Colors.white,
fontSize: 45,
),
),
]),
style: GoogleFonts.manrope(
fontSize: 45,
letterSpacing: -4.5,
height: 1.0,
fontWeight: FontWeight.w600,
textStyle: const TextStyle(
leadingDistribution: TextLeadingDistribution.even,
)),
textAlign: TextAlign.center,
maxLines: 1,
);
The code results in this (I also tried with Text.rich instead of AutoSizeText but the result is the same):
In the image, I have wrapped the text in a red container to check its bounding box.
I am implementing this element following a design I made in Figma:
Similatly, in this image the red frame has an autolayout applied with all padding set to 0, in a way that simulates wrapping the text in a Container.
The text looks the same in both the design and the Flutter implementation, but the Flutter one is shifted upwards, which on big text sizes is really noticeable. I figured it might have something to do with the vertical alignment of the text but I could not find any way to fix it.
Is this an expected behaviour or am I doing something wrong?

Top align text vertically for training and main text in a ListTile

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
);

How to make showcase widget appear on top of text. I implemented it but its appearing beneath the text

I am implementing a showcase widget but I want to place the widget on top of the text. How can I achieve this?
This is the code:
Showcase(
key: keys,
overlayOpacity: 0,
overlayColor: Colors.transparent,
title: "New!",
titleTextStyle: TextStyle(fontSize: 12),
shapeBorder: const CircleBorder(),
showcaseBackgroundColor: Color(0xfffcecaf),
descTextStyle:
const TextStyle(fontWeight: FontWeight.bold, fontSize: 13),
description: "Tap to Learn more",
child: Container(
child: Text(
"xyz",
style: TextStyle(
fontSize: 20,
height: 1.2,
color: AppColors.PRIMARY_COLOR,
),
),
),
),

how to make row text going center

Hello i want to ask how to make the text going center.
i have row that contain 2 text.
below is my code.
Container(
child: Padding(
padding: const EdgeInsets.only(bottom: 60.0),
child: Center(
child: Row(
children: [
Text(
"Great",
style: TextStyle(
color: Colors.white,
fontSize: 44.0,
fontWeight: FontWeight.w700,
fontFamily: "Berlin"),
),
Text(
"Ocean",
style: TextStyle(
color: Colors.blue,
fontSize: 44.0,
fontWeight: FontWeight.w700,
fontFamily: "Berlin"),
),
],
),
),
),
),
and output from that code is going like this.
how to make that row going center?
There are a couple of ways to achieve this but first, I would like to refactor your code. You are using Padding inside a Container widget, which is totally unnecessary as Container widget already has a property called padding. So, you should remove the Padding widget.
Also, you have used Center widget inside Container which is also unnecessary as Container has alignment property which you can use to center align child widgets (Alignment.center).
Lastly, in order to center align children widgets in a Row widget, there is mainAxisAlignment & crossAxisAlignment properties which you can use to align widgets.
Setting mainAxisAlignment to MainAxisAlignment.center will center all of your children widgets.
Also, you have used two different Text widgets to create different styled Text widgets, which you can do with a single RichText widget.
Your final code should look like this:
return Container(
padding: const EdgeInsets.only(bottom: 60.0),
alignment: Alignment.center,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
RichText(
text: TextSpan(
style: TextStyle(
color: Colors.white,
fontSize: 44.0,
fontWeight: FontWeight.w700,
fontFamily: "Berlin"),
text: "Great",
children: <TextSpan>[
TextSpan(
text: 'Ocean',
style: TextStyle(
color: Colors.blue,
fontSize: 44.0,
fontWeight: FontWeight.w700,
fontFamily: "Berlin"),
),
],
),
),
],
),
);

How to make a multi line text in Flutter

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,
),
),
)