How to design a user center ui like this using dart - dart

I'm familiar with Column and Row.
But the complex UI in my image example, I don't know how to begin, ignoring the Chinese words.

Will this work?
double _appBarHeight = 120, _imageHeight = 80, _iconTopMargin = 44, _iconLeftMargin = 12, _leftMargin = 120;
#override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: <Widget>[
Positioned(
left: 0,
right: 0,
height: _appBarHeight,
child: Container(color: Colors.blue),
),
Positioned(
left: _iconLeftMargin,
top: _iconTopMargin,
child: Icon(Icons.settings, color: Colors.white),
),
Positioned(
right: _iconLeftMargin,
top: _iconTopMargin,
child: Icon(Icons.bubble_chart, color: Colors.white),
),
Positioned(
left: _iconLeftMargin,
top: _appBarHeight - _imageHeight / 2,
child: ClipOval(child: Image.asset("assets/images/profile.jpg", fit: BoxFit.cover, height: _imageHeight, width: _imageHeight)),
),
Positioned(
left: _leftMargin,
top: _appBarHeight - (_imageHeight / 2),
child: Text("CopsOnRoad", style: TextStyle(color: Colors.white, fontWeight: FontWeight.w500, fontSize: 18)),
),
Positioned.fill(
left: _leftMargin,
top: _appBarHeight + (_imageHeight / 4),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Column(
children: <Widget>[
Text("2", style: TextStyle(fontWeight: FontWeight.bold)),
Text("Gold", style: TextStyle(color: Colors.grey)),
],
),
Column(
children: <Widget>[
Text("22", style: TextStyle(fontWeight: FontWeight.bold)),
Text("Silver", style: TextStyle(color: Colors.grey)),
],
),
Column(
children: <Widget>[
Text("28", style: TextStyle(fontWeight: FontWeight.bold)),
Text("Bronze", style: TextStyle(color: Colors.grey)),
],
),
Container(),
],
),
),
Positioned(
left: 0,
top: _appBarHeight + _imageHeight / 1.1,
right: 0,
height: 1,
child: Container(color: Colors.grey),
),
Positioned(
top: _appBarHeight + _imageHeight * 1.1,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Text("Reputation", style: TextStyle(color: Colors.grey)),
),
),
Positioned.fill(
left: _leftMargin,
top: _appBarHeight + _imageHeight * 1.1,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text("This", style: TextStyle(fontWeight: FontWeight.bold)),
SizedBox(width: 10),
Container(width: 1, color: Colors.grey.withOpacity(0.4), height: 16),
SizedBox(width: 10),
Text("is", style: TextStyle(fontWeight: FontWeight.bold)),
SizedBox(width: 10),
Container(width: 1, color: Colors.grey.withOpacity(0.4), height: 16),
SizedBox(width: 10),
Text("5509", style: TextStyle(fontWeight: FontWeight.bold)),
SizedBox(width: 10),
Spacer(),
Icon(Icons.keyboard_arrow_right, color: Colors.grey)
],
),
),
],
),
);
}

You can use the Stack widget and a Positioned element to help you position the avatar in the right place.
A quick video on the Positioned and Stack: https://www.youtube.com/watch?v=EgtPleVwxBQ

Related

How to fix cropped shadow in a Horizontal List View in Flutter

When I create a Container with box shadow inside a ListView (scrolls Horizontally), the shadow looks fine, but, when I add multiple Containers inside the ListView, their shadows(just shadows, not Container) gets cropped at top and bottom.
Please also note that this whole ListView is wrapped under a parent Container.
I tried to increase the height of Parent Container(in which the whole ListView is wrapped), but it increases the height of child Container with its shadow still cropped.
I also tried to give padding to Parent Container but, it still shadow still gets cropped.
Maybe I need to wrap the ListView inside any other Widget which can get the job done without the problem.
Container(
// padding: EdgeInsets.only(left: 30.0, right: 0.0),
height: 140.0,
child: ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
SizedBox(
width: 30.0,
),
Container(
//This is actual custom Card
width: 340.0,
height: 140.0,
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.black12,
offset: Offset.zero,
blurRadius: 10.0,
spreadRadius: 0.0,
)
],
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
),
child: Row(
children: <Widget>[
Container(
padding: EdgeInsets.fromLTRB(
30.0, 20.0, 25.0, 20.0),
child: Image.asset(
'assets/images/leather_boot.png'),
),
Container(
padding:
EdgeInsets.only(top: 30.0, bottom: 30.0),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Text(
'BadAss Genuine',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w500,
fontSize: 18.0,
),
),
SizedBox(
height: 3.0,
),
Text(
'Leather Boots',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w500,
fontSize: 18.0,
),
),
SizedBox(
height: 12.0,
),
Container(
height: 1.5,
width: 150.0,
color: Color(0xff643523),
),
],
),
),
],
),
),
SizedBox(
width: 30.0,
),
Container(
//This is actual custom Card
width: 340.0,
height: 140.0,
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.black12,
offset: Offset.zero,
blurRadius: 10.0,
spreadRadius: 0.0,
)
],
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
),
child: Row(
children: <Widget>[
Container(
padding: EdgeInsets.fromLTRB(
30.0, 20.0, 25.0, 20.0),
child: Image.asset(
'assets/images/leather_boot.png'),
),
Container(
padding:
EdgeInsets.only(top: 30.0, bottom: 30.0),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Text(
'BadAss Genuine',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w500,
fontSize: 18.0,
),
),
SizedBox(
height: 3.0,
),
Text(
'Leather Boots',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w500,
fontSize: 18.0,
),
),
SizedBox(
height: 12.0,
),
Container(
height: 1.5,
width: 150.0,
color: Color(0xff643523),
),
],
),
),
],
),
),
SizedBox(
width: 30.0,
),
],
),
),
I expect the ListView to have Containers(as custom Cards) to have proper BoxShadow, but in the actual output, Containers' BoxShadow gets cropped from both Top & Bottom.
As #Zahra wrote,
adding clipBehavior: Clip.none, to the ListView, solved the problem.
The crop happens only when your widgets exceed the screen size
Okay I found the solution myself.
Steps to fix the problem
Create several Container(as a card) with some width and with a BoxShadow of Radius 10.0. Lets call it Child Container.
Create a ListView with Horizontal scroll axis. Put Child Containers made above in this ListView.
Now wrap the ListView inside a new Container(Lets call it Parent Container) to give ListView a height. If you want your Child Containers to be of height 140.0, then make your Parent Container's height 160.0, which includes radius of BoxShadow of 10.0 on top & bottom each(10.0+ 140.0 + 10.0).
Now give padding to your ListView of 10.0 on both top & bottom.
Problem Solved (Silly Me).
Sample Code here
Container(
height: 160.0,
child: ListView(
padding: EdgeInsets.only(top: 10.0, bottom: 10.0),
shrinkWrap: true,
scrollDirection: Axis.horizontal,
children: <Widget>[
SizedBox(
width: 30.0,
),
Container(
width: 340.0,
// height: 140.0,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
boxShadow: [
BoxShadow(
blurRadius: 10.0,
color: Colors.black12,
)
],
),
child: Row(
children: <Widget>[
Container(
padding: EdgeInsets.fromLTRB(
30.0, 20.0, 25.0, 20.0),
child: Image.asset(
'assets/images/leather_boot.png'),
),
Container(
padding:
EdgeInsets.only(top: 20.0, bottom: 20.0),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Text(
'BadAss Genuine',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w400,
fontSize: 18.0,
),
),
SizedBox(
height: 3.0,
),
Text(
'Leather Boots',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w400,
fontSize: 18.0,
),
),
SizedBox(
height: 12.0,
),
Container(
height: 1.0,
width: 150.0,
color: Color(0xff643523),
),
SizedBox(
height: 12.0,
),
Row(
children: <Widget>[
SizedBox(
width: 110.0,
),
Container(
height: 30.0,
width: 30.0,
child: Image.asset(
'assets/images/boot.png'),
),
],
),
],
),
),
],
),
),
SizedBox(
width: 30.0,
),
Container(
//This is actual custom Card
width: 340.0,
// height: 140.0,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
boxShadow: [
BoxShadow(
blurRadius: 10.0,
color: Colors.black12,
)
],
),
child: Row(
children: <Widget>[
Container(
padding: EdgeInsets.fromLTRB(
30.0, 20.0, 25.0, 20.0),
child:
Image.asset('assets/images/gloves.png'),
),
Container(
padding:
EdgeInsets.only(top: 20.0, bottom: 20.0),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Text(
'Highly Durable',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w400,
fontSize: 18.0,
),
),
SizedBox(
height: 3.0,
),
Text(
'Riding Gloves',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w400,
fontSize: 18.0,
),
),
SizedBox(
height: 12.0,
),
Container(
height: 1.0,
width: 150.0,
color: Color(0xff643523),
),
SizedBox(
height: 12.0,
),
Row(
children: <Widget>[
SizedBox(
width: 110.0,
),
Container(
height: 30.0,
width: 30.0,
child: Image.asset(
'assets/images/glove.png'),
),
],
),
],
),
),
],
),
),
SizedBox(
width: 30.0,
),
Container(
//This is actual custom Card
width: 340.0,
// height: 140.0,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
boxShadow: [
BoxShadow(
blurRadius: 10.0,
color: Colors.black12,
)
],
),
child: Row(
children: <Widget>[
Container(
padding: EdgeInsets.fromLTRB(
30.0, 20.0, 25.0, 20.0),
child:
Image.asset('assets/images/helmet.png'),
),
Container(
padding:
EdgeInsets.only(top: 20.0, bottom: 20.0),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Text(
'German Hat',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w400,
fontSize: 18.0,
),
),
SizedBox(
height: 3.0,
),
Text(
'Riding Helmet',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w400,
fontSize: 18.0,
),
),
SizedBox(
height: 12.0,
),
Container(
height: 1.0,
width: 150.0,
color: Color(0xff643523),
),
SizedBox(
height: 12.0,
),
Row(
children: <Widget>[
SizedBox(
width: 110.0,
),
Container(
height: 30.0,
width: 30.0,
child: Image.asset(
'assets/images/helmeticon.png'),
),
],
),
],
),
),
],
),
),
SizedBox(
width: 30.0,
),
],
),
),

How to position elements inside a ListView?

Good morning. I made this screen and it works like a charm on high resolutions. Problem is, I want to support lower resolutions like Nexus 4 (768x1280).
So when I run this on an emulator (Nexus 4 size) and I touch the input fields, the keyboard either: blocks the inputs, or moves the two buttons at the bottom and overlaps them on something else.
So, to solve it I wrapped the entire layout on a ListView(), but now the bottom buttons, which are wrapped on a Row(), just won't stay at the bottom.
This is my code without the ListView and working on high res, but not on low:
return Form(
Stack(
Center(
Column(
...
),
),
Align(
alignment: Alignment.bottomCenter,
child: Row(
...
),
),
),
);
This is how it looks with resizeToAvoidBottomPadding: false
And this is how it looks with the value set to true
Thanks, everyone.
Did you try to use SingleChildScrollView ?
It is a widget for making the page able to resize the height and as well scrolling , for the listview thats not what is the listview for , you should add listview when you get an unknown amount of data,
We don't normally use it to just adjust the view.
ok so i edited the code as in here and i can scroll normally after the keyboard pop up and the view is good and i can click on the button normally try it.
Widget formWidget(){
return new Scaffold(
// appBar: AppBar(
// // Here we take the value from the MyHomePage object that was created by
// // the App.build method, and use it to set our appbar title.
// title: Text(widget.title),
// ),
body:Column(
children: <Widget> [
Expanded(
child:SingleChildScrollView(
child: Form(
child:
// Stack(
// children: <Widget>[
// Center(
// child: SingleChildScrollView(
// child:
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: [
Padding(
padding: (MediaQuery.of(context).size.height) > 600
? const EdgeInsets.only(top: 0.0)
: const EdgeInsets.only(top: 30.0),
child: Image(
image: AssetImage('assets/favIcon.png'),
width: 88.0,
height: 88.0,
),
),
Padding(
padding: const EdgeInsets.fromLTRB(0, 28.0, 0, 12.0),
child: Text(
'Delegados',
style: TextStyle(
fontFamily: 'Archia',
fontSize: 32.0,
),
),
),
Text(
'Introduce tus datos de acceso aquí.',
style: TextStyle(
color: Color(0xff83868F),
fontFamily: 'Brutal',
fontSize: 14.0,
),
),
Padding(
padding:
const EdgeInsets.fromLTRB(16.0, 26.0, 16.0, 12.0),
child: TextFormField(
decoration: InputDecoration(
labelText: 'Correo',
filled: true,
fillColor: Color(0xffF0F1F5),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: BorderSide(
width: 0,
style: BorderStyle.none,
),
),
),
style: TextStyle(
fontFamily: 'Brutal',
color: Color(0xff1A1B1F),
),
controller: TextEditingController() ,
textInputAction: TextInputAction.next,
),
),
Padding(
padding: const EdgeInsets.fromLTRB(16.0, 0, 16.0, 12.0),
child: TextFormField(
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
labelText: 'Contraseña',
filled: true,
fillColor: Color(0xffF0F1F5),
suffixIcon: Icon(Icons.remove_red_eye),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: BorderSide(
width: 0,
style: BorderStyle.none,
),
),
),
style: TextStyle(
fontFamily: 'Brutal',
color: Color(0xff1A1B1F),
),
controller: TextEditingController() ,
//focusNode:FocusNode(),
obscureText: true,
),
),
Align(
alignment: Alignment.centerRight,
child: Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 0, 26.0),
child: CupertinoButton(
onPressed: () {},
child: Text(
'Olvidé mi Contraseña',
style: TextStyle(
color: Color(0xff565A66),
fontFamily: 'Brutal',
fontSize: 14.0,
),
),
),
),
),
Padding(
padding: const EdgeInsets.fromLTRB(16.0, 0, 16.0, 0),
child: ButtonTheme(
minWidth: double.infinity,
child: InkWell(
// onTap: state is! LoginLoading
// ? _onLoginButtonPressed
// : null,
child: Container(
height: 48.0,
width: 500.0,
decoration: BoxDecoration(
color: Color(0xff00CC36),
borderRadius: BorderRadius.circular(8.0),
),
child: Align(
alignment: Alignment.center,
child: Container(
child:
// state is LoginLoading
// ? CircularProgressIndicator():
Text(
'INGRESAR AHORA ›',
style: TextStyle(
color: Colors.white,
fontFamily: 'Brutal',
fontSize: 14.0,
),
),
)),
),
),
),
),
],
),
// ),
)
,
// aqui va <<<<<<<<<<<<
// ],
// ),
)
),
Align(
alignment: Alignment.bottomCenter,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
CupertinoButton(
onPressed: () {},
child: Text(
'¿No tienes cuenta?',
style: TextStyle(
color: Color(0xff83868F),
fontFamily: 'Brutal',
fontSize: 14.0,
),
),
),
InkWell(
onTap: null,
child: Container(
height: 32.0,
width: 112.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(6.0),
border: Border.all(
color: Color(0xffD7D9E0),
width: 1.0,
),
),
child: Align(
alignment: Alignment.center,
child: Text(
'CONTACTANOS',
style: TextStyle(
color: Color(0xff565A66),
fontFamily: 'Brutal',
fontSize: 11.0),
),
),
),
),
],
),
),
]
)
,
// )
);
}
In your Scaffold can you try this.
Scaffold(
resizeToAvoidBottomInset: false,
...
);
I position two elements in the center and bottom of the screen by this code.
body: Column(
children: [
Expanded(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
height: 80,
width: 80,
child:
Image(image: AssetImage("assets/images/logo.png"))),
SizedBox(height: 10),
Text(
"Tings App",
style: TextStyle(fontSize: 36),
),
SizedBox(height: 10),
TextFormField(
controller: _emailController,
decoration: InputDecoration(
border: OutlineInputBorder(),
isDense: true,
labelText: 'Email/phone'),
validator: (value) {
if (value.isEmpty) {
return 'Please enter a valid email';
}
return null;
},
),
],
),
),
),
Align(
alignment: Alignment.bottomCenter,
child: Container(
padding: EdgeInsets.all(20),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
_isLoading
? CircularProgressIndicator()
: SizedBox(
width: MediaQuery.of(context).size.width * 0.7,
height: 60.0,
child: ElevatedButton(
style: ButtonStyle(
shape: MaterialStateProperty.all<
RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(100.0),
),
),
),
child: Text(
"SignIn",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w800,
fontSize: 18),
),
onPressed: () {
_login(context);
},
),
),
SizedBox(height: 16),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Don't have account?",
style: TextStyle(fontSize: 16),
),
SizedBox(width: 6),
TextButton(
onPressed: () {
Navigator.push(
context, SlideRightRoute(page: Signup()));
},
child: Text("SignUp"),
),
],
)
],
),
),
)
],
),

How to make a Container stretch to occupy same height as row?

I want to achieve something like below
What I am able to achieve
Here is my code
return Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(10))),
child: Row(
children: <Widget>[
Container(
color: Colors.orange,
width: 4,
),
Expanded(
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Icon(Icons.alarm),
SizedBox(
width: 2,
),
Text(
"Starts",
style:
TextStyle(fontFamily: "BarlowMedium", fontSize: 12),
),
SizedBox(
width: 4,
),
Text(
studentClassesData.classStarttime,
style: TextStyle(fontFamily: "BarlowBold", fontSize: 12),
),
SizedBox(
width: 4,
),
Text(
"to",
style:
TextStyle(fontFamily: "BarlowMedium", fontSize: 12),
),
SizedBox(
width: 4,
),
Text(
studentClassesData.classEndtime,
style: TextStyle(fontFamily: "BarlowBold", fontSize: 12),
)
],
),
SizedBox(
height: 4,
),
Align(
alignment: Alignment.centerLeft,
child: Text(
studentClassesData.subject,
style: TextStyle(
fontFamily: "BarlowBold", fontSize: 12, color: blue),
),
),
SizedBox(
height: 4,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
CircleAvatar(
backgroundImage:
NetworkImage(studentClassesData.facultyImage),
child: Image.asset("images/round_only.webp"),
),
SizedBox(width: 5,),
Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Align(
alignment: Alignment.centerLeft,
child: Text(
"Faculty",
style: TextStyle(fontFamily: "KohinoorDemi"),
),
),
SizedBox(
height: 3,
),
Text(
studentClassesData.faculty,
style: TextStyle(fontFamily: "BarlowBold"),
),
],
)
],
),
SizedBox(
height: 4,
),
Row(
children: <Widget>[
Icon(Icons.business),
Column(
children: <Widget>[
Text(
"Floor/Room",
style: TextStyle(fontFamily: "KohinoorDemi"),
),
SizedBox(
height: 3,
),
Text(
"${studentClassesData.floor}/${studentClassesData.room}",
style: TextStyle(fontFamily: "BarlowBold"),
),
],
)
],
),
],
),
)
],
));
I am not able to achieve the view which has a yellowish colour at the start to occupy same height as the Row. As you can see in the above code I have used a Container and I know I can give a height to the container but I don't want to give a fixed height to the container as the height may change depending on data coming from the api..
You need to use - IntrinsicHeight to get what you want.
working Code(with Dummy Values):
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(10))),
clipBehavior: Clip.antiAlias,
child: IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Container(
color: Colors.orange,
width: 4,
),
SizedBox(width: 5.0,),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
children: <Widget>[
Icon(Icons.alarm),
SizedBox(
width: 2,
),
Text(
"Starts",
style: TextStyle(
fontFamily: "BarlowMedium", fontSize: 12),
),
SizedBox(
width: 4,
),
Text(
'11:30 AM',
style:
TextStyle(fontFamily: "BarlowBold", fontSize: 12),
),
SizedBox(
width: 4,
),
Text(
"to",
style: TextStyle(
fontFamily: "BarlowMedium", fontSize: 12),
),
SizedBox(
width: 4,
),
Text(
'1:30 PM',
style:
TextStyle(fontFamily: "BarlowBold", fontSize: 12),
)
],
),
SizedBox(
height: 4,
),
Align(
alignment: Alignment.centerLeft,
child: Text(
'Design Studio 6 (Capstone)',
style: TextStyle(
fontFamily: "BarlowBold",
fontSize: 12,
color: Colors.blue),
),
),
SizedBox(
height: 4,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
CircleAvatar(
backgroundImage:
NetworkImage('https://placeimg.com/640/480/any'),
child: Image.asset("images/round_only.webp"),
),
SizedBox(
width: 5,
),
Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Align(
alignment: Alignment.centerLeft,
child: Text(
"Faculty",
style: TextStyle(fontFamily: "KohinoorDemi"),
),
),
SizedBox(
height: 3,
),
Text(
'Meenal',
style: TextStyle(fontFamily: "BarlowBold"),
),
],
)
],
),
SizedBox(
height: 4,
),
Row(
children: <Widget>[
Icon(Icons.business),
Text(
"Floor/Room",
style: TextStyle(fontFamily: "KohinoorDemi"),
),
SizedBox(
height: 3,
),
Text(
"6th Floor: North Wing / ISDI 606",
style: TextStyle(fontFamily: "BarlowBold"),
)
],
),
],
)
],
),
)),
Output:
I don't have fonts you have used, so UI looks different than yours. But it get the job Done.
You can do it by wrapping your Card in a SizedBox giving it a height you want. In this case, you don't need to hard code any height to your Container, the Container will just expand to match the height of your Row. Here is simple example:
SizedBox(
height: 100,
child: Card(
color: Colors.green,
child: Row(
children: <Widget>[
Container(
color: Colors.blue,
width: 100, // no need to set any height, it will automatically fill to match row
)
],
),
),
);

Row RenderFlex overflowed by 76 pixels on the right

Below are my code I always got some pixel overflowed on right size. I was playing with Expanded and Fixable widgets as well as mainAxisSize of row and column too.
Look at the code:
Widget productDisplayListView(List<Products> listOfProduct, int index) {
return Container(
margin: EdgeInsets.all(7),
child: Container(
child: Card(
elevation: 4,
child: Container(
padding: EdgeInsets.all(6),
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
height: 110,
width: 90,
child: Image.network(
listOfProduct[index].thumbnail ?? '',
fit: BoxFit.cover,
),
),
Container(
padding: EdgeInsets.all(5),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
padding: EdgeInsets.zero,
margin: EdgeInsets.zero,
height: 20,
width: 20,
child: Icon(
Icons.crop_square,
color: Colors.red,
size: 18,
),
),
Flexible(
child: Text(
'The overflowing RenderFlex has an orientation of Axis.horizontal.',
overflow: TextOverflow.ellipsis,
softWrap: true,
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
color: Theme.of(context).primaryColor),
),
)
],
),
SizedBox(height: 5),
Text(
'The overflowing RenderFlex has an orientation of Axis.horizontal.',
maxLines: 1,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w500,
color: Colors.grey),
),
SizedBox(height: 5),
Text(
'₹${listOfProduct[index].price ?? ''}',
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w700,
color: Colors.black),
)
],
),
)
],
),
),
),
),
);
}
I tried with many Que./Ans. on stackOverFlow but But didn't get success.
Updated Code with Fixed Overflow Error. Have to made quite a change in your Widget Tree.
Widget productDisplayListView() {
return Card(
elevation: 4,
child: Container(
padding: EdgeInsets.all(6),
child: Row(
children: <Widget>[
Container(
height: 110,
width: 90,
child: Image.network(
'https://placeimg.com/250/250/any',
fit: BoxFit.cover,
),
),
SizedBox(
width: 5.0,
),
Flexible(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
MergeSemantics(
child: Row(
children: <Widget>[
Icon(
Icons.crop_square,
color: Colors.red,
size: 18,
),
Flexible(
child: Text(
'The overflowing RenderFlex has an orientation of Axis.horizontal.',
overflow: TextOverflow.ellipsis,
softWrap: true,
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
color: Theme.of(context).primaryColor),
),
)
],
),
),
SizedBox(height: 5),
Text(
'The overflowing RenderFlex has an orientation of Axis.horizontal.',
maxLines: 1,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w500,
color: Colors.grey),
),
SizedBox(height: 5),
Text(
'₹ 10,000',
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w700,
color: Colors.black),
)
],
),
)
],
),
),
);
}
OutPut:
Check Your Rows Add Column Widgets. If any row or column widget has a single flexible child an error will occur
Doing like this should fix your problem:-
..... Container(
padding: EdgeInsets.all(5),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Flexible(
child: Container(
padding: EdgeInsets.zero,
margin: EdgeInsets.zero,
height: 20,
width: 20,
child: Icon(
Icons.crop_square,
color: Colors.red,
size: 18,
),
),
),
Flexible(
child: Text(
'The overflowing RenderFlex has an orientation of Axis.horizontal.',
overflow: TextOverflow.ellipsis,
softWrap: true,
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
color: Theme.of(context).primaryColor),
),
)
],
),
SizedBox(height: 5),
Flexible(
child: Text(
'The overflowing RenderFlex has an orientation of Axis.horizontal.',
maxLines: 1,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w500,
color: Colors.grey),
),
),
SizedBox(height: 5),
Text(
'₹${listOfProduct[index].price ?? ''}',
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w700,
color: Colors.black),
)
],

Incorrect use of Parent Widget?

This is the body of the Scaffold, I dont really understand Why Iam getting this error? I have added constrains on the height and the width. Still not getting the error. And the sequence of the body seems logic to me ?
body:Center(child:SingleChildScrollView
(child: Column(
children:_list1
.map((element)=>
Container(
margin: EdgeInsets.all(9.0),
constraints: new BoxConstraints.expand(height: 300.0),
decoration: new BoxDecoration(
border: new Border.all(color: Colors.blueAccent),
borderRadius: BorderRadius.horizontal( left:Radius.circular(30.0) ,right:Radius.circular(30.0) ),
image: new DecorationImage(
image: new AssetImage('assets/food1.jpg'),
fit: BoxFit.cover,),),
padding: EdgeInsets.only(bottom: 20.0),
child: Stack(
children:<Widget>[
Positioned(left: 0.0,bottom: 30.0,child: Text(element.name, style: new TextStyle(fontWeight: FontWeight.bold,fontSize: 20.0,)),),
Positioned(left: 0.0,bottom: 0.0,child: Text(element.dis,style: new TextStyle(fontWeight: FontWeight.bold,fontSize: 20.0,)),),
Positioned(right: 0.0,top:0.0,child:Icon(Icons.star)),
Positioned(right: 200.0,top:0.0,child:Icon(Icons.check)),
]
),
),
).toList()
)
) )
);
You can use ListView instead of Center, SingleChildScrollView and Column.
body: ListView(
children: _list1
.map(
(element) => Container(
margin: EdgeInsets.all(9.0),
constraints: new BoxConstraints.expand(height: 300.0),
decoration: new BoxDecoration(
border: new Border.all(color: Colors.blueAccent),
borderRadius: BorderRadius.horizontal(
left: Radius.circular(30.0),
right: Radius.circular(30.0),
),
image: new DecorationImage(
image: new NetworkImage(
'https://images.pexels.com/photos/5317/food-salad-restaurant-person.jpg?auto=compress&cs=tinysrgb&h=350'),
fit: BoxFit.cover,
),
),
padding: EdgeInsets.only(bottom: 20.0),
child: Stack(
children: <Widget>[
Positioned(
left: 0.0,
bottom: 30.0,
child: Text(
element.name,
style: new TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20.0,
),
),
),
Positioned(
left: 0.0,
bottom: 0.0,
child: Text(
element.dis,
style: new TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20.0,
),
),
),
Positioned(
right: 0.0,
top: 0.0,
child: Icon(Icons.star),
),
Positioned(
right: 200.0,
top: 0.0,
child: Icon(Icons.check),
),
],
),
),
)
.toList(),
),
In your code Center seemed useless though.

Resources