Align image right in the stack of flutter - flutter

child: Stack(
//alignment: Alignment.center,
children: <Widget>[
Container(
alignment: Alignment.center,
width: MediaQuery.of(mContext).size.width / 1.7,
decoration: ShapeDecoration(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0)),
gradient: LinearGradient(
colors: gradient,
begin: Alignment.topLeft,
end: Alignment.bottomRight),
),
child: Text(title,
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.w500)),
padding: EdgeInsets.only(top: 16, bottom: 16),
),
Visibility(
visible: isEndIconVisible,
child: Padding(
padding: EdgeInsets.only(right: 10),
child: ImageIcon(
AssetImage("assets/ic_forward.png"),
size: 30,
color: Colors.white,
)),
),
],
),
I have a button which should be at the center of the screen. A text which is at the centre of the button and a right arrow. Since I want the button at the center i put alignment centre and so the right arrow coming as centre. Can anyone help me to solve this? I also want to know where we put click for this button.

You can use simple row Widget to achieve you expected ui.
Look at following code which help you may be.
Stack(
alignment: Alignment.center,
children: <Widget>[
Container(
alignment: Alignment.center,
width: MediaQuery.of(context).size.width / 1.7,
decoration: ShapeDecoration(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0)),
color: Colors.red
,
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text("vdsv",
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.w500)),
Visibility(
visible: true,
child: Padding(
padding: EdgeInsets.only(right: 10),
child: ImageIcon(
AssetImage("assets/images/logo.png"),
size: 30,
color: Colors.white,
)),
),
],
),
padding: EdgeInsets.only(top: 16, bottom: 16),
),
],
)

Add align before Visibility
child: Stack(
//alignment: Alignment.center,
children: <Widget>[
Container(
alignment: Alignment.center,
width: MediaQuery.of(mContext).size.width / 1.7,
decoration: ShapeDecoration(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0)),
gradient: LinearGradient(
colors: gradient,
begin: Alignment.topLeft,
end: Alignment.bottomRight),
),
child: Text(title,
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.w500)),
padding: EdgeInsets.only(top: 16, bottom: 16),
),
Align(alignment: Alignment.topRight,
child: Visibility(
visible: isEndIconVisible,
child: Padding(
padding: EdgeInsets.only(right: 10),
child: ImageIcon(
AssetImage("assets/ic_forward.png"),
size: 30,
color: Colors.white,
)),
),)
],
),

Related

ModelViewer in ListView - Flutter

I have ListView which has ModelViewer in it. ModelViewer initially makes it possible to twist the object in different directions. But inside ListView the object does not rotate. Does anyone know how to fix this?
ListView(children: [
Padding(
padding: const EdgeInsets.all(15.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
width: double.infinity,
height: 500,
child: ClipRRect(
borderRadius: BorderRadius.circular(15.0),
child: ModelViewer(
backgroundColor: Colors.grey[50],
src: 'assets/totoro.glb',
alt: "3D-модель аниме персонажа Totoro",
autoPlay: true,
autoRotate: false,
cameraControls: true,
),
),
),
const SizedBox(height: 10.0),
Container(
//height: 200,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15.0),
color: Colors.grey[50],
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.3),
blurRadius: 10)
]),
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Align(
alignment: Alignment.topLeft,
child: Text(
'Totoro is a giant furry beast that roars through the forest and makes strange sounds like "to-to-ro". In a word, Totoro is a Japanese lamb.',
style: GoogleFonts.roboto(
fontSize: 20,
color: Colors.black87.withOpacity(0.7),
fontWeight: FontWeight.w700)),
),
),
)
],
),
),
]),

Flutter add space between text and border bottom

I have this code in my Flutter project:
Row(
children: <Widget>[
Align(
alignment: Alignment.centerLeft,
child: Icon(
Icons.face,
size: _mediaWidth*0.09,
color: Colors.grey[600],
)
),
Container(
margin: EdgeInsets.symmetric(
vertical: 10,
horizontal: _mediaWidth*0.03
),
child: Stack(
children: <Widget>[
Text(
"A",
style: TextStyle(
fontSize: _mediaWidth*0.08,
color: Colors.grey[600]
),
),
Align(
alignment: Alignment.centerRight,
child: Icon(Icons.add)
),
Divider(height:10)
]
),
width: _mediaWidth*0.85,
height: _mediaHeight*0.05,
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: Colors.grey[400],
width: 1,
)
)
),
),
]
),
And I get this:
I want to increase the space between the text and the underline. I tried adding a bottom padding to the container, however, it only hid the text:
How can I properly add a space between the text and the bottom border of the container?
According do your code, the Container has an hard-coded height property:
height: _mediaHeight*0.05
Adding a padding, without increasing the height of the Widget, results in cropping the content.
The full example is reported below:
Row(
children: <Widget>[
Align(
alignment: Alignment.centerLeft,
child: Icon(
Icons.face,
size: _mediaWidth*0.09,
color: Colors.grey[600],
)
),
Container(
margin: EdgeInsets.symmetric(
vertical: 10,
horizontal: _mediaWidth*0.03
),
padding: EdgeInsets.only(bottom: 10),
child: Stack(
children: <Widget>[
Text(
"A",
style: TextStyle(
fontSize: _mediaWidth*0.08,
color: Colors.grey[600]
),
),
Align(
alignment: Alignment.centerRight,
child: Icon(Icons.add)
),
Divider(height:10)
]
),
width: _mediaWidth*0.85,
height: _mediaHeight*0.10, // we should modify the height as well
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: Colors.grey[400],
width: 1
)
)
),
),
],
),

FLUTTER : How can I make a custom flutter container?

I want to make a custom container/card that looks like:
How can I achieve overlapping/overlaying layout in flutter?
Use the Stack widget & the Positioned widget that helps to put the widgets where ever you want inside the stack
Code:
Container(
width: 135.0,
height: 80.0,
margin: EdgeInsets.only(right: 5.0),
child: Stack(
children: [
Align(
alignment: Alignment.centerLeft,
child: Container(
width: 110.0,
height: 150.0,
decoration: BoxDecoration(
color: Colors.white,
shape: BoxShape.rectangle,
borderRadius: BorderRadius.all(Radius.circular(20.0)),
),
child: Align(
alignment: Alignment.bottomLeft,
child: Padding(
padding: EdgeInsets.only(left: 15.0, bottom: 20.0),
child: Text(
text,
style: TextStyle(
fontSize: 15.0,
fontFamily: 'PlayfairDisplay',
color: kInactiveSearchPageTextColor,
),
),
),
),
),
),
Align(
alignment: Alignment.topLeft,
child: Image.asset(
image,
width: 110,
height: 110,
),
),
Positioned(
top: 162,
left: 90,
child: Container(
width: 41.0,
height: 41.0,
child: RawMaterialButton(
fillColor: Colors.white,
shape: CircleBorder(),
elevation: 12.0,
child: Icon(
Icons.add,
color: kActiveSearchPageButtonColor,
),
onPressed: onPressed,
),
),
),
],
),
);

How do I align the contents inside my container in Flutter?

I have a few buttons that I've added inside this rounded container. I want to align alll go these in the middle. Originally when I added them they were perfectly aligned but when I changed the size of the text below the buttons the alignment got changed as well. Here is the code:
Stack(
children: <Widget>[
Padding(
padding:
const EdgeInsets.only(top: 290.0, left: 8, right: 8),
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius:
const BorderRadius.all(Radius.circular(16.0)),
),
height: 110,
),
),
Padding(
padding: const EdgeInsets.only(top: 110.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 198.0, left: 0),
child: Column(
children: <Widget>[
Container(
height: 50,
width: 50,
decoration: new BoxDecoration(
gradient: LinearGradient(
colors: [
const Color(0xFFFF8C3B),
const Color(0xFFFE524B)
],
begin: Alignment.centerLeft,
end: Alignment.centerRight,
),
color: Colors.orange,
shape: BoxShape.circle,
),
child: Icon(Entypo.login,
color: Colors.white)),
SizedBox(
height: 5,
),
Text('Sign In', style: TextStyle(
color: Color(0xFFFF8C3B),
fontFamily: "Netflix",
fontWeight: FontWeight.bold,
fontSize: 17)),
],
),
),
Padding(
padding:
const EdgeInsets.only(top: 198.0, left: 25),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
height: 50,
width: 50,
decoration: new BoxDecoration(
gradient: LinearGradient(
colors: [
const Color(0xFFFF8C3B),
const Color(0xFFFE524B)
],
begin: Alignment.centerLeft,
end: Alignment.centerRight,
),
color: Colors.orange,
shape: BoxShape.circle,
),
child: Padding(
padding: const EdgeInsets.only(
left: 2.0, top: 1),
child: Container(
child: Icon(Entypo.credit,
color: Colors.white)),
)),
SizedBox(
height: 5,
),
Text('Payments', style: TextStyle(
color: Color(0xFFFF8C3B),
fontFamily: "Netflix",
fontWeight: FontWeight.bold,
fontSize: 17)),
],
),
),
Padding(
padding:
const EdgeInsets.only(top: 198.0, left: 15),
child: Column(
children: <Widget>[
Container(
height: 50,
width: 50,
decoration: new BoxDecoration(
gradient: LinearGradient(
colors: [
const Color(0xFFFF8C3B),
const Color(0xFFFE524B)
],
begin: Alignment.centerLeft,
end: Alignment.centerRight,
),
color: Colors.orange,
shape: BoxShape.circle,
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
child: Icon(Entypo.log_out,
color: Colors.white)),
)),
SizedBox(
height: 5,
),
Text('Sign Out', style: TextStyle(
color: Color(0xFFFF8C3B),
fontFamily: "Netflix",
fontWeight: FontWeight.bold,
fontSize: 17)),
],
),
),
Padding(
padding:
const EdgeInsets.only(top: 198.0, left: 20),
child: Column(
children: <Widget>[
Container(
height: 50,
width: 50,
decoration: new BoxDecoration(
gradient: LinearGradient(
colors: [
const Color(0xFFFF8C3B),
const Color(0xFFFE524B)
],
begin: Alignment.centerLeft,
end: Alignment.centerRight,
),
color: Colors.orange,
shape: BoxShape.circle,
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
child: Icon(Entypo.info,
color: Colors.white)),
)),
SizedBox(
height: 5,
),
Text('About Us', style: TextStyle(
color: Color(0xFFFF8C3B),
fontFamily: "Netflix",
fontWeight: FontWeight.bold,
fontSize: 17)),
],
),
),
],
),
),
],
),
This is what the alignment looks like:
You can put the buttons in a row. And then, you can set MainAxisAlignment property to center.
Put the buttons in a row. And then, you can set MainAxisAlignment property to center.

Flutter : How can i create this circle avatar that's half out of the container?

How can I create this design I found in pinterest
I just wanted to create the user circle half of the container I tried many ways but failed.
Thanks.
To let that half circle get out of the box you need to add some padding on top of the Container to make room for what you desire. Here's a sample code. first define the size of the circle container. here I named it "circleRadius" :
final double circleRadius = 120.0;
Container(
height: double.infinity,
width: double.infinity,
color: Color(0xffE0E0E0),
child: Stack(children: <Widget>[
Padding(
padding: const EdgeInsets.all(16.0),
child: Stack(
alignment: Alignment.topCenter,
children: <Widget>[
Padding(
padding:
EdgeInsets.only(top: circleRadius / 2.0, ), ///here we create space for the circle avatar to get ut of the box
child: Container(
height: 300.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15.0),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black26,
blurRadius: 8.0,
offset: Offset(0.0, 5.0),
),
],
),
width: double.infinity,
child: Padding(
padding: const EdgeInsets.only(top: 15.0, bottom: 15.0),
child: Column(
children: <Widget>[
SizedBox(height: circleRadius/2,),
Text('Maria Elliot', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 34.0),),
Text('Albany, NewYork', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16.0, color: Colors.lightBlueAccent),),
SizedBox(
height: 30.0,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 32.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Column(
children: <Widget>[
Text('Likes', style: TextStyle( fontSize: 20.0, color: Colors.black54,),),
Text('12K', style: TextStyle( fontSize: 34.0, color: Colors.black87, fontFamily: ''),),
],
),
Column(
children: <Widget>[
Text('Wished', style: TextStyle( fontSize: 20.0, color: Colors.black54),),
Text('12K', style: TextStyle( fontSize: 34.0, color: Colors.black87, fontFamily: ''),),
],
),
Column(
children: <Widget>[
Text('Purchased', style: TextStyle( fontSize: 20.0, color: Colors.black54),),
Text('12K', style: TextStyle( fontSize: 34.0, color: Colors.black87, fontFamily: ''),),
],
),
],
),
)
],
)
),
),
),
///Image Avatar
Container(
width: circleRadius,
height: circleRadius,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black26,
blurRadius: 8.0,
offset: Offset(0.0, 5.0),
),
],
),
child: Padding(
padding: EdgeInsets.all(4.0),
child: Center(
child: Container(
child: Icon(Icons.person), /// replace your image with the Icon
),
),
),
),
],
),
),
]),
),
and the output:
You can use a ClipOval with the Image for the Circle
Then to get it in the half of the container use the Stack widget combined with the Positioned Widget
Example:
Stack(
children: <Widget>[
Container(
width: 250,
height: 250,
color: Colors.red,
),
Positioned(
top:50 ,//change this as needed
child:ClipOval(
child: Image.network(
'https://picsum.photos/250?image=9',
),
),
),
],
),
References
Network Image
ClipOval
Great Tutorial
Stack
Positioned