Related
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
I want to show these two buttons click the middle button in the bottom navigation. Already I created the bottom dialog box but it's not working. on click of image button. please help me!
void _bottomSheet() {
Container(
height: 500,
width: double.infinity,
color: Colors.white,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.end,
children: [
Row(
children: [
Flexible(
flex: 1,
child: Align(
alignment: Alignment.centerRight,
child: FloatingActionButton(
onPressed: () {
// Add your onPressed code here!
},
backgroundColor: Colors.black,
child: const Icon(
MyBottomIcon.barcode,
),
),
),
),
SizedBox(
width: 20,
),
Flexible(
flex: 1,
child: Align(
alignment: Alignment.centerLeft,
child: FloatingActionButton(
onPressed: () {
// Add your onPressed code here!
},
backgroundColor: Colors.black,
child: const Icon(
MyBottomIcon.barcode,
),
),
),
),
],
),
],
),
);
}
Please review my code and correct me when I call this method showing nothing on the screen.
My suggestion is by using floatingActionButton
floatingActionButton: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
padding: const EdgeInsets.all(5),
width: 80.0,
height: 80.0,
child: FloatingActionButton(
onPressed: () => showAlertDialog(context), // Call the function from example below
elevation: 7.0,
child: const Icon(
Icons.add,
size: 50,
),
),
),
],
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
Create the showAlertDialog(context) function and suit the Widget as your needs.
showAlertDialog(BuildContext context) {
showDialog(
context: context,
builder: (BuildContext context) {
return Center(
child: Container(
padding: const EdgeInsets.only(top: 380.0),
child: Stack(
clipBehavior: Clip.none,
alignment: Alignment.center,
children: <Widget>[
Container(
width: double.infinity,
height: 800,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: Colors.transparent),
padding: const EdgeInsets.fromLTRB(20, 50, 20, 20),
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
height: 100,
padding: const EdgeInsets.all(5.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.only(right: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ClipOval(
child: Container(
color: Colors.yellow,
height: 70.0,
width: 70.0,
child: const Center(
child: SizedBox(
height: 30,
width: 30,
child: Icon(Icons.phone),
),
),
),
),
],
),
),
Padding(
padding: const EdgeInsets.only(left: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ClipOval(
child: Container(
color: Colors.red,
height: 70.0,
width: 70.0,
child: const Center(
child: SizedBox(
height: 30,
width: 30,
child: Icon(Icons.computer),
),
),
),
),
],
),
),
],
),
),
],
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
padding: const EdgeInsets.all(5),
width: 80.0,
height: 80.0,
child: FloatingActionButton(
onPressed: () => {Navigator.pop(context)},
elevation: 7.0,
child: const Icon(
Icons.close,
size: 50,
),
),
),
],
),
],
),
),
);
},
);
}
What I want:
image
child: IntrinsicWidth(
child: Column(
children: [
Stack(
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: const [
Red(),
Green(),
],
),
const Align(
child: Yellow(),
),
],
),
const Blue(),
const PurpleWrap(),
],
),
),
What I got:
image
How can I achieve what I want?
Also can I achieve it without using IntrinsicWidth/Stack?
their is problem in the Blue(), inside the blue, you should just make the width: double.infinity; and what else problem you got ?
try this
SizedBox(
// your blue size
width: 300,
child: Column(mainAxisAlignment: MainAxisAlignment.start, children: [
Row(children: [
Container(
height: 100,
alignment: Alignment.center,
color: Colors.pink,
child: Text("Flexible 22222")),
Expanded(
child: Container(
color: Colors.yellow,
height: 100,
),
),
Container(
height: 100,
alignment: Alignment.center,
color: Colors.amber,
child: const Text("Horizontally center")),
Expanded(
child: Container(
color: Colors.yellow,
height: 100,
),
),
Container(
height: 100, color: Colors.green, child: Text("Flexible")),
]),
Container(
height: 200,
width: double.infinity,
color: Colors.blue,
alignment: Alignment.center,
child: Text("Fixed Size")),
Container(
color: Colors.grey,
height: 50,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [Text("Wrap 1")])),
Container(
color: Colors.grey,
margin: EdgeInsets.only(top: 8),
height: 50,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [Text("Wrap 2")])),
]),
)
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")],
),
),
],
),
),
),
],
This is what I have:
source code:
Container(
width: 150,
height: 150,
color: Colors.grey,
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
height: 100,
width: 100,
color: Colors.green,
),
Row(
mainAxisSize: MainAxisSize.min,
children: [
Container(
child: Text('text'),
color: Colors.blue,
),
Container(
child: Text('text'),
color: Colors.red,
),
],
),
],
),
),
),
How can I make the blue and red container to match the green container's width without making them larger as the green container?
this is what I want to get without using a fixed with for the containers inside the row. Also I have more than one element in the column and I don't want to use fixed sizes.
If the size if fixed then you can add a width to the container which are wrap with the row widget.
The reason i gave width 50 is beacause the parent container is having width of 100 already so remaning width are given to containers
Container(
width: 150,
height: 150,
color: Colors.grey,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
height: 100,
width: 100,
color: Colors.green,
),
Row(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 50,
child: Text('text'),
color: Colors.blue,
),
Container(
width: 50,
child: Text('text'),
color: Colors.red,
),
],
),
],
),
),
You can use flexible widget to give row fixible width
Container(
width: 150,
height: 150,
color: Colors.grey,
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
height: 100,
width: 100,
color: Colors.green,
),
Container(
width: 100,
child: Row(
children: [
Flexible(
flex: 1,
fit: FlexFit.tight,
child: Container(
child: Text('text'),
color: Colors.blue,
),
),
Flexible(
flex: 1,
fit: FlexFit.tight,
child: Container(
child: Text('text'),
color: Colors.red,
),
),
],
),
),
],
),
),
)
Container(
width: 150,
height: 150,
color: Colors.grey,
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
height: 100,
width: 100,
color: Colors.green,
),
Container(
width: 100,
Row(
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
child:
Container(
child: Text('text'),
color: Colors.blue,
),
),
Expanded(
child:
Container(
child: Text('text'),
color: Colors.red,
),
),
],
),
),
],
),
),
),
You can wrap only children of Row with Expanded widget.
Try this, you have to add Exapnded to the childeren of row widgets
Container(
padding: EdgeInsets.all(16),
color: Colors.grey,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
color: Colors.green,
child: Text('Hdddfhlsd', style: primaryTextStyle()),
),
Row(
mainAxisSize: MainAxisSize.max,
children: [
Expanded(
child: Container(
child: Text('text'),
color: Colors.blue,
),
),
Expanded(
child: Container(
child: Text('text'),
color: Colors.red,
),
),
],
)
],
),
)
**Replace your container by this **
Container(
width: 150,
height: 150,
color: Colors.grey,
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 100,
child: Column(
children: [
Container(
height: 100,
width: 100,
color: Colors.green,
),
Row(
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
child: Container(
child: Text('text'),
color: Colors.blue,
),
),
Expanded(
child: Container(
child: Text('text'),
color: Colors.red,
),
),
],
)
],
),
),
],
),
),
)