IconButton's ripple effect appears under the widget - flutter

I have a Container widget and an IconButton. When I press on the IconButton, ripple effect shows behind the Container. Is there a way to fix this?
Here is the full class as Github Gist.
Container(
height: height,
decoration: _cardBoxDecoration(Colors.white),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
IconButton(
icon: Icon(
FontAwesomeIcons.checkCircle,
color: _checkGrey,
size: 20,
),
onPressed: () {},
),
IconButton(
icon: Icon(
Icons.more_horiz,
color: _grey,
size: 20,
),
onPressed: () {},
)
],
),
]
)
);

You can use the Material widget to get the output you want. Replace the Container Widget with Material Widget.
class _AppointmentsCart extends StatelessWidget {
final double height;
_AppointmentsCart({this.height});
#override
Widget build(BuildContext context) {
return Material( // replace container widget
clipBehavior: Clip.antiAlias,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(20))),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
IconButton(
icon: Icon(
FontAwesomeIcons.checkCircle,
color: _grey,
size: 20,
),
onPressed: () {},
),
IconButton(
icon: Icon(
Icons.more_horiz,
color: Colors.grey,
size: 20,
),
onPressed: () {},
)
],
),
Padding(
padding: EdgeInsets.only(left: 15),
child: Text(
'Today',
style: TextStyle(fontSize: 18),
),
),
Padding(
padding: const EdgeInsets.all(15),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
'5',
style: TextStyle(fontSize: 24, color: _titleGrey),
),
Text(
'Appoinemts',
style: TextStyle(fontSize: 12, color: _subtitleGrey),
)
],
),
)
],
),
);
}
}

Related

How to draw vertical connector lines between icons in Flutter?

I have 3 ListTile widgets as shown below and I want to add vertical connection lines between icons but not sure how to do that. Can anyone help please? Thanks.
[Icon] Order received
| 2020-05-28 10:00 AM
|
|
[Icon] On the way
| 2020-05-29 10:00 AM
|
|
[Icon] Delivered
2020--05-29 11:00 AM
Edit: source code is provided below. As described above I need to draw a line between icons of the ListTile widgets. Tried VerticalDivider but there is still a big gap between ListTile widgets.
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:home_chefs/common_widgets/text_widget.dart';
import 'package:home_chefs/constants/color_palette.dart';
import 'package:home_chefs/constants/font_enum.dart';
import 'package:home_chefs/constants/form_styleguides.dart';
class OrderStatusWidget extends StatefulWidget {
#override
_OrderStatusWidgetState createState() => _OrderStatusWidgetState();
}
class _OrderStatusWidgetState extends State<OrderStatusWidget> {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: ColorPalette.white,
body: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Container(
padding: EdgeInsets.only(top: 30.0, bottom: 30.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
TextWidget(
text: 'Order status',
fontFamily: FontFamily.BalooRegular.toShortString(),
fontSize: FormStyleGuides.textSizeMedium,
),
TextWidget(
text: 'Invoice: 12828',
fontFamily: FontFamily.BalooRegular.toShortString(),
fontSize: FormStyleGuides.textSizeMedium,
),
Container(
height: 100.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(8.0)),
image: DecorationImage(
fit: BoxFit.contain,
image: AssetImage(
'assets/images/trending/pho_ha_noi.jpg',
))))
],
),
),
Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
ListTile(
leading: FaIcon(
FontAwesomeIcons.book,
color: ColorPalette.persimmon,
),
title: Text('Order received'),
subtitle: Text('30/05/2020 10.00 AM'),
//contentPadding: EdgeInsets.only(left: 20.0, bottom: 30.0),
),
ListTile(
leading: FaIcon(
FontAwesomeIcons.truck,
color: ColorPalette.persimmon,
),
title: Text('On the way'),
subtitle: Text('30/05/2020 10.00 AM'),
//contentPadding: EdgeInsets.only(left: 20.0, bottom: 30.0),
),
ListTile(
leading: FaIcon(
FontAwesomeIcons.solidFlag,
color: ColorPalette.persimmon,
),
title: Text('Delivered'),
subtitle: Text('30/05/2020 11.00 AM'),
//contentPadding: EdgeInsets.only(left: 20.0, bottom: 30.0),
),
],
),
),
Container(
width: 100.0,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
FormStyleGuides.buttonBorderRadius),
side: BorderSide(color: ColorPalette.persimmon)),
color: ColorPalette.persimmon,
highlightColor: ColorPalette.persimmon,
onPressed: () {},
padding: EdgeInsets.fromLTRB(
FormStyleGuides.buttonPaddingLeft,
FormStyleGuides.buttonPaddingTop,
FormStyleGuides.buttonPaddingRight,
FormStyleGuides.buttonPaddingBottom),
child: TextWidget(
text: 'Confirm delivery',
color: ColorPalette.white,
fontSize: FormStyleGuides.textFormFieldLabelSize,
),
),
],
),
)
],
),
);
}
}
If I understood your question correctly, you are looking for something like this:
class IconLines62088774 extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
ItemContainer(),
ItemContainer(),
ItemContainer(),
],
);
}
}
class ItemContainer extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
color: Colors.blue,
height: 20,
width: 1,
),
Icon(Icons.message, color: Colors.grey,),
Container(
color: Colors.blue,
height: 20,
width: 1,
),
],
),
Expanded(
child: Padding(
padding: EdgeInsets.all(8),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('On the way'),
Text('01-07-2020'),
],
),
),
),
],
),
);
}
}

Place Widgets at the edge of their parent widget

EDIT: Added a screenshot of the desired output
Goal: Placing a group of widgets (RoundButtons and Text widgets) at the edge of their parent widget
Problem: The widgets that need to move are still close to their nearby widgets
Here is a screenshot showing the problem:
Here's the desired output:
The following code snippet shows the widgets that I need to move to the end of the parent:
Widgets to be moved: inner Row and its widgets.
Row(//parent widget
children: <Widget>[
Row(//To be moved to the end of the parent
children: <Widget>[
RoundIconButton(
icon: FontAwesomeIcons.minus, onPressed: () {}),
Text('$_counter'),
RoundIconButton(
icon: FontAwesomeIcons.plus, onPressed: () {}),
],
),
Text('10000', style: GoogleFonts.cairo(fontSize: 15)),
],
),
Here is the current implementation that corresponds to the screenshot above:
Container(
width: deviceWidth,
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Padding(
padding: EdgeInsets.only(right: 10),
child: Column(
textDirection: TextDirection.rtl,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
'Product',
style: GoogleFonts.cairo(
fontSize: 15,
),
),
Text(
'subtitle',
style: GoogleFonts.cairo(
fontSize: 15,
fontWeight: FontWeight.w200,
),
),
StrikeThroughWidget(
child: Text(
'5000',
style: GoogleFonts.cairo(
fontSize: 10,
fontWeight: FontWeight.w200,
),
),
),
Row(
children: <Widget>[
Row(
children: <Widget>[
RoundIconButton(
icon: FontAwesomeIcons.minus, onPressed: () {}),
Text('$_counter'),
RoundIconButton(
icon: FontAwesomeIcons.plus, onPressed: () {}),
],
),
Text('10000', style: GoogleFonts.cairo(fontSize: 15)),
],
),
],
),
),
Container(
padding: const EdgeInsets.all(3.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(color: Colors.grey[350])),
width: 90,
height: 90,
child: FlutterLogo(),
),
],
),
),
Already-tried Solutions:
Changing mainAxisAlignment of the Row with multiple values but didn't get the desired output
Placing the Row inside of a Flex Widget
You can separate the Widgets in multiple layers using Stack and use Position to place the layers exactly where you want.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Material(
child: Center(
child: Stack(
children: <Widget>[
Container(
width: 500,
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Padding(
padding: EdgeInsets.only(right: 10),
child: Column(
textDirection: TextDirection.rtl,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text('Product'),
Text('subtitle'),
Text('5000'),
Text('10000'),
],
),
),
Container(
padding: const EdgeInsets.all(3.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(color: Colors.grey[350])),
width: 90,
height: 90,
child: FlutterLogo(),
),
],
),
),
Positioned(
bottom: 0,
left: 0,
child: Row(
children: <Widget>[
CircleAvatar(
backgroundColor: Colors.blue,
radius: 20,
child: IconButton(
padding: EdgeInsets.zero,
icon: Icon(Icons.add),
color: Colors.white,
onPressed: () {},
),
),
Text('1'),
CircleAvatar(
backgroundColor: Colors.blue,
radius: 20,
child: IconButton(
padding: EdgeInsets.zero,
icon: Icon(Icons.remove),
color: Colors.white,
onPressed: () {},
),
),
],
),
)
],
),
),
),
);
}
Hope this helps.
You could use a Stack and Positioned:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Material(child: Center(
child:
Container(
color: Colors.grey,
width: 400,
height: 100,
child: Stack(children: <Widget>[
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Padding(
padding: EdgeInsets.only(right: 10),
child: Column(
textDirection: TextDirection.rtl,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
'Product',
style: TextStyle(
fontSize: 15,
),
),
Text(
'subtitle',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w200,
),
),
Text(
'5000',
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.w200,
),
),
],
),
),
Container(
padding: const EdgeInsets.all(3.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(color: Colors.grey[350])),
width: 90,
height: 90,
child: FlutterLogo(),
),
],
),
Positioned(
bottom: 0,
left: 0,
child: Row(
children: <Widget>[
Row(
children: <Widget>[
RawMaterialButton(
child: Text("-"), onPressed: () {}),
Text('6'),
RawMaterialButton(
child: Text("+"), onPressed: () {}),
],
),
Text('10000', style: TextStyle(fontSize: 15)),
],
),),
]
),),),),
);
}
}
Try adding a Spacer
Row(//parent widget
children: <Widget>[
Row(//To be moved to the end of the parent
children: <Widget>[
RoundIconButton(
icon: FontAwesomeIcons.minus, onPressed: () {}),
Text('$_counter'),
RoundIconButton(
icon: FontAwesomeIcons.plus, onPressed: () {}),
],
),
Spacer(),//Where I added the spacer
Text('10000', style: GoogleFonts.cairo(fontSize: 15)),
],
),

how to set the size of rows and columns as their parent widget in flutter?

Using a Column in a Row which is a child of a Card widget, how do I set the Column width as large as the row widget?
return Card(
child: Row(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(4.0),
child: Container(
width: 100.0,
height: 100.0,
// container for image
color: Colors.grey,
),
),
Column(
//crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Item Name',
textAlign: TextAlign.left,
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
),
),
Text(
'Previous Price',
style: TextStyle(fontSize: 15.0, color: Colors.grey),
),
Row(
children: <Widget>[
RaisedButton(
textColor: Colors.white,
child: Text('Add'),
),
Icon(Icons.add),
Container(
width: 50.0,
height: 50.0,
child: Text('12'),
color: Colors.red[200],
),
Icon(Icons.remove),
],
),
],
),
],
),
)
import 'package:flutter/material.dart';
main() => runApp(MyApp());
class MyApp extends StatefulWidget {
#override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SafeArea(
child: Container(
child: Card(
child: Row(
children: [
Padding(
padding: const EdgeInsets.all(4.0),
child: Container(
width: 100.0, height: 100.0,
// container for image
color: Colors.grey,
),
),
Container(
color: Colors.red,
child: Column(
mainAxisSize: MainAxisSize.min,
//crossAxisAlignment: CrossAxisAlignment.stretch,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Item Name',
textAlign: TextAlign.left,
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
),
),
Text(
'Previous Price',
style: TextStyle(fontSize: 15.0, color: Colors.grey),
),
Container(
child: Row(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
RaisedButton(
textColor: Colors.white,
child: Text('Add'),
onPressed: () {},
),
Icon(Icons.add),
Padding(
padding: const EdgeInsets.all(5.0),
child: Container(
width: 50.0,
height: 50.0,
child: Center(child: Text('12')),
color: Colors.red[200],
),
),
Icon(Icons.remove),
],
),
),
],
),
),
],
),
),
),
)));
}
}
let me know if this works maybe I am correct, but still, the description is about confusing. looking at your code I made the prediction.
Thanks.
I'm a little confused by your description,
but crossAxisAlignment: CrossAxisAlignment.stretch might be the answer to the title.
Try using,
Expanded(
child:Container(
child: Row(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
RaisedButton(
textColor: Colors.white,
child: Text('Add'),
onPressed: () {},
),
Icon(Icons.add),
Padding(
padding: const EdgeInsets.all(5.0),
child: Container(
width: 50.0,
height: 50.0,
child: Center(child: Text('12')),
color: Colors.red[200],
),
),
Icon(Icons.remove),
],
),
),
)

How to position these icons in Flutter?

I'm trying to re-create layout from Gmail, but I don't know how to position icons in my layout.
Here's an Image how I want these icons to look like:
Here's an image of what I already did in Flutter:
I want the icons to have a space between them and I'd like them to be at the same level of height as "McDonald Poland".
Is there anyone, who can help me?
Code:
import 'package:flutter/material.dart';
class GeneratedMailCouponScreen extends StatelessWidget {
final String couponImage;
GeneratedMailCouponScreen({Key key, #required this.couponImage}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: SafeArea(
child: Container(
padding: EdgeInsets.all(16.0),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Icon(
Icons.arrow_back
)
],
),
Row(
children: [
Icon(
Icons.archive
),
SizedBox(width: 5.0),
Icon(
Icons.delete
),
SizedBox(width: 5.0),
Icon(
Icons.mail
),
SizedBox(width: 5.0),
Icon(
Icons.more_vert
)
],
)
],
),
SizedBox(height: 16.0),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Text('Voucher', style: TextStyle(color: Colors.black, fontSize: 18.0)),
SizedBox(width: 8.0),
Container(
color: Colors.grey[200],
child: Padding(
padding: EdgeInsets.fromLTRB(4, 2, 4, 2),
child: Text('Odebrane', style: TextStyle(color: Colors.black, fontSize: 12.0),),
),
)
],
),
Row(
children: [
Icon(
Icons.star_border
)
],
)
],
),
SizedBox(height: 16.0),
Row(
children: [
Container(
height: 45.0,
width: 45.0,
decoration: BoxDecoration(
color: Colors.blue[100],
shape: BoxShape.circle
),
child: Center(
child: Text('M', style: TextStyle(fontSize: 20.0),),
)
),
Row(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text('McDonalds Poland', style: TextStyle(color: Colors.black)),
SizedBox(width: 8.0),
Text('Wczoraj', style: TextStyle(color: Colors.grey))
],
),
Row(
children: [
Text('do mnie', style: TextStyle(color: Colors.grey)),
Icon(
Icons.expand_more
)
],
)
],
),
Row(
children: [
Icon(
Icons.reply
),
Icon(
Icons.more_vert
)
],
)
],
)
],
)
],
),
),
),
);
}
}
I have made some modifications to your code please check is it works for you
import 'package:flutter/material.dart';
class GeneratedMailCouponScreen extends StatelessWidget {
final String couponImage;
GeneratedMailCouponScreen({Key key, #required this.couponImage})
: super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: SafeArea(
child: Container(
padding: EdgeInsets.all(16.0),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [Icon(Icons.arrow_back)],
),
Row(
children: [
Icon(Icons.archive),
SizedBox(width: 5.0),
Icon(Icons.delete),
SizedBox(width: 5.0),
Icon(Icons.mail),
SizedBox(width: 5.0),
Icon(Icons.more_vert)
],
)
],
),
SizedBox(height: 16.0),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Text(
'Voucher',
style: TextStyle(color: Colors.black, fontSize: 18.0),
),
SizedBox(width: 8.0),
Container(
color: Colors.grey[200],
child: Padding(
padding: EdgeInsets.fromLTRB(4, 2, 4, 2),
child: Text(
'Odebrane',
style:
TextStyle(color: Colors.black, fontSize: 12.0),
),
),
)
],
),
Row(
children: [Icon(Icons.star_border)],
)
],
),
SizedBox(height: 16.0),
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
height: 45.0,
width: 45.0,
decoration: BoxDecoration(
color: Colors.blue[100], shape: BoxShape.circle),
child: Center(
child: Text(
'M',
style: TextStyle(fontSize: 20.0),
),
),
),
SizedBox(width: 10),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text(
'McDonalds Poland',
style: TextStyle(color: Colors.black),
),
SizedBox(width: 8.0),
Text(
'Wczoraj',
style: TextStyle(color: Colors.grey),
)
],
),
Row(
children: [
Text('do mnie',
style: TextStyle(color: Colors.grey)),
Icon(Icons.expand_more)
],
)
],
),
Spacer(flex: 1,),
Row(
children: [Icon(Icons.reply), Icon(Icons.more_vert)],
)
],
)
],
),
),
),
);
}
}
I made a some changes. Now these icons are same height as text height, I hope works for you
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: SafeArea(
child: Container(
padding: EdgeInsets.all(16.0),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [Icon(Icons.arrow_back)],
),
Row(
children: [
Icon(Icons.archive),
SizedBox(width: 5.0),
Icon(Icons.delete),
SizedBox(width: 5.0),
Icon(Icons.mail),
SizedBox(width: 5.0),
Icon(Icons.more_vert)
],
)
],
),
SizedBox(height: 16.0),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Text('Voucher',
style:
TextStyle(color: Colors.black, fontSize: 18.0)),
SizedBox(width: 8.0),
Container(
color: Colors.grey[200],
child: Padding(
padding: EdgeInsets.fromLTRB(4, 2, 4, 2),
child: Text(
'Odebrane',
style:
TextStyle(color: Colors.black, fontSize: 12.0),
),
),
)
],
),
Row(
children: [Icon(Icons.star_border)],
)
],
),
SizedBox(height: 16.0),
Container(
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
height: 45.0,
width: 45.0,
decoration: BoxDecoration(
color: Colors.blue[100], shape: BoxShape.circle),
child: Center(
child: Text(
'M',
style: TextStyle(fontSize: 20.0),
),
)),
SizedBox(
width: 16,
),
Expanded(
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
child: Row(
children: <Widget>[
Text('McDonalds Poland',
style:
TextStyle(color: Colors.black)),
SizedBox(width: 8.0),
Text('Wczoraj',
style:
TextStyle(color: Colors.grey)),
],
),
),
Container(
child: Row(
children: <Widget>[
Icon(Icons.reply),
Icon(Icons.more_vert)
],
),
)
],
),
),
Container(
child: Row(
children: [
Text('do mnie',
style: TextStyle(color: Colors.grey)),
Icon(Icons.expand_more)
],
),
)
],
),
),
),
],
),
),
],
),
),
),
);
}
this is work! You have to put the 'M' Container inside the Row and put the icons inside a Container
return Scaffold(
body: Container(
padding: EdgeInsets.only(top: 50),
child: new Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Container(
height: 45.0,
width: 45.0,
decoration: BoxDecoration(
color: Colors.blue[100], shape: BoxShape.circle),
child: Center(
child: Text(
'M',
style: TextStyle(fontSize: 20.0),
),
)),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text('McDonalds Poland',
style: TextStyle(color: Colors.black)),
SizedBox(width: 8.0),
Text('Wczoraj',
style: TextStyle(color: Colors.grey))
],
),
Row(
children: [
Text('do mnie',
style: TextStyle(color: Colors.grey)),
Icon(Icons.expand_more)
],
)
],
),
],
),
Container(
padding: EdgeInsets.only(top: 50),
child: Row(
children: [
Icon(Icons.reply),
Icon(Icons.more_vert)
],
),
)
],
)
])),
);

[flutter]Why my column alignment is always center?

I declared two columns in a row to layout the text and the icon.
The column for the icon is always center even if I set the mainAxisAlignment with MainAxisAlignment.start.
Here is the code for the card:
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:life_logger/models.dart';
import 'package:life_logger/screens/entry_editor_screen.dart';
import 'package:life_logger/widgets/dot.dart';
Wrap buildActivities(Entry entry) {
var children = <Widget>[];
var idx = 0;
entry.activities.forEach((activity) {
var element = Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
Icon(
activity.iconData,
color: entry.mood.color,
),
SizedBox(
width: 3,
),
Text(
'${activity.description}',
style: TextStyle(color: Colors.grey),
),
]);
children.add(element);
if (idx < entry.activities.length - 1) {
children.add(Dot());
}
idx++;
});
return Wrap(
children: children,
spacing: 5,
crossAxisAlignment: WrapCrossAlignment.center,
);
}
Widget buildEntryRow(Entry entry, BuildContext context) {
var entryRow = GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => EntryEditorScreen(entry)),
);
},
child: Row(
children: <Widget>[
// the column for the icon
Column(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 8.0, right: 8.0),
child: Icon(
entry.mood.iconData,
color: entry.mood.color,
size: 48,
),
),
],
),
Expanded(
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Baseline(
baseline: 30.0,
baselineType: TextBaseline.alphabetic,
child: Text(
entry.mood.description,
style: TextStyle(
color: entry.mood.color,
fontSize: 24,
),
),
),
Baseline(
baseline: 30.0,
baselineType: TextBaseline.alphabetic,
child: Text(
DateFormat.Hm().format(entry.createdAt),
style: TextStyle(
color: Colors.grey,
fontSize: 16,
),
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Expanded(child: buildActivities(entry)),
],
),
Row(
children: <Widget>[
Text(
entry.note,
style: TextStyle(
color: Colors.grey,
fontSize: 16,
),
),
],
),
],
),
),
],
));
return entryRow;
}
class EntryCard extends StatefulWidget {
final List<Entry> entries;
EntryCard(this.entries);
#override
_EntryCardState createState() => _EntryCardState();
}
class _EntryCardState extends State<EntryCard> {
#override
Widget build(BuildContext context) {
var dateRow = Container(
height: 30,
decoration: BoxDecoration(
color: widget.entries[0].mood.color.withOpacity(0.5),
borderRadius: BorderRadius.all(Radius.circular(4.0)),
),
child: Row(
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 24.5, right: 24.5),
child: Ring(
size: 5.0,
color: widget.entries[0].mood.color,
),
),
Text(
DateFormat('EEEEE, M月d日').format(widget.entries[0].createdAt),
style: TextStyle(
color: widget.entries[0].mood.color,
fontSize: 14,
),
)
],
));
return Card(
child: Column(
children: <Widget>[dateRow] +
widget.entries.map((entry) => buildEntryRow(entry, context)).toList(),
));
}
}
The actual layout as follow:
Use crossAxisAlignment: CrossAxisAlignment.start
And for future, I would suggest you to add code that is independent of other code so that others can run it and see.
like that for one widget
Container(
child: Align(
alignment: Alignment.centerRight,
child: Text(S.current.forgetPassword),
),
),
or for all
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
If you want you can adjust column according to you .
Here is code of how to call widgets of columns at start.
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
Use it :
Column(
children: const <Widget>[
Align(
alignment: Alignment.centerLeft,
child: Text('Text 1')
),
Align(
alignment: Alignment.centerLeft,
child: Text('Text 2')
),
],
)
Setting the height of the Container worked for me:
height: double.infinity,