I'm trying to align widget inside the row but the widget automatically aligns to the center. I want to align both the widget to the top of the row.
Widget PlayerConnectWidget(double width,double height){
return SingleChildScrollView(
child: Container(
margin: EdgeInsets.only(left: width*0.03,right: width*0.03,top: width*0.05),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Flexible(flex:1,fit:FlexFit.loose,child:MyFeedTile(),),
Flexible(flex:1,fit:FlexFit.loose,child:_logoContainer(width),),
],),
SizedBox(height: width*0.02),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Expanded(flex: 7,child: Container(
margin: EdgeInsets.only(right: width*0.03),
padding: EdgeInsets.all(width*0.03),
decoration: BoxDecoration(color: Colors.white70,borderRadius: new BorderRadius.circular(12.0),),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Text('Venue'),
new Divider(
color: Colors.black87,
),
Text('Location'),
new Divider(
color: Colors.black87,
),
Text('Sports'),
new Divider(
color: Colors.black87,
),
Text('Opening Times'),
new Divider(
color: Colors.black87,
),
Text('Notes'),
new Divider(
color: Colors.black87,
),
],),
),),
Expanded(flex: 3, child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
// mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
// SizedBox(height: width*0.02),
Container(
decoration: BoxDecoration(
color: MyColors.yellowBg,
borderRadius: new BorderRadius.circular(8.0),
),
child: FlatButton(
onPressed: (){
},
child: Text(
'Message',
style: TextStyle(
color: Colors.white,
fontSize: 16.0,
)
)
),),
SizedBox(height: width*0.02),
Container(
decoration: BoxDecoration(
color: MyColors.yellowBg,
borderRadius: new BorderRadius.circular(8.0),
),
child: FlatButton(
onPressed: (){
},
child: Text(
'Continue',
style: TextStyle(
color: Colors.white,
fontSize: 16.0,
)
)
),)
],),)
],)
],
),
)
);
}
Widget _logoContainer(double width){
return Container(
margin: EdgeInsets.only(left:width*0.05),
height: 110.0,
width: 120.0,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/cmp_click.png"),
fit: BoxFit.fill,
)
),
);
}
Widget MyFeedTile(){
return GestureDetector(
onTap: (){
Navigator.push(context, MaterialPageRoute(builder: (context) => FeedView()),);
},
child: Container(
padding: EdgeInsets.only(top:width*0.02,bottom: width*0.02),
decoration: BoxDecoration(
color: MyColors.colorPrimaryDark,
borderRadius: new BorderRadius.circular(12.0),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Expanded(flex: 3,
child: Container(
//decoration: BoxDecoration(color: Colors.green[100]),
height: 50,
width: 50,
margin: EdgeInsets.all(width*0.01),
child: CircleAvatar(
radius: 50.0,
backgroundImage:
NetworkImage('https://via.placeholder.com/150'),
backgroundColor: Colors.transparent,),),
),
Expanded(flex: 7,child: Container(
//decoration: BoxDecoration(color: Colors.green[100]),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Text('User name',style: TextStyle(color: Colors.white,fontFamily: 'bold'),),
SizedBox(height: width*0.01),
Text('Time',style: TextStyle(color: Colors.white,fontFamily: 'light'),),
SizedBox(height: width*0.01),
Text('Location',style: TextStyle(color: Colors.white,fontFamily: 'light'),),
SizedBox(height: width*0.01),
Text('Date',style: TextStyle(color: Colors.white,fontFamily: 'light'),),
],),),)
],),
),);
}
I'm getting this
and I'm trying to achieve this
and this
You just need to add the following line in your code :
crossAxisAlignment: CrossAxisAlignment.start
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.start,
There is a property name cross-axis alignment for both Row and Column
As I see you have used main axis alignment.
Main Axis for Column is to align children Vertically.
Main Axis for Row is to align children Horizontally.
Cross Axis for Column is to align children Horizontally.
Cross Axis for Row is to align children Vertically.
So you can try with this for your row
crossAxisAlignment: CrossAxisAlignment.start,
Related
I am trying to [![make the button ][1]][1] at the corner of the listitem but its not working
this is what i tried
Container(
margin: EdgeInsets.all(5),
padding: EdgeInsets.all(10),
color: Colors.black12,
child: Row(
mainAxisSize: MainAxisSize.max,
children: [
Container(
height: 100,
width: 100,
color: Colors.black,
child: Image.network(_items[index]['product_img']),
),
Container(
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Container(
child: Container(
padding: const EdgeInsets.all(8.0),
child: Text(_items[index]['product_name']),
),
),
Container(
padding: const EdgeInsets.all(8.0),
child: Text('M.R.P: ₹ ' +
_items[index]['product_price']),
),
Container(
child: Row(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Align(
alignment: Alignment.bottomRight,
child: Container(
padding: EdgeInsets.all(8),
child: ElevatedButton(
child: Text("Add +"),
onPressed: () =>
print("it's pressed"),
style: ElevatedButton.styleFrom(
primary: Colors.red,
onPrimary: Colors.white,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(32.0),
),
),
),
),
),
],
),
)
],
),
)
tried to set the size also but that is also not working , In one of the sugession i was told to put crossAxis also that i tried and still not working
[1]: https://i.stack.imgur.com/RQ1hY.png
I use row widget with two widgets inside, a text widget and iconbutton but iconbutton is not aligned with text and I don't know how to do it. This is a screenshot to show you
Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 10),
child: widgets[index],
),
IconButton(
icon: Icon(
Icons.close,
size: 25,
color: Colors.grey,
),
onPressed: () => {
setState(() {
widgets.remove(widgets[index]);
}),
})
],
),
Use mainAxisSize: MainAxisSize.min,
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.grey, width: 1),
borderRadius: BorderRadius.all(Radius.circular(8.0))),
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 10),
child: Text(
'Theo',
style:
TextStyle(color: Colors.deepOrangeAccent, fontSize: 20),
),
),
IconButton(
icon: Icon(
Icons.close,
size: 25,
color: Colors.grey,
),
onPressed: () => {})
],
),
),
Output:
replace CrossAxisAlignment.start with CrossAxisAlignment.baseline and add textBaseline: TextBaseline.alphabetic like this:
Row(
mainAxisSize: MainAxisSize.min,
textBaseline: TextBaseline.alphabetic,
crossAxisAlignment: CrossAxisAlignment.baseline,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 10),
child: widgets[index],
),
IconButton(
icon: Icon(
Icons.close,
size: 25,
color: Colors.grey,
),
onPressed: () => {
setState(() {
widgets.remove(widgets[index]);
}),
})
],
),
You may need this to confirm:
I used InkWell instead of iconbutton and it works
I have an issue in ROW that one child has many items so it is large and another child has fewer items so its height is small so the less item is showing in the center of the ROW, so I need it to align to the top inside the ROW, you can have a look at the image.
Please have a look at my code as well.
rowList = Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: mainBodyList,
);
MAIN BODY LIST
Container(
width: screenWidth * 0.49,
child: Card(
color: Colors.white,
child: Column(
children: <Widget>[
Container(
//width: 200,
padding: EdgeInsets.symmetric(vertical: 8, horizontal: 8),
decoration: BoxDecoration(
color: Colors.black12,
),
child: Row(
children: <Widget>[
ClipOval(
child: Material(
color: Colors.white,
child: SizedBox(
width: 40,
height: 40,
child:
/*Image.asset(
'assets/icons/doc_icon.png'),*/
Icon(
Icons.playlist_add_check,
color: AppTheme.primaryColor,
),
),
),
),
Flexible(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
_localization.localeString(name),
style: TextStyle(color: AppTheme.primaryColor),
),
],
),
),
),
],
),
),
Container(
child: Column(
children: _dynamicListWidget(list),
),
),
],
),
),
);
You need to set crossAxisAlignment as CrossAxisAlignment.start
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: mainBodyList,
);
I'm trying to make custom timeline view, Facing issue in alignment of text and circle.
The Code
Widget orderTimeLine() {
return Container(
decoration: BoxDecoration(color: Colors.white),
margin: EdgeInsets.only(
bottom: SizeConfig.safeBlockHorizontal * 3,
),
padding: EdgeInsets.only(
top: SizeConfig.safeBlockHorizontal * 3,
left: SizeConfig.safeBlockHorizontal * 7,
bottom: SizeConfig.safeBlockHorizontal * 3,
),
child: Column(
children: <Widget>[
timelineRow("Order Confirmed", orderDateTime),
timelineRow("Order Inprocess", orderDateTime),
timelineRow("Order Processed", ""),
timelineRow("Order Shipped", ""),
timelineLastRow("Order Delivered", ""),
],
),
);
}
Widget timelineRow(String title, String subTile) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Expanded(
flex: 1,
child: Column(
// mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
width: 18,
height: 18,
decoration: new BoxDecoration(
color: Colors.green,
shape: BoxShape.circle,
),
child: Text(""),
),
Container(
width: 3,
height: 50,
decoration: new BoxDecoration(
color: Colors.green,
shape: BoxShape.rectangle,
),
child: Text(""),
),
],
),
),
Expanded(
flex: 9,
child: Column(
// mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('${title}\n ${subTile}',
style: TextStyle(
fontFamily: "regular",
fontSize: 14,
color: Colors.black54)),
],
),
),
],
);
}
Widget timelineLastRow(String title, String subTile) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Expanded(
flex: 1,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
width: 18,
height: 18,
decoration: new BoxDecoration(
color: Colors.green,
shape: BoxShape.circle,
),
child: Text(""),
),
Container(
width: 3,
height: 20,
decoration: new BoxDecoration(
color: Colors.transparent,
shape: BoxShape.rectangle,
),
child: Text(""),
),
],
),
),
Expanded(
flex: 9,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('${title}\n ${subTile}',
style: TextStyle(
fontFamily: "regular",
fontSize: 14,
color: Colors.black54)),
],
),
),
],
);
}
Expected:
Getting
You could do this with timeline_tile.
Also, the beautiful_timelines repository contains some examples built with this package.
Web demo
You need to set crossAxisAligment for rows:
Widget timelineRow(String title, String subTile) {
return Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start, # <- this
I'm making custom toolbar with background shape but my back button is getting correct the alignment to the text
Widget _toolBar(String headerText){
return Container(
decoration: BoxDecoration(
color: MyColors.greenHeader,
borderRadius: new BorderRadius.only(
bottomLeft: const Radius.circular(15.0),
bottomRight: const Radius.circular(15.0))
),
child:Center(child: Stack(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Expanded(
flex: 1,
child:Text(headerText,
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 18.0,
)
),),
],),
Row(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Flexible(
flex: 1,
child:IconButton(
icon: new Icon(Icons.arrow_back_ios),
color: Colors.white,
onPressed: (){},
)
),
],),
],
),)
);
}
The above code also tried without stack by Using Row with expanded but the text alignment going wrong the text getting center to its expanded widget n
return Scaffold(
body: Stack(
children: <Widget>[
Container(
decoration: _buildBackground(),
),
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Expanded(
flex: 13,
child:_toolBar('VENUE LOGIN')
),
Expanded(
flex: 87,
child: Container(
child: LoginBody(),
),
)
],
)
],
),
);
You can try center your Text and IconButton widgets.
Stack(
children: <Widget>[
Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Expanded(
flex: 1,
child: Text(headerText,
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 18.0,
)),
),
],
),
),
Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Flexible(
flex: 1,
child: IconButton(
icon: new Icon(Icons.arrow_back_ios),
color: Colors.white,
onPressed: () {},
)),
],
),
),
],
),
You can Try like this
appBar: PreferredSize(
preferredSize: Size(null, 100),
child: Container(
width: MediaQuery.of(context).size.width,
height: 100,
child: ClipRRect(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(15),
bottomRight: Radius.circular(15)
),
child: Container(
color: Colors.green,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Icon(Icons.navigate_before,size: 40,),
Text("Center",style: TextStyle(fontSize: 30),),
Icon(Icons.navigate_before,color: Colors.transparent,),
],
),
),
),
),
),