Container fill width of Column - flutter

I have a row inside this a column, column children are a two text, first text widget I put inside a container, I want the container background fill dull width of column. but the background only seen in where the text are present, left and right are empty,
here is my code
Row(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
_bookingData.bookingData[index].paymentStatusFe =="Paid" ?
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.deepPurpleAccent)
),
child:
Column(
children: <Widget>[
Container(
child: Text("Paid"),
color: Colors.red,
),
Padding(
padding: const EdgeInsets.all(2.0),
child: Text(
'AED' +
' ' +
_bookingData
.bookingData[
index]
.amount
.toString(),
style: TextStyle(
fontSize:
12,
fontFamily:
'Roboto Condensed',
color: Colors.deepPurpleAccent,
fontWeight:
FontWeight
.w600),
),
)
],
),
): Container(
// width: double.infinity,
decoration: BoxDecoration(
border: Border.all(color: Colors.red)
),
child:
Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(
"Not Paid",
style: TextStyle(
backgroundColor: Colors.red,
color: Colors.white
),
),
Padding(
padding: const EdgeInsets.all(2.0),
child: Text(
'AED' +
' ' +
_bookingData
.bookingData[
index]
.amount
.toString(),
style: TextStyle(
fontSize:
12,
fontFamily:
'Roboto Condensed',
color: Colors.red,
fontWeight:
FontWeight
.w600),
),
)
],
),
),
],
),
Row is put inside a Listview. So I want to have red in background for paid text, but red is only coming start of paid and till where it ends, not the entire column.

You have to do two changes in your code
1) Add your root container in within expanded widget
2) In your inner container set width:double.infinity
Row(mainAxisSize: MainAxisSize.max, children: <Widget>[
// first change
Expanded(
flex: 1,
child: Container(
decoration:
BoxDecoration(border: Border.all(color: Colors.deepPurpleAccent)),
child: Column(
children: <Widget>[
Container(
//second change
width: double.infinity,
child: Text("Paid"),
color: Colors.red,
),
Padding(
padding: const EdgeInsets.all(2.0),
child: Text(
'AED TEST',
style: TextStyle(
fontSize: 12,
fontFamily: 'Roboto Condensed',
color: Colors.deepPurpleAccent,
fontWeight: FontWeight.w600),
),
)
],
)),
),
]);

Related

How to Center Children of Row Widgets

I have a horizontal ListView with three Containers, I want to center the content/children of the Rows within the Containers. I have tried MainAxisAlignment.center but it does not seem to work for me.
This is the code, the mainAxisAlignment has been commented although I have tried using it to no avail.
Container(
padding: const EdgeInsets.symmetric(horizontal: 4.0),
width: 134.0,
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(8.0)),
color: Color(0xFFFF7700),
),
child: Row(
// mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
urlImage,
height: 45.0,
width: 45.0,
),
const SizedBox(width: 4.0),
Flexible(
child: Text(
title,
style: const TextStyle(
fontSize: 14.0,
fontWeight: FontWeight.w600,
color: Colors.white,
),
),
),
],
));
First, both children of the column should be wrapped inside Expanded. Then, check textAlign property of Text and set it to center
home: Scaffold(
body: Builder(builder: (context) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 4.0),
width: 134.0,
child: Container(
decoration:
BoxDecoration(border: Border.all(color: Colors.green)),
child: Row(
// mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.red)),
child: const Text('smth'),
)),
const SizedBox(width: 4.0),
Expanded(
child: Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.red)),
child: const Text(
'title',
style: TextStyle(
fontSize: 14.0,
fontWeight: FontWeight.w600,
color: Colors.black,
),
textAlign: TextAlign.center,
),
),
),
],
),
));
}),
));
RESULT
I wrapped them with border colors so you can see the difference. When both are wrapped with Expanded, they take the same space and now you can center the text.

Dart Flutter bears writing

I placed a post like this. When the text did not fit, it did not pass when it should have been on the bottom line.
Code:
body: Container(
padding: EdgeInsets.all(10),
child: Container(
height: 150,
decoration: BoxDecoration(
color: Colors.black
),
padding: EdgeInsets.all(10),
child: Container(
height: 180,
decoration: BoxDecoration(
border: Border.all(color: Colors.white, width: 2),
),
child: Row(
children: [
Padding(
padding: EdgeInsets.all(10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("Soru sor, kazan", style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold, color: Colors.white),),
Text("SorSor! uygulaması ile soru sor, para kazan! Tek amacın yaşadığın sorunları soru olarak açmak ve diğer kullanıcıların sorularını yanıtlamak.", style: TextStyle(fontSize: 16, color: Colors.white),),
],
),
),
],
),
),
)
)
I want it to go to the bottom line when there is no space left. How can I do it?
Just remove the Row widget that you have above the Padding and the issue will gone.
Container(
height: 180,
decoration: BoxDecoration(
border: Border.all(color: Colors.white, width: 2),
),
child: Padding(
padding: EdgeInsets.all(10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Soru sor, kazan",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.white),
),
Text(
"SorSor! uygulaması ile soru sor, para kazan! Tek amacın yaşadığın sorunları soru olarak açmak ve diğer kullanıcıların sorularını yanıtlamak.",
style: TextStyle(fontSize: 16, color: Colors.white),
),
],
),
),
),

how to implement textfield inside tile flutter

hi i need to design this page
but i'm new in flutter so i'm face difficult to manage to do it
here is my try
Container (
child: Column (
children: <Widget> [
Container(
margin: EdgeInsets.all(20),
child: Text(
"Source Account",
style: TextStyle(fontSize: 30,
color: Color(0xff8aa1ba)),
),
),
Container(
height: 100,
child: Card(
color: Color(0xff343b4b),
clipBehavior: Clip.antiAlias,
elevation: 10,
margin: EdgeInsets.all(7),
child: Column(
children: <Widget>[
ListTile(
title: Text("Main Account 123456",
style: TextStyle(
color: Colors.white,
fontSize: 15, fontWeight: FontWeight.bold),textAlign: TextAlign.left,),
subtitle: Text(" Available Balance \n 10.000.9 KWD" ,
style: TextStyle(
color: Colors.white,
fontSize: 15, fontWeight: FontWeight.bold),textAlign: TextAlign.right,),
),
],
),
),
),
],
),
)
so can any one help me to implement this or give me an idea of how to implement a textfield inside a list tile or card
Put a Row inside of your title. So replace the your code with something like this:
ListTile(
title: Row(
children: <Widget>[
Expanded(
child: TextField(
// your TextField's Content
),
),
],
),
Card(color: Colors.grey, child: Container(
padding: EdgeInsets.symmetric(vertical: 4, horizontal: 8), child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text("Loans", style: TextStyle(color: Colors.white, fontWeight: FontWeight.w500,),),
Column(children: [
Icon(Icons.add),
Text("Amount", style: TextStyle(color: Colors.white,),)
])
]
),
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.black),
borderRadius: BorderRadius.circular(2),
),
padding: EdgeInsets.symmetric(horizontal: 16),
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
),
style: TextStyle(color: Colors.white),
textAlign: TextAlign.end,
),
)
]),
),)

I have a problem adding a Text to a Container

I'm new to flutter and new to programming in general. My problem is I can't add this
child: Align(
alignment: Alignment(0, 48),
child: Text(
'SETS',
style: TextStyle(
fontWeight: FontWeight._(4),
fontSize: 18.0,
fontFamily: 'Roboto',
color: Color(0xFF494949)),
)),
to this code
class _SetupState extends State<Setup> {
#override
Widget build(BuildContext context) {
return Column(children: [
Align(
alignment: Alignment.topCenter,
child: SizedBox(
height: 350.0,
width: 350.0,
child: Container(
margin: const EdgeInsets.only(top: 6.0),
padding: EdgeInsets.all(8),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15.0),
color: Color(0xFFE3E3E3),
),
child: Align(
alignment: Alignment.topCenter,
child: Text(
'SET UP YOUR WORKOUT',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20.0,
fontFamily: 'Roboto',
color: Color(0xFF494949)),
)),
),
)),
]);
}
}
I tried adding it to the container, making a new align but I still didn't manage to succeed.
Thanks for the help!!
I made a layout based on the image provided in the comments:
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: SizedBox(
height: 350.0,
width: 350.0,
child: Container(
margin: const EdgeInsets.only(top: 6.0),
padding: EdgeInsets.all(8),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15.0),
color: Color(0xFFE3E3E3),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
'SET UP YOUR WORKOUT',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20.0,
fontFamily: 'Roboto',
color: Color(0xFF494949)),
),
Column(
children: <Widget>[
Text(
'SETS',
style: TextStyle(
fontWeight: FontWeight.w400,
fontSize: 16.0,
fontFamily: 'Roboto',
color: Color(0xFF494949)),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 50),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Icon(
Icons.add
),
Icon(
Icons.remove
),
],
),
),
],
),
Column(
children: <Widget>[
Text(
'WORKS',
style: TextStyle(
fontWeight: FontWeight.w400,
fontSize: 16.0,
fontFamily: 'Roboto',
color: Color(0xFF494949)),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 50),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Icon(
Icons.add
),
Icon(
Icons.remove
),
],
),
),
],
),
Column(
children: <Widget>[
Text(
'RESTS',
style: TextStyle(
fontWeight: FontWeight.w400,
fontSize: 16.0,
fontFamily: 'Roboto',
color: Color(0xFF494949)),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 50),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Icon(
Icons.add
),
Icon(
Icons.remove
),
],
),
),
],
),
Row(
children: <Widget>[
Expanded(
child: FlatButton(
color: Colors.greenAccent,
child: Text(
'START',
style: TextStyle(
fontSize: 40,
color: Colors.white,
fontWeight: FontWeight.w400
),
),
onPressed: () {
},
shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0)),
),
),
],
)
],
),
),
),
),
);
}
I used a Column(let's name it column1) for the whole grey box, and every one of (SETS, +, -), (WORK, +, -), and (RESTS, +, -) is a Column inside the column1. Every (+, -) is a Row wrapped with a Padding. The Padding is used to make the (+, -) become closer to the center of the box.
There are many ways to make such layout, this is only one.
Result:
if that does not work you can first align it the way you want. Then use padding or margin so that you can have it exactly where you want it be.
Container(
padding:
alignment:
child:Text()
)

is there a way to align icon with text

I'm building my first flutter app and I'm faced with a problem I'm trying to create a container that will allow you to choose several cities. I cannot align the text and the icon
child: Container(
padding: EdgeInsets.only(top: 16),
margin: EdgeInsets.all(50),
height: 40,
width: 700,
decoration: BoxDecoration(
border: Border.all(width: 0.5, color: Colors.brown),
borderRadius: BorderRadius.circular(50)),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Center(
child: Text(
'SÉLECTIONNEZ UNE VILLE',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.black,
fontSize: 14,
fontWeight: FontWeight.bold),
),
),
SizedBox(
width: 10,
),
Icon(
Icons.keyboard_arrow_down,
size: 30,
),
],
),
),
You need to use MainAxisAlignment and Expanded Property inside Row
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Container(
margin: EdgeInsets.all(50),
height: 40,
width: 700,
decoration: BoxDecoration(
border: Border.all(width: 0.5, color: Colors.brown),
borderRadius: BorderRadius.circular(50)),
child: Padding(
padding: EdgeInsets.only(left: 10, right: 10),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Expanded(
child: Text('SÉLECTIONNEZ UNE VILLE',
style: TextStyle(
color: Colors.black,
fontSize: 14,
fontWeight: FontWeight.bold)),
),
Icon(Icons.keyboard_arrow_down,size: 30),
],
),
),
),
);
}
Output :
Your top padding was messing the alignment.Try the following:
class MyWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
border: Border.all(width: 0.5, color: Colors.brown),
borderRadius: BorderRadius.circular(50)),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'SÉLECTIONNEZ UNE VILLE',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.black,
fontSize: 14,
fontWeight: FontWeight.bold,
),
),
const SizedBox(width: 10),
Icon(
Icons.keyboard_arrow_down,
size: 30,
),
],
),
);
}
}
You can use the crossAxisAlignment and mainAxisAlignment property of the Row widgets to determine how the children of the Row widget will be placed.
To center the Text and Icon vertically in the Row widget, set crossAxisAlignment: CrossAxisAlignment.center.
To center the Text and Icon horizontally in the Row widget, set mainAxisAlignment: MainAxisAlignment.center.
I added a demo code using your widget tree as an example, I also removed the top padding you gave the Container as it was putting the items downwards.
Container(
margin: EdgeInsets.all(50),
height: 40,
width: 700,
decoration: BoxDecoration(
border: Border.all(width: 0.5, color: Colors.brown),
borderRadius: BorderRadius.circular(50)),
child: Row(
// set the crossaxisalignment so the [items] in the will be vertically centered
crossAxisAlignment: CrossAxisAlignment.center,
// set the crossaxisalignment so the [items] will be horizontally centered
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'SÉLECTIONNEZ UNE VILLE',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.black,
fontSize: 14,
fontWeight: FontWeight.bold),
),
SizedBox(
width: 10,
),
Icon(
Icons.keyboard_arrow_down,
size: 30,
),
],
),
),
OUTPUT: