Text inside container was overflow when minimize screen in flutter - flutter

I have a container with width MediaQuery.of(context).size.width / 1.75.When I minimize screen size text inside the container is overflowing.
This is the output I got now:
class ProfileTopPortion extends StatelessWidget {
const ProfileTopPortion({
Key? key,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Column(
children: [
Padding(
padding: const EdgeInsets.all(18.0),
child: Container(
width: MediaQuery.of(context).size.width / 1.75,
decoration: BoxDecoration(
border: Border.all(color: Color(0xffEBEBEB), width: 0.4),
color: Color(0xfffbfbfa),
),
child: Row(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(left: 20.0),
child: MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
onTap: () {
// Get.toNamed('/events',arguments: 0);
},
child: Padding(
padding: const EdgeInsets.only(top: 0.0),
child: SvgPicture.asset(
allowDrawingOutsideViewBox: true,
Images.avatar,
),
)),
),
),
SizedBox(
width: 20,
),
Column(
// mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'First Name',
),
SizedBox(
height: 6,
),
Text(
'Engineer',
),
SizedBox(
height: 20,
),
Row(
children: [
Column(
// mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Email',
),
SizedBox(
height: 10,
),
Text(
'Organization',
),
],
),
SizedBox(
width: 30,
),
Column(
mainAxisSize: MainAxisSize.min,
// mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'testEmail1235#gmail.com',
),
SizedBox(
height: 10,
),
Text("Test12346#gma.com"),
],
)
],
),
SizedBox(
height: 25,
),
],
),
],
),
),
),
],
),
);
}
}
I tried flexible and expanded widgets but nothing works.

You need to use Expanded in two widget, try this:
Padding(
padding: const EdgeInsets.all(18.0),
child: Container(
width: MediaQuery.of(context).size.width / 1.75,
decoration: BoxDecoration(
border: Border.all(color: Color(0xffEBEBEB), width: 0.4),
color: Color(0xfffbfbfa),
),
child: Row(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(left: 20.0),
child: MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
onTap: () {
// Get.toNamed('/events',arguments: 0);
},
child: Padding(
padding: const EdgeInsets.only(top: 0.0),
child: SvgPicture.asset(
allowDrawingOutsideViewBox: true,
Images.avatar,
),
)),
),
),
SizedBox(
width: 20,
),
Expanded(//<---- add this
child: Column(
// mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'First Name',
),
SizedBox(
height: 6,
),
Text(
'Engineer',
),
SizedBox(
height: 20,
),
Row(
children: [
Column(
// mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Email',
),
SizedBox(
height: 10,
),
Text(
'Organization',
),
],
),
SizedBox(
width: 30,
),
Expanded(//<---- add this
child: Column(
mainAxisSize: MainAxisSize.min,
// mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'testEmail1235#gmail.com',
overflow: TextOverflow.ellipsis,//<---- add this
),
SizedBox(
height: 10,
),
Text(
"Test12346#gma.com",
overflow: TextOverflow.ellipsis,//<---- add this
),
],
),
)
],
),
SizedBox(
height: 25,
),
],
),
),
],
),
),
),

wrap this column to expanded and also wrap the inner texts into flexible
Expanded( child: Column(
mainAxisSize: MainAxisSize.min,
// mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Flexible(child:Text(
'testEmail1235#gmail.com',
)),
SizedBox(
height: 10,
),
Flexible(child:Text("Test12346#gma.com")),
],
),)

Wrap your text with FittedBox
FittedBox(
child: Text(
"your text",
),
),

Instead of using height and width for container you can use the constraints property i.e
constraints:Boxconstrains(
maxWidth:double.infinity,
maxHeight:double.infinity,
),
It will resize the container height and width according to the text inside.
You can use padding for further decoration

Related

Flutter expand row inside of a column

I have the following layout:
Row ->
Column
Padding ->
Column ->
Row ->// this one is only taking as much space as it needs
Text
Image
Text
Row
I need the row in the second column to take the whole width of the column it is wrapped in.
No matter how much I look for the answer wrapping different widgets into Flexible and Expanded doesn't help.
here is the code:
Padding(
padding: const EdgeInsets.all(10.0),
child: Row(
children: [
Column(
children: [
CircleAvatar(
radius: 25,
child: Image(
image: getCategoryImage(task.type),
),
)
],
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
// mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(task.title, style: Theme.of(context).textTheme.headlineMedium,),
const Image(
width: 20, image: AssetImage("assets/icons/task/tickbox.png"))
],
),
Text(generateBirdList(task.assignedBirds), style: Theme.of(context).textTheme.titleSmall,),
Row(
children: [
],
)
],
),
),
],
),
),
Container(
color: Colors.amber,
padding: const EdgeInsets.all(10.0),
child: Row(
children: [
Container(
color: Colors.blueAccent,
child: CircleAvatar(
radius: 25,
child: Image.network(
"https://st.depositphotos.com/1909187/2297/i/950/depositphotos_22971972-stock-photo-blank-white-male-head-front.jpg",
),
),
),
Expanded(
child: Container(
color: Colors.green,
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
// mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"task.title",
style: Theme.of(context).textTheme.headlineMedium,
),
Image.network(
"https://st.depositphotos.com/1909187/2297/i/950/depositphotos_22971972-stock-photo-blank-white-male-head-front.jpg",
width: 20,
)
],
),
Text(
"Bla bla bla text",
style: Theme.of(context).textTheme.titleSmall,
),
Row(
children: [],
)
],
),
),
),
],
),
),

Listview inside a row not working in Flutter

I need a listview inside a row.
class Profiles extends StatelessWidget {
const Profiles({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
body: Row(
children: [
SideBar(),
Expanded(
child: ListView(
children: [
Wrap(
children: [
Padding(
padding: const EdgeInsets.only(top: 40.0, left: 45),
child: Container(
width: MediaQuery.of(context).size.width / 1.75,
decoration: BoxDecoration(
border: Border.all(color: Color(0xffEBEBEB)),
color: Color(0xfffbfbfa),
),
child: Stack(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Positioned(
right: 0,
top: 0,
child: Align(
alignment: Alignment.topRight,
child: MouseRegion(
cursor: SystemMouseCursors.click,
child: Text(
"Edit",
),
),
),
),
Row(
mainAxisSize: MainAxisSize.min,
children: [
MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
onTap: () {
// Get.toNamed('/events',arguments: 0);
},
child: Padding(
padding:
const EdgeInsets.only(top: 0.0),
child: SvgPicture.asset(
allowDrawingOutsideViewBox: true,
Images.avatar,
),
)),
),
SizedBox(
width: 20,
),
Column(
// mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
'FirstName',
textAlign: TextAlign.left,
),
SizedBox(
height: 6,
),
Text("Update your role"),
SizedBox(
height: 20,
),
Row(
children: [
Column(
// mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
'Email',
textAlign: TextAlign.left,
),
SizedBox(
height: 10,
),
Text(
'Organization',
textAlign: TextAlign.left,
),
],
),
SizedBox(
width: 30,
),
Column(
mainAxisSize: MainAxisSize.min,
// mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
'email',
textAlign: TextAlign.left,
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
SizedBox(
height: 10,
),
Text(
"NA",
),
],
)
],
)
],
),
],
),
],
)
],
),
),
),
],
)
],
))
],
),
);
}
}
SideBar() is a Column widget having multiple elements. Code of the sidebar is,
class SideBar extends StatefulWidget {
#override
State<SideBar> createState() => _SideBarState();
}
class _SideBarState extends State<SideBar> {
#override
Widget build(BuildContext conText) {
return Material(
elevation: 1,
child: Container(
width: 70,
color: Color(0xFAFAFB),
child: Padding(
padding: const EdgeInsets.only(top: 15.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
children: [
SvgPicture.asset(
Images.topStoriesIcon,
),
SvgPicture.asset(
Images.topStoriesIcon,
),
SvgPicture.asset(
Images.topStoriesIcon,
)
],
),
],
),
),
),
);
}
}
I got an error: Assertion failed: constraints.hasBoundedWidth is not true.
But listview is working when I wrap with Expanded widget like this,
Row(
children: [
SideBar(),
Expanded(
child: ListView(
shrinkWrap: true,
children: [
],
),
)
],
).
But at that time I got Incorrect ParentWidget error
I tried many ways but didn't get results.
The expected result is attached below,
enter image description here
You can use Positioned widget as Stack child, you dont need to have on Column
child: Stack(
children: [
Positioned( // if needed put it here
top: 0,
right: 0,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Align( /// not here
alignment: Alignment.topRight,
child: MouseRegion(
cursor: SystemMouseCursors.click,
child: Text(
"Edit",
),
),
),
Row(
mainAxisSize: MainAxisSize.min,

How to align expanded widgets in a row

Why does the 1st two work but not the 3rd?? what's the alternative to add vertical divider with height that stretch to the max height of the row?
These 2 works
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
// crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
child: Text('Kicukiro'),
),
Container(width: 1,color: Colors.black,height: double.infinity,),
Container(
padding: EdgeInsets.symmetric(horizontal: 10),
child: Text('Kicukiro'),
)
],
)
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Container(
child: Text('Kicukiro'),
),
),
// Container(width: 1,color: Colors.black,height: double.infinity,),
Expanded(
child: Container(
padding: EdgeInsets.symmetric(horizontal: 10),
child: Text('Kicukiro'),
),
)
],
)
this does not work
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Container(
child: Text('Kicukiro'),
),
),
Container(width: 1,color: Colors.black,height: double.infinity,),
Expanded(
child: Container(
padding: EdgeInsets.symmetric(horizontal: 10),
child: Text('Kicukiro'),
),
)
],
)
Test this and it will work
IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Container(
child: const Text("Kicukiro", style: TextStyle(fontSize: 52),)),
),
Container(color:Colors.black, width: 1),
Expanded(
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 10),
child: const Text("Kicukiro", style: TextStyle(fontSize: 52),)),
),
],
),
),
In the last screenshot please add the Container under an Expanded widget. Use children property under Row widget.
Here is an example code
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Expanded(
flex: 5,
child: Padding(
padding: EdgeInsets.all(10.0),
child: Center(
child: Text(
'This is question',
style: TextStyle(
fontSize: 25.0,
color: Colors.white,
),
),
),
),
),
Expanded(
child: Padding(
padding: EdgeInsets.all(10.0),
child: FlatButton(
//textColor: Colors.white,
color: Colors.green,
child: Text(
'True',
style: TextStyle(color: Colors.white, fontSize: 20.0),
),
onPressed: () {},
),
)),
Expanded(
child: Padding(
padding: EdgeInsets.all(10.0),
child: FlatButton(
//textColor: Colors.white,
color: Colors.red,
child: Text(
'False',
style: TextStyle(color: Colors.white, fontSize: 20.0),
),
onPressed: () {},
),
)),
]
The third is true, in fact, its existence in an SingleChildScrollView has created a problem
It is fixed by putting SizedBox in Row and giving it height
The reason for this problem is the size of the height of the container, which is determined by double.infinity and due to its presence in an SingleChildScrollView, it continues indefinitely and an error was created.
SingleChildScrollView(
child: SizedBox(
height: 250,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(child: Container(child: Text("Kicukiro"))),
Container(
width: 1,color: Colors.black,height: double.infinity,
),
Expanded(child: Container(
padding: EdgeInsets.symmetric(horizontal: 10),
child: Text("Kicukiro"))),
],
),
),
),

ManAxisAlignment.spaceBetween (row) not working as it should?

I have the following code:
_buildWave() {
return Container(
height: 100.0,
width: double.infinity,
child: Container(
child: Stack(
children: [
WaveWidget(
config: CustomConfig(
colors: helpers.waveColors,
durations: [32000, 21000, 25000, 5000],
heightPercentages: [0.25, 0.26, 0.28, 0.31]),
backgroundColor: Colors.transparent,
size: Size(double.infinity, double.infinity),
waveAmplitude: 0,
),
Container(
child: Positioned(
bottom: 15,
child: Padding(
padding: EdgeInsets.fromLTRB(15, 0, 5, 0),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(LineIcons.streetView, size: 20),
SizedBox(width: 5),
Text(
"Left",
style: TextStyle(fontWeight: FontWeight.bold),
),
],
),
),
Container(
child: Row(
mainAxisSize: MainAxisSize.min,
children: [Text("Right")],
),
),
],
),
),
),
),
],
),
),
);
}
The intention is to place the LEFT and RIGHT text on yes, the left and right side. Now, I know this can be done using MainAxisAlignment.spaceBetween but for some reason it won't work. I'm getting no errors.
Image is what I'm getting right now:
Maybe that is because you have kept the Row Widget inside Stack Widget, try giving the full width to the Positioned Widget present inside the Stack Widget like below and also remove the Container Widget:
child: Stack(
children: [
WaveWidget(
config: CustomConfig(
colors: helpers.waveColors,
durations: [32000, 21000, 25000, 5000],
heightPercentages: [0.25, 0.26, 0.28, 0.31]),
backgroundColor: Colors.transparent,
size: Size(double.infinity, double.infinity),
waveAmplitude: 0,
),
Positioned(
// Here
left: 0.0,
right: 0.0,
//
bottom: 15,
child: Padding(
padding: EdgeInsets.fromLTRB(15, 0, 5, 0),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(LineIcons.streetView, size: 20),
SizedBox(width: 5),
Text(
"Left",
style: TextStyle(fontWeight: FontWeight.bold),
),
],
),
),
Container(
child: Row(
mainAxisSize: MainAxisSize.min,
children: [Text("Right")],
),
),
],
),
),
),
],

Padding not rendering between header and textfield?

I want to add space between my header and text field, as currently, they are far too close. I have tried adding padding to the row which has the text field, however, there is no movement. Any thoughts on how I could do so?
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
Image.asset(
"assets/Login_Photo.jpg",
height: MediaQuery.of(context).size.height * 0.4,
width: MediaQuery.of(context).size.width,
fit: BoxFit.cover,
),
Padding(
padding: const EdgeInsets.all(50.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Login',
style: TextStyle(
fontSize: 35,
fontFamily: 'Avenir',
fontWeight: FontWeight.w900,
),
),
Row(
padding: const EdgeInsets.all(50.0),
children: <Widget>[
Expanded(
child: TextField(
decoration:
InputDecoration(hintText: "Email Address"))),
I have edited your code, So you can wrap Row in the Container and set margin like as top, bottom ,left, right according to your UI, Please tell me if my code is useful or not.
Widget build(BuildContext context) {
return Scaffold(
body: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Image.asset(
"assets/Login_Photo.jpg",
height: MediaQuery.of(context).size.height * 0.4,
width: MediaQuery.of(context).size.width,
fit: BoxFit.cover,
),
Padding(
padding: const EdgeInsets.all(50.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Login',
style: TextStyle(
fontSize: 35,
fontFamily: 'Avenir',
fontWeight: FontWeight.w900,
),
),
Container(
margin:
EdgeInsets.only(top: 10, left: 0, right: 0, bottom: 0),
child: Row(
// padding: const EdgeInsets.all(50.0),
children: <Widget>[
Expanded(
child: TextField(
decoration:
InputDecoration(hintText: "Email Address"),
),
),
],
),
),
],
),
)
],
),
);
}
Use SizedBox widget, with the height property, you assign the distance you want to separate. For Exmaple:
SizedBox(height: 10)//change this value for which you need.
Full code, look like this:
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
Image.asset(
"assets/Login_Photo.jpg",
height: MediaQuery.of(context).size.height * 0.4,
width: MediaQuery.of(context).size.width,
fit: BoxFit.cover,
),
Padding(
padding: const EdgeInsets.all(50.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Login',
style: TextStyle(
fontSize: 35,
fontFamily: 'Avenir',
fontWeight: FontWeight.w900,
),
),
Sizedbox(height: 10),
Row(
padding: const EdgeInsets.all(50.0),
children: <Widget>[
Expanded(
child: TextField(
decoration:
InputDecoration(hintText: "Email Address"))),
How strange that it doesn't work for you, maybe one of these alternatives works for you:
Container and give some height:
Column(
children: <Widget>[
Widget1(),
Container(height: 10), // set height
Widget2(),
],
)
Spacer
Column(
children: <Widget>[
Widget1(),
Spacer(), // use Spacer
Widget2(),
],
)
Expanded
Column(
children: <Widget>[
Widget1(),
Expanded(child: SizedBox()), // use Expanded
Widget2(),
],
)
mainAxisAlignment
Column(
mainAxisAlignment: MainAxisAlignment.spaceAround, // mainAxisAlignment
children: <Widget>[
Widget1(),
Widget2(),
],
)
Wrap
Wrap(
direction: Axis.vertical, // make sure to set this
spacing: 20, // set your spacing
children: <Widget>[
Widget1(),
Widget2(),
],
)
Space between Column's children in Flutter