Align children to top of row in Flutter? - flutter

after I write my posts in my application, my photo and date center the text. I need to pin the photo and date to the beginning. What should I do for this?
............................................................................................................................................................................................
child: Row( children: [
Padding(
padding: EdgeInsets.only(top: 15),
child: CircleAvatar(
radius: 20,
backgroundImage: NetworkImage(
userData['photoUrl'],
),
),
),
Expanded(
child: Padding(
padding:
EdgeInsets.only(left: 8, top: 20),
child: Container(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
userData['username'],
style: TextStyle(
fontWeight:
FontWeight.bold),
),
Container(
width: double.infinity,
padding: const EdgeInsets.only(
top: 8,
),
child: RichText(
text: TextSpan(
style: const TextStyle(
color: primaryColor),
children: [
TextSpan(
text:
' ${(snap.data()! as dynamic)['description']}',
),
],
),
),
),
],
),
),
),
),
Container(
padding:
EdgeInsets.symmetric(vertical: 4),
child: Text(
DateFormat.yMd().format(
(snap.data()!
as dynamic)['datePublished']
.toDate(),
),
style: const TextStyle(
fontSize: 15,
color: secondaryColor,
),
),
),

child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [

In your Row, set crossAxisAlignment: CrossAxisAlignment.start. This will cause the Row's children to be aligned at the top of the row.

Related

How to place image & textfiled both at center in flutter

How to place image & textfield both at center in flutter.
Below is code what i have tried so far any help is appreciated!
Container(
child: Padding(
padding: const EdgeInsets.only(top: 32.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
child: Image.asset(
'images/Warning.png',
),
),
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Container(
alignment: Alignment.center,
child: Text(
'OTP is valid for 5 minutes only.',
style: TextStyle(
color: Color(0xFF4B4B4B),
fontSize: 12,
fontFamily: 'Soleil_Regular',
),
),
),
),
],
),
),
),
trying as some thing shown in the picture both text & image is in same line any help is appreciated!
Simple way of doing it by using RichText
RichText(
textAlign: TextAlign.center,
text: TextSpan(children: [
WidgetSpan(child: Icon(Icons.ac_unit)), // use image in your case instead of icon
TextSpan(text: "This is Text")
]))
Full Snippet
Container(
child: Padding(
padding: const EdgeInsets.only(top: 32.0),
child: Text.rich(TextSpan(
style: TextStyle(
color: Color(0xFF4B4B4B),
fontSize: 12,
fontFamily: 'Soleil_Regular'),
children: [
WidgetSpan(
child: Image.asset(
'images/Warning.png',
alignment: Alignment.center,
),
),
WidgetSpan(
child: SizedBox(
width: 10,
)),
TextSpan(
text: 'OTP is valid for 5 minutes only.',
),
],
)),
),
),
Give your image a size and you will get your result
Container(
child: Padding(
padding: const EdgeInsets.only(top: 32.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
child: Image.network(
'http://orbitsystemsinc.com/images/banner-round-bg.png',width: 40,height: 40,
),
),
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Container(
alignment: Alignment.center,
child: Text(
'OTP is valid for 5 minutes only.',
style: TextStyle(
color: Color(0xFF4B4B4B),
fontSize: 12,
fontFamily: 'Soleil_Regular',
),
),
),
),
],
),
),
)

flutter: how to align time on the bottom right side of chat message

Here is my chat screen screenshot. I want to align time under chat message not from the start but on the bottom right side of the chat tile.
How can I do that in my code?
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
child: Padding(
padding: const EdgeInsets.only(top: 2.0),
child: Image.network(senderPhoto,
))),
SizedBox(width: 20),
Text(peerName),
],
),
Container(
margin: EdgeInsets.only(right: 130),
padding: EdgeInsets.only(
top: 10, bottom: 10, left: 10, right: 10),
),
child: Text(message,
textAlign: TextAlign.start,
style: TextStyle(
color: Colors.white,
fontSize: 16,
)),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Padding(
padding: const EdgeInsets.only(top: 1.0),
child: Text(
timeSent.toDate(),
style: TextStyle(fontSize: 10, color: Colors.white),
),
),
],
),
],
))
Wrap your timeSent.toDate padding widget into a row, and give that a mainaxisAlignment of end, like this:
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Padding(
padding: const EdgeInsets.only(top: 1.0),
child: Text(
timeSent.toDate(),
style: TextStyle(fontSize: 10, color: Colors.white),
),
),
],
),
This will solve your problem.
Wrap the Text field in the Row and give the mainAxixAlignment to end. That will solve the problem.
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
child: Padding(
padding: const EdgeInsets.only(top: 2.0),
child: Image.network(senderPhoto,
))),
SizedBox(width: 20),
Text(peerName),
],
),
Container(
margin: EdgeInsets.only(right: 130),
padding: EdgeInsets.only(
top: 10, bottom: 10, left: 10, right: 10),
),
child: Text(message,
textAlign: TextAlign.start,
style: TextStyle(
color: Colors.white,
fontSize: 16,
)),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Padding(
padding: const EdgeInsets.only(top: 1.0),
child: Text(
timeSent.toDate(),
style: TextStyle(fontSize: 10, color: Colors.white),
),
),
],
),
],
));

Flutter - How to fix text overflow in a card?

I'm building an app and I want to show this text but i need put some "limit" to not happen this:
card with overflow
so, I tried a few things (like SizedBox to limit the text, AutoSizeText to change the font size... but i don't know how to limit this and make this responsive), but to no avail.
this is the code of the card:
Card(
child: Container(
height: 120,
child: Padding(
padding: EdgeInsets.only(
left: 15,
right: 15,
top: 10,
bottom: 10,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
ClipOval(
child: Image.network(
pedido.logomarca,
height: 90,
width: 90,
),
),
Padding(
padding: EdgeInsets.only(left: 20),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
SizedBox(
child: AutoSizeText(
pedido.nomefantasia.toUpperCase(),
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
),
Row(
children: <Widget>[
ClipOval(
child: Container(
height: 10,
width: 10,
color: Colors.green,
),
),
Padding(
padding: EdgeInsets.only(
left: 8,
),
child: Text(
pedido.statuspedidodescricao,
),
),
),
],
),
],
),
),
Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
DateFormat('dd/MM/yyyy').format(pedido.datavenda),
style: TextStyle(
color: Colors.blueGrey,
fontSize: 14,
),
),
Padding(
padding: EdgeInsets.only(top: 10),
child: Text(
'R\$ ${pedido.valortotal.toStringAsFixed(2).replaceAll('.', ',')}',
style: TextStyle(
color: Colors.green[600],
fontSize: 16,
),
),
),
telefone
? OutlineButton(
onPressed: () {},
splashColor: Colors.green,
highlightColor: Colors.green,
highlightedBorderColor: Colors.green,
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: <Widget>[
Text('Ligar'),
Padding(
padding: EdgeInsets.only(left: 3),
child: Icon(
Icons.call,
size: 15,
),
),
],
),
)
: Container(),
],
),
),
],
),
),
),
),
AutoSized text has a parameter you need to set. maxlines: 2
AutoSizeText(
pedido.nomefantasia.toUpperCase(),
maxlines: 2,
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
Documentation
change this:
Padding(
padding: EdgeInsets.only(
left: 8,
),
child: Text(
pedido.statuspedidodescricao,
),
),
to this:
Expanded(
child: Padding(
padding: EdgeInsets.only(
left: 8,
),
child: Text(
pedido.statuspedidodescricao,
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
),
)

Flutter text is not ellipsized in the list

I have a list of object. There is a name that can be long and according to design it should end with three dots if it can't fit
Container(
height: 72,
constraints: BoxConstraints(minWidth: double.infinity),
child: Row(
children: <Widget>[
Container(
margin: const EdgeInsets.only(left: 16.0, right: 16.0),
child: CircleAvatar(
radius: 20.0,
backgroundImage: NetworkImage(_model._organizerLogo),
backgroundColor: Colors.transparent,
),
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: EdgeInsets.only(right: 8.0),
child: Text(
_model._eventName,
style: TextStyle(
fontSize: 15,
color: Colors.black,
fontWeight: FontWeight.w500),
textAlign: TextAlign.start,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
...
])
],
),
)
Wrapping Container in Flexible or Expandable didn't work.
How to make oversized text ellipsis? Thanks!
Add Expanded to your Column to give it a fixed width based on the remaining space.
Container(
height: 72,
constraints: BoxConstraints(minWidth: double.infinity),
child: Row(
children: <Widget>[
Container(
margin: const EdgeInsets.only(left: 16.0, right: 16.0),
child: CircleAvatar(
radius: 20.0,
backgroundImage: NetworkImage(_model._organizerLogo),
backgroundColor: Colors.transparent,
),
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: EdgeInsets.only(right: 8.0),
child: Text(
_model._eventName,
style: TextStyle(
fontSize: 15,
color: Colors.black,
fontWeight: FontWeight.w500),
textAlign: TextAlign.start,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
...
])
),
],
),
)
Here is the working solution:
Container(
height: 72,
constraints: BoxConstraints(minWidth: double.infinity),
child: Row(
children: <Widget>[
Container(
margin: const EdgeInsets.only(left: 16.0, right: 16.0),
child: CircleAvatar(
radius: 20.0,
backgroundImage: NetworkImage(poolImageUrl),
backgroundColor: Colors.transparent,
),
),
Expanded(
child: Container(
padding: EdgeInsets.only(right: 8.0),
child: Text(
"This will not overflow now, because we have put it in Expanded, you can try any long string here for test",
style: TextStyle(fontSize: 15, color: Colors.black, fontWeight: FontWeight.w500),
textAlign: TextAlign.start,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
),
],
),
),

Flutter: How to place a button in the middle of 2 containers?

UI Layout
If the purple area is inside an Expanded widget, how would I go about to position the button? I've implemented that UI by setting a fixed height to the purple container but haven't been able to understand how to achieve the same effect if the height is variable, depending on the content.
I was able to get close by using Stack and Positioned widgets but then the button is not really clickable. If anyone can give me a general idea on how to achieve the desired goal I would be thankful.
Here's my attempt (demo case)
#override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Expanded(
flex: 1,
child: SingleChildScrollView(
child: Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
color: Colors.redAccent,
),
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Stack(
children: <Widget> [
Padding(
padding: const EdgeInsets.only(bottom: 40.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Icon(
Icons.book,
color: Colors.white,
size: 40.0
),
Container(
width: 90.0,
child: new Divider(color: Colors.white),
),
Text(
"Some random text -",
style: TextStyle(color: Colors.white, fontSize: 25.0),
),
Padding(
padding: const EdgeInsets.only(top: 8.0, right: 70.0),
child: Row(
children: <Widget>[
Flexible(
child: Text(
'More random text that can vary a lot!',
style: TextStyle(
color: Colors.white,
fontSize: 16.0,
fontWeight: FontWeight.bold,
),
),
),
],
),
),
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Row(
children: <Widget>[
Text(
'Random text ',
style: TextStyle(
color: Colors.white,
fontSize: 16.0,
fontWeight: FontWeight.bold,
),
),
],
),
),
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Row(
children: <Widget>[
Text(
'Random',
style: TextStyle(
color: Colors.white,
fontSize: 16.0,
fontWeight: FontWeight.bold,
),
),
],
),
),
],
),
),
Positioned(
bottom: 0.0,
left: MediaQuery.of(context).size.width - 100.0,
child: FractionalTranslation(
translation: const Offset(0.0, 0.8),
child: FloatingActionButton(
backgroundColor: Colors.white,
foregroundColor: Colors.redAccent,
child: new Icon(
Icons.map
),
onPressed: () {
},
),
),
),
]
),
),
),
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 8.0, left: 8.0),
child: Row(
children: <Widget>[
Flexible(
child: Text(
"Random text",
style: new TextStyle(
fontFamily: 'Raleway',
fontSize: 16.0,
color: Colors.black38
)
),
),
],
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"Random text - long text",
style: new TextStyle(
fontFamily: 'Raleway',
fontSize: 18.0
)
),
),
],
)
],
)
),
),
],
);
Explaining what I described in the comments:
You can use the FractionalTranslation widget to shift your FAB half way down.
FractionalTranslation(translation: Offset(0, .5), child: FloatingActionButton(...))
This requires you to have it positioned at the bottom of the purple area (referring to your screenshot) beforehand, but I assume that you have that figured out.