I am trying to create a new text field, but I don't know how to get the text in the position I want. When trying to program, it stays in this position:
but I want it to look like this, in this position:
This is the code:
body: Container(
padding: EdgeInsets.only(left: 25, bottom: 15),
height: 80,
decoration: BoxDecoration(
color: Color.fromARGB(255, 73, 158, 138),
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(36),
bottomRight: Radius.circular(36),
)
),
child: Column(
children: <Widget>[
Text(
"Olá, usuário",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 35,
),
),
Text(
"Olá, usuário",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 35,
),
),
],
),
),
DEMO
remove height
and set width as infinite to fill the parent using width: double. Infinity, Also set Column to have
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
Container should be first of child of Column
Related
In flutter how to set a text widget under a sized box in a container as below? I tried but didn't get what I wanted. Thanks in advance!
[1]: https://i.stack.imgur.com/fLRje.jpg,
[2]: https://i.stack.imgur.com/dfMa8.jpg
[What I want][1]
[What I get][2]
Row(
children: [
Container(
decoration: BoxDecoration(
border: Border.all(
color: Color(0xffb2b2b2),
),
borderRadius: BorderRadius.all(Radius.circular(10))),
child: SizedBox(
width: 70.0,
height: 70.0,
child: Card(
color: Color(0xffe31da8),
child: IconButton(
onPressed: () {},
icon: Icon(Icons.notifications,
size: 40, color: Colors.white),
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)),
)),
Padding(
padding: const EdgeInsets.only(left: 30, top: 30),
child: Row(
children: [
const Text('Language',
style: TextStyle(
fontSize: 17,
letterSpacing: 0.5,
fontWeight: FontWeight.bold,
color: Color(0xff5f2dea),
decorationStyle: TextDecorationStyle.wavy)),
],
),
),
),
],
),
To add multiple widget vertically you have to use Column. Row is used to multiple widget in one line (Horizontally). 1. Remove unnecessary use of Row from your code. Use padding, margin or alignment parameters to give proper spacing or alignment. Here is updated code:
Container(
decoration: BoxDecoration(
border: Border.all(
color: Color(0xffb2b2b2),
),
borderRadius: BorderRadius.all(Radius.circular(10))),
child: SizedBox(
width: 120.0,
height: 120.0,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Card(
color: Color(0xffe31da8),
child: IconButton(
onPressed: () {},
icon: Icon(Icons.notifications,
size: 40, color: Colors.white),
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)),
),
Padding(
padding: const EdgeInsets.only(top: 30),
child: const Text('Language',
style: TextStyle(
fontSize: 14,
letterSpacing: 0.5,
fontWeight: FontWeight.bold,
color: Color(0xff5f2dea),
decorationStyle: TextDecorationStyle.wavy)),
),
],
)),
),
I want to create a padding between the text and the blue part. Now it looks like this:
But I want a space like this:
This is the code:
body: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
padding: EdgeInsets.only(left: 25, bottom: 24),
// height: 100,
width: double.infinity,
decoration: BoxDecoration(
color: Color.fromARGB(255, 92, 172, 178),
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(36),
bottomRight: Radius.circular(36),
)
),
child: const Text(
"Olá, usuário",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 35,
),
)),
Center(child: Text(
"As suas finanças estão:",
style: TextStyle(
color: Colors.black,
fontSize: 18,
)),
)]),
You can include a SizedBox(height: 200), before Center widget. Or Padding widget with only top.
Another thing is you can use crossAxisAlignment: CrossAxisAlignment.center,
body: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
padding: const EdgeInsets.only(left: 25, bottom: 24),
width: double.infinity,
decoration: BoxDecoration(
color: Color.fromARGB(255, 92, 172, 178),
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(36),
bottomRight: Radius.circular(36),
)),
child: const Text(
"Olá, usuário",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 35,
),
)),
SizedBox(height: 100),
Text("As suas finanças estão:",
style: TextStyle(
color: Colors.black,
fontSize: 18,
)),
]),
Also you can use LayoutBuilder to get widget size & You may like to add top text as custom AppBar.
You can use toolbarHeight to get more size, or bottom
appBar: AppBar(
// toolbarHeight: ,
bottom: PreferredSize(
child: Container(
child: Row(
children: [],
),
),
preferredSize: Size.fromHeight(100),
),
),
For customAppBar with PreferredSizeWidget and also you can check SliverHeaderDelegate
child: Card(
elevation: 10,
child: Container(
decoration: BoxDecoration(
color: Colors.black87,
borderRadius: BorderRadius.circular(7)),
height: 50,
width: 50,
margin: EdgeInsets.all(5),
child: Center(
child: Text(
"${toplist[index]}".toUpperCase(),
style: TextStyle(
fontSize: 20,
fontFamily: "regular",
color: Colors.white,
fontWeight: FontWeight.bold),
)),
),
),
every time change value of the text in gridview and change the container size, I get a fixed size of the container on every random text.
Put your (Card) Widget inside a (FittedBox) Widget, and select (scaleDown) to your (fit option) as you see below in the code sample.
FittedBox(
fit: BoxFit.scaleDown,
child: Card(
elevation: 10,
child: Container(
decoration: BoxDecoration(
color: Colors.black87,
borderRadius: BorderRadius.circular(7)),
height: 50,
width: 50,
margin: EdgeInsets.all(5),
child: Center(
child: Text(
"${toplist[index]}".toUpperCase(),
style: TextStyle(
fontSize: 20,
fontFamily: "regular",
color: Colors.white,
fontWeight: FontWeight.bold),
)),
),
),
),
In this code when I am not using row then proceed button is not expanding but when I am using Row for adding one more widget then that is expanding.
This is my code.
Stack(
alignment: Alignment.centerRight,
children: [
Container(
margin: EdgeInsets.all(5),
height: 150,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
'assets/assets_allocation_image.png',
),
fit: BoxFit.fill)),
),
Column(
children: [
Text(
"Know your\nASSET ALLOCATION",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: tSize18,
fontWeight: FontWeight.w600),
overflow: TextOverflow.ellipsis,
maxLines: 2,
),
Padding(
padding: const EdgeInsets.only(
top: 20,
),
child: Container(
padding: const EdgeInsets.only(
left: 10, right: 10, top: 5, bottom: 5),
decoration: BoxDecoration(
color: orangeColor,
border: Border.all(
color: orangeColor, width: 2.0, style: BorderStyle.solid),
borderRadius: BorderRadius.all(
Radius.circular(3),
),
),
child: Row( // here
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Proceed',
style: TextStyle(
fontSize: tSize12,
fontWeight: FontWeight.w500,
color: whiteColor),
textAlign: TextAlign.center,
),
SizedBox(width: 3,),
Icon(
Icons.arrow_circle_right_outlined,
color: Colors.white,
size: 18,
)
],
),
),
),
],
),
],
);
This is my ui
I want UI like this
How to possible without wrapping in container and without giving width Becouse if I will give fix width then if user changed text size from mobile device then it will give me overflow error.
so how to fix it?
You can apply mainAxisSize and row will not expand anymore
Row(
mainAxisSize: MainAxisSize.min,
...
Container tries to expand to the available space. Since you are using Column as it's parent, there are no restrictions on width of the Container. Hence it expands to its full width.
One way you can achieve is by replacing the Container with DecoratedBox which has no size constraints and tries to fit to the width and height of its child widget. Use proper padding around the Text widget. That would be sufficient to achieve the above.
Also add mainAxisSize: MainAxisSize.min to Row widget.
Example code is as below. Please look at the code comment as well for the changes
Column(
children: [
Text(
"Know your\nASSET ALLOCATION",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: tSize18,
fontWeight: FontWeight.w600),
overflow: TextOverflow.ellipsis,
maxLines: 2,
),
child: DecoratedBox( // change Container to DecoratedBox
decoration: BoxDecoration(
color: orangeColor,
border: Border.all(
color: orangeColor, width: 2.0, style: BorderStyle.solid),
borderRadius: BorderRadius.all(
Radius.circular(3),
),
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal:24,vertical:16),//here change the value as per your requirement
child :Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Proceed',
style: TextStyle(
fontSize: tSize12,
fontWeight: FontWeight.w500,
color: whiteColor),
textAlign: TextAlign.center,
),
SizedBox(width: 3,),
Icon(
Icons.arrow_circle_right_outlined,
color: Colors.white,
size: 18,
)
],
),
),
),
],
)
I have this ListView.generator that returns such Containers
Container(
child: Row(
children: <Widget>[
Container(
child: null,
width: 10,
height: 10,
decoration: BoxDecoration(
color: social[i].color,
shape: BoxShape.circle,
),
margin: EdgeInsets.only(right: 7, top: 1,),
),
Text(
social[i].name,
style: TextStyle(
color: Colors.white,
fontFamily: 'Muli',
fontSize: 24.0,
fontWeight: FontWeight.w700
),
)
],
),
width: social[i].name.length * 16.0,
)
Right know I'm making use of width to set it based on text length but it's giving me and inadequate result as spacing between twitter and instagram is bigger than it should be.
The result I want being this with an even space between them.
A Wrap widget with spacing set to even wouldn't help as I want this list to have a full width of the user resolution and to be aligned to the left.
you can use mainAxisAlignment: MainAxisAlignment.spaceEvenly for Row element like
Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Container(
child: null,
width: 10,
height: 10,
decoration: BoxDecoration(
color: social[i].color,
shape: BoxShape.circle,
),
margin: EdgeInsets.only(right: 7, top: 1,),
),
Text(
social[i].name,
style: TextStyle(
color: Colors.white,
fontFamily: 'Muli',
fontSize: 24.0,
fontWeight: FontWeight.w700
),
)
],
),
width: social[i].name.length * 16.0,
)
In case you want to know more about it. https://medium.com/jlouage/flutter-row-column-cheat-sheet-78c38d242041 you can check this article. I found it really helpful.