Flutter add space between text and border bottom - flutter

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
)
)
),
),
],
),

Related

How to use center widget for the child of a wrap widget without expanding the child to the full width?

When I use center in a text used in Wrap widget as shown in the code below:
Wrap(
children: [
Padding(
padding: const EdgeInsets.symmetric(
vertical: 6.0),
child: Container(
decoration: BoxDecoration(
color: Colors.transparent,
borderRadius: BorderRadius.circular(27),
border: Border.all(
color: Colors.grey.withOpacity(0.60)),
),
padding: EdgeInsets.fromLTRB(9,6,9,6),
child: Center(<--placing this center widget makes the child expand to full width
child: Text(
'NTU',
style: TextStyle(
color: Colors.white.withOpacity(0.87),
fontSize: 16.5,
),
),
),
),
)
]),
the container expands to the full width as shown below:
What I want is:
But placing a center widget in the child of the Wrap widget seems to make it expand to the full width. Any suggestion on how to make it shrink to the child's width even when the center widget is used? Thank you.
Set widthFactor of Center widget to set its width to the child's width multiplied by this factor.
return Wrap(
children: [
Padding(
padding: const EdgeInsets.symmetric(
vertical: 6.0),
child: Container(
decoration: BoxDecoration(
color: Colors.transparent,
borderRadius: BorderRadius.circular(27),
border: Border.all(
color: Colors.grey.withOpacity(0.60)),
),
padding: const EdgeInsets.fromLTRB(9,6,9,6),
child: Center(
widthFactor: 1.5,
child: Text(
'NTU',
style: TextStyle(
color: Colors.white.withOpacity(0.87),
fontSize: 16.5,
),
),
),
),
)
]),
Try giving width to your container,
Wrap(
children: [
Align(
alignment: Alignment.centerLeft,
child: Container(
width: 100,
decoration: BoxDecoration(
color: Colors.transparent,
borderRadius: BorderRadius.circular(27),
border: Border.all(color: Colors.grey.withOpacity(0.60)),
),
padding: EdgeInsets.fromLTRB(9, 6, 9, 6),
child: Center(
child: Text(
'NTU',
style: TextStyle(
color: Colors.black.withOpacity(0.87),
fontSize: 16.5,
),
),
),
),
)
],
),
try this code:
Wrap(
children: [
Row(
children: [
Flexible(
child: SizedBox(width: MediaQuery.of(context).size.width),
),
Container(
width: 100,
decoration: BoxDecoration(
color: Colors.transparent,
borderRadius: BorderRadius.circular(27),
border: Border.all(color: Colors.grey.withOpacity(0.60)),
),
padding: EdgeInsets.fromLTRB(9, 6, 9, 6),
child: Center(
child: Text(
'NTU',
style: TextStyle(
color: Colors.black.withOpacity(0.87),
fontSize: 16.5,
),
),
),
),
Flexible(
child: SizedBox(width: MediaQuery.of(context).size.width),
),
],
),
],
),

Create color with round in a widget - Flutter

I cant able to achieve this round design below the Banana image.
When i try to add gradient, it is not creating sharp differentiator.
How can i achieve this in Flutter.
You will just need a Stack widget & place a Container with a circular shape.
To create a circle, you can use the shape property of Container & set it to BoxShape.circle. Then, place the remaining widgets on top of each other.
The resulting output of the below code is as follows:
Your code should look something like this:
return Stack(
children: [
// Green Background
Container(
height: 400,
decoration: BoxDecoration(
color: Colors.green,
),
),
// Circle
Positioned(
right: -50,
top: -50,
child: Container(
height: 300,
width: 300,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.black12,
),
),
),
Positioned(
top: 20,
right: 20,
left: 20,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(
child: TextFormField(
decoration: InputDecoration(
filled: true,
hintText: 'Search for products',
),
)),
IconButton(icon: Icon(Icons.search), onPressed: () {}),
],
),
Container(
margin: const EdgeInsets.only(top: 40),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text('BANANA 5% OFF',
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 30,
),),
),
Expanded(
child: Container(
height: 150,
width: 150,
color: Colors.white10,
alignment: Alignment.center,
child: Text('Image'),
),
),
],
),
),
],
),
),
],
);

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.

Align image right in the stack of 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,
)),
),)
],
),