Align text vertically flutter - flutter

I think the best way to explain my issue is with images, so this is what I want to achieve, dont mind the styling of either image.
But when I try to implement it myself, the bottom text gets indented.
Here are my code. Note I am new to flutter, so tips are also appreciated.
SizedBox(
width: 580,
height: 95,
child: Material(
color: panelBackground,
borderRadius: BorderRadius.circular(5),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 25),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
children: [
const Text(
"Project Name",
style: TextStyle(
fontSize: 36,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 5),
RichText(
text: const TextSpan(
text: "Made by: ",
style: TextStyle(
fontSize: 14,
color: Color(0xFF838383),
),
children: [
TextSpan(
text: '/',
style: TextStyle(
color: Colors.amber,
fontWeight: FontWeight.bold)),
TextSpan(
text: '6u5t4v',
style: TextStyle(
color: Colors.amberAccent,
letterSpacing: 2,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.italic))
])),
],
),
Column(
children: [Text("rating here")],
),
const SidebarIcon(
icon: Icon(Icons.save),
)
],
),
),
),
),

Just set crossAxisAlignment to start
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
"Project Name",
style: TextStyle(
fontSize: 36,
color: Colors.white,
fontWeight: FontWeight.w600,
),
),

you have to warp Text with Align Widget and given following code
Align(alignment:Alignment.topLeft, child:"your Widget")

Related

Flutter - Align Items inside a Row - Multiple tiles

I have the following List.
I would like the scale Icons (on the right) to be aligned.
The top should be in the same spot as the one underneath.
#override
Widget build(BuildContext context) {
return Padding(
padding:
const EdgeInsets.only(left: 0.0, right: 0.0, top: 8.0, bottom: 8.0),
child: Slidable(
endActionPane: ActionPane(motion: StretchMotion(), children: [
//delete option
SlidableAction(
onPressed: deleteTapped,
backgroundColor: Colors.red.shade400,
icon: Icons.delete,
borderRadius: BorderRadius.circular(8),
)
]),
child: Container(
padding: const EdgeInsets.all(16.0),
decoration: BoxDecoration(
color: Color(0xFFD9F0FF),
borderRadius: BorderRadius.circular(8),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
const Icon(
Icons.date_range_outlined,
color: Color(0xFF006B8F),
),
const SizedBox(width: 8),
Text(date,
style: const TextStyle(
fontWeight: FontWeight.w400,
fontSize: 18,
color: Color(0xFF006B8F))),
const Spacer(),
const Text(
"|",
style: TextStyle(
fontSize: 18,
color: Color(0xFF006B8F),
fontWeight: FontWeight.bold),
),
const Spacer(),
const Icon(
Icons.monitor_weight_outlined,
color: Color(0xFF006B8F),
),
const SizedBox(width: 8),
Text(weight + " kg",
style: const TextStyle(
fontWeight: FontWeight.w400,
fontSize: 18,
color: Color(0xFF006B8F))),
],
),
),
),
);
}
}
I have tried several things, like putting the Icon and the text in a container but with no luck.
Any help appreciate it!
While you are already using Spacer on both Size, you can use
textAlign: TextAlign.center,
const Text(
"|",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 18,
color: Color(0xFF006B8F),
fontWeight: FontWeight.bold),
),
Without spacer, it can be
Expanded(
child: const Text(
"|",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 18,
color: Color(0xFF006B8F),
fontWeight: FontWeight.bold),
),
),
try this:
Column(
children: [
IntrinsicHeight(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Row(
children: [
//left part
],
),
VerticalDivider(),
Row(
children: [
//right part
],
)
],
),
),
....
],
)

Flutter: How to add spaceEvenly to richText widget?

My question is about flutter and dart language
I have this design:
And, I want to achieve this:
As you can see the icons and text it is separated
This is my code:
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
RichText(
text: TextSpan(
style: GoogleFonts.questrial(),
children: [
WidgetSpan(
child: Icon(FontAwesomeIcons.checkDouble,
size: 40,
color: Color(0xffD7D7D7)),
),
TextSpan(
text: "Timer",
style: GoogleFonts.questrial(
textStyle: TextStyle(
fontSize: 20,
fontWeight: FontWeight.normal,
color:Color(0xff3B3B3B),
),
)
),
WidgetSpan(
child: Icon(FontAwesomeIcons.squareXmark,
size: 40,
color: Color(
0xffD7D7D7)),
),
],
),
),
],
),
How to add some space between icons and text?
Thank you in advance.
Instead of RichText please use Row like
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Icon(FontAwesomeIcons.checkDouble,size: 40, color: Color(0xffD7D7D7)),
Text("Timer", textStyle: TextStyle(
fontSize: 20,
fontWeight: FontWeight.normal,
color:Color(0xff3B3B3B),
),
),
Icon(FontAwesomeIcons.squareXmark, size: 40, color: Color(0xffD7D7D7)),
],
),

Reduce space between specific children in column widget

What is this space in between and how do I remove/reduce it?
Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
SvgPicture.asset(
'assets/weather/cloudy-night.svg',
width: 300,
),
Text(
'Temperature',
style: GoogleFonts.inter(
fontSize: 75,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
Text(
'Datetime',
style: GoogleFonts.inter(
fontSize: 30,
color: Colors.white,
),
),
],
),
)
Add height to text
Text(
'Temperature',
style: GoogleFonts.inter(
fontSize: 75,
fontWeight: FontWeight.bold,
color: Colors.white,
height: 1,
),
),

How do I handle this Text widget in Flutter?

I have a function that returns an AlertDialog. Here's a screenshot of what it looks like: https://i.stack.imgur.com/ZPVFI.jpg. And here's the code for it:
void _showDialog(BuildContext context, List details) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
titlePadding: const EdgeInsets.all(5),
contentPadding: const EdgeInsets.only(left: 10, right: 10),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(10))
),
title: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
details[3].toString(),
style: test.GoogleFonts.quicksand(color: Colors.black, fontSize: 40)
),
]
),
content: Container(
color: Colors.green,
width: double.infinity,
height: 150,
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Text(
'Data: ',
style: test.GoogleFonts.quicksand(color: Colors.black, fontSize: 20, fontWeight: FontWeight.bold)
),
Text(
details[0],
style: test.GoogleFonts.quicksand(color: Colors.black, fontSize: 20)
),
],
),
Row(
children: <Widget>[
Text(
'Tipologia: ',
style: test.GoogleFonts.quicksand(color: Colors.black, fontSize: 20, fontWeight: FontWeight.bold)
),
Text(
details[2].toLowerCase(),
style: test.GoogleFonts.quicksand(color: Colors.black, fontSize: 20)
),
],
),
details[5] != ''
? Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Text(
'Descrizione: ',
style: test.GoogleFonts.quicksand(color: Colors.black, fontSize: 20, fontWeight: FontWeight.bold)
),
],
),
Container(
//width: 100,
child: Text(
details[5],
style: test.GoogleFonts.quicksand(color: Colors.black, fontSize: 20),
overflow: TextOverflow.ellipsis,
maxLines: 5,
textAlign: TextAlign.justify,
),
)
],
)
: Offstage(
child: Text('invisible')
),
Row(
children: <Widget>[
details[4] == 'SI'
? Text(
'Il voto fa media.',
style: test.GoogleFonts.quicksand(color: Colors.black, fontSize: 20, fontWeight: FontWeight.bold)
)
: Text(
'Il voto non fa media.',
style: test.GoogleFonts.quicksand(color: Colors.black, fontSize: 20, fontWeight: FontWeight.bold)
)
],
),
],
),
),
actions: <Widget>[
FlatButton(
child: Text(
"Chiudi",
style: test.GoogleFonts.quicksand(color: Colors.black, fontSize: 15)
),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
The rows containing "Data" and "Tipologia" are no issue. But after "Descrizione" there's a Text widget that contains a string of variable length. I'd like said text to be displayed on multiple lines, starting right after "Descrizione: " (just like "pratico" starts right after "Tipologia: "). How do I do it?
Edit: here's how it looks like now https://i.stack.imgur.com/fKajB.jpg
I'd suggest you go with RichText() instead of Row() with Texts
Just Like What follows
RichText(
textAlign: TextAlign.left,
text: TextSpan(
children: [
TextSpan(children: [
TextSpan(
text: 'Descrizione: ',
style: test.GoogleFonts.quicksand(color: Colors.black, fontSize: 20, fontWeight: FontWeight.bold),),
TextSpan(
text: details[5],
style: test.GoogleFonts.quicksand(color: Colors.black, fontSize: 20),
),
]),
],
),
so your code should look like
void _showDialog(BuildContext context, List details) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
titlePadding: const EdgeInsets.all(5),
contentPadding: const EdgeInsets.only(left: 10, right: 10),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(10))
),
title: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
details[3].toString(),
style: test.GoogleFonts.quicksand(color: Colors.black, fontSize: 40)
),
]
),
content: Container(
color: Colors.green,
width: double.infinity,
height: 150,
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Text(
'Data: ',
style: test.GoogleFonts.quicksand(color: Colors.black, fontSize: 20, fontWeight: FontWeight.bold)
),
Text(
details[0],
style: test.GoogleFonts.quicksand(color: Colors.black, fontSize: 20)
),
],
),
Row(
children: <Widget>[
Text(
'Tipologia: ',
style: test.GoogleFonts.quicksand(color: Colors.black, fontSize: 20, fontWeight: FontWeight.bold)
),
Text(
details[2].toLowerCase(),
style: test.GoogleFonts.quicksand(color: Colors.black, fontSize: 20)
),
],
),
details[5] != ''
? Column(
children: <Widget>[
RichText(
textAlign: TextAlign.left,
text: TextSpan(
children: [
TextSpan(children: [
TextSpan(
text: 'Descrizione: ',
style: test.GoogleFonts.quicksand(color: Colors.black, fontSize: 20, fontWeight: FontWeight.bold),),
TextSpan(
text: details[5],
style: test.GoogleFonts.quicksand(color: Colors.black, fontSize: 20),
),
]),
],
)
: Offstage(
child: Text('invisible')
),
Row(
children: <Widget>[
details[4] == 'SI'
? Text(
'Il voto fa media.',
style: test.GoogleFonts.quicksand(color: Colors.black, fontSize: 20, fontWeight: FontWeight.bold)
)
: Text(
'Il voto non fa media.',
style: test.GoogleFonts.quicksand(color: Colors.black, fontSize: 20, fontWeight: FontWeight.bold)
)
],
),
],
),
),
actions: <Widget>[
FlatButton(
child: Text(
"Chiudi",
style: test.GoogleFonts.quicksand(color: Colors.black, fontSize: 15)
),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
All you have to do is make a couple simple changes to your code
details[5] != ''
? Container(
width: double.infinity,
child: Row(
crossAxisAlignment: CrossAxisAlignment
.start, // This will change how the multi-line text is aligned
children: <Widget>[
Text(
'Descrizione: ',
style: test.GoogleFonts.quicksand(
color: Colors.black,
fontSize: 20,
fontWeight: FontWeight.bold),
),
Flexible(
child: Text(
details[5],
style: test.GoogleFonts.quicksand(
color: Colors.black, fontSize: 20),
overflow: TextOverflow.ellipsis,
maxLines: 5,
textAlign: TextAlign.justify,
),
),
],
),
)
: Offstage(child: Text('invisible')),
Let me know if you need anything else

How to align text widget in rows in google flutter?

I'm trying to align several a text which is in rows (a number, a small padding, followed by said text) in a column and don't know how to achieve it.
I already tried out every MainAxisAlignment setting in the rows property.
This screenshot should clarify my issue: The left part is the mockup and how it's supposed to look like, right-hand side is the current state in flutter.
I want the text to be aligned at the green line that I added to visualize my problem (so the first text needs to start a bit more to the right).
My code:
Widget singleStep(BuildContext context, int numToPrint, String text,
{String fineprint = ""}) {
return Padding(
padding: EdgeInsets.only(
bottom: 0.023 * getScreenHeight(context),
left: 0.037 * getScreenWidth(context)),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
RichText(
text: TextSpan(children: <TextSpan>[
TextSpan(
text: "#",
style: GoZeroTextStyles.regular(_NUMBERFONTSIZE,
color: GoZeroColors.green)),
TextSpan(
text: numToPrint.toString(),
style: GoZeroTextStyles.regular(_NUMBERFONTSIZE))
])),
Padding(
padding: EdgeInsets.only(left: 0.017 * getScreenWidth(context)),
child: RichText(
text: TextSpan(
style: GoZeroTextStyles.regular(_TEXTSIZE),
children: <TextSpan>[
TextSpan(text: text + "\n"),
TextSpan(
text: fineprint,
style: GoZeroTextStyles.regular(_FINEPRINTSIZE))
])))
],
));
}
All steps are wrapped in a column, which is a child of a Stack.
Advice is gladly appreciated. Also if you got any other advice to improve the code, feel free to leave a comment :)
Thank you in advance!
Cheers,
David
I hope I understand you well. There are some advices for your problem to solve it:
Consider to add SizedBox(width:20.0) before RichText widgets to achieve the align in mockup.
Looks like you want to make all Text widgets centered. Consider to add center widget so they align themselves at the center of column or row.
#override
Widget build(BuildContext context) {
return Container(
color: Colors.white,
padding: EdgeInsets.all(10),
child: Column(children: [
Expanded(
flex: 4,
child: Container(
alignment:Alignment.center,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(color: Colors.grey, width: 1.0)),
child:Text('I\'m in Circle',textAlign: TextAlign.center,
style: TextStyle(
fontSize: 19,
fontWeight: FontWeight.bold,
color: Colors.black)))),
SizedBox(height: 15),
Text('Title',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 19,
fontWeight: FontWeight.bold,
color: Colors.black)),
SizedBox(height: 10),
Expanded(
flex: 3,
//Use listview instead of column if there are more items....
child: Column(
mainAxisAlignment:MainAxisAlignment.spaceEvenly,
children: [
Row(children: [
Padding(
padding:
const EdgeInsets.symmetric(vertical: 8, horizontal: 15),
child: Text('#1',
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.bold,
color: Colors.green)),
),
Text('Your text goes here.......\nSecond line',
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.bold,
color: Colors.black)),
]),
Row(children: [
Padding(
padding:
const EdgeInsets.symmetric(vertical: 8, horizontal: 15),
child: Text('#2',
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.bold,
color: Colors.green)),
),
Text('Your text goes here.......\nSecond line',
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.bold,
color: Colors.black)),
]),
Row(
children: [
Padding(
padding:
const EdgeInsets.symmetric(vertical: 8, horizontal: 15),
child: Text('#3',
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.bold,
color: Colors.green)),
),
Text('Your text goes here.......\nSecond line',
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.bold,
color: Colors.black)),
])
]))
]));
}
My suggestion would be to return Container instead of Padding from the Widget singleStep and use the property padding of the container to set the padding.
Screenshot
Below is a very basic code snippet using Container using which I could add padding to the left of texts:
void main() {
runApp(
MaterialApp(
home: SafeArea(
child: Scaffold(
backgroundColor: Colors.white,
body: Container(
margin: EdgeInsets.only(top: 20.0),
padding: EdgeInsets.only(
left: 20.0,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Text(
"Hello World",
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.green,
fontSize: 20.0,
),
),
Text(
"Hello World",
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.green,
fontSize: 20.0,
),
),
Text(
"Hello World",
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.green,
fontSize: 20.0,
),
),
],
),
),
),
),
),
);
}
Hope this is helpful.