how to reduce container height flutter - flutter

how to reduce the height of the green container. when I change flex values it throws bottom overflow under the green container, when I click the email field. appreciate your help on this.
I want more space to form sections and decrease the height of green space. ..........................................................
return GestureDetector(
onTap: () => FocusManager.instance.primaryFocus?.unfocus(),
child: Scaffold(
body: Column(
children: [
Expanded(
flex: 2,
child: Container(
color: MainGreen,
child: Column(children: [
Align(
alignment: Alignment.topLeft,
child: Padding(
padding: const EdgeInsets.only(top: 8),
child: Container(
child: IconButton(
onPressed: () {
Navigator.pop(context);
},
icon: Icon(
Icons.arrow_left_sharp,
color: backgroundWhite,
size: width * 0.1,
),
),
),
),
),
Center(
child: ClipRect(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.crib_rounded,
color: textWhite,
size: width * 0.18,
),
],
),
),
),
SizedBox(
height: height * 0.001,
),
Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Fantom Carpentry",
style: TextStyle(
fontSize: width * 0.06,
color: textWhite,
fontWeight: FontWeight.bold,
fontFamily: "Roboto"),
),
],
),
),
SizedBox(
height: height * 0.08,
),
Center(
child: Text(
"Login",
style: TextStyle(
fontSize: 25,
color: textWhite,
fontWeight: FontWeight.bold,
fontFamily: "Roboto"),
),
)
]),
),
),
const Expanded(
flex: 2,
child: Center(
child: Padding(
padding: EdgeInsets.only(left: 25, right: 25),
child: LoginForm(),
))),
],
),
),
);
}
}

Try below code and remove 1st Expanded widget
Scaffold(
body: Column(
children: [
Container(
color: Colors.green,
child: Column(
children: [
Align(
alignment: Alignment.topLeft,
child: Padding(
padding: const EdgeInsets.only(top: 5),
child: Container(
child: IconButton(
onPressed: () {
Navigator.pop(context);
},
icon: Icon(
Icons.arrow_left_sharp,
color: Colors.white,
size: width * 0.1,
),
),
),
),
),
Center(
child: ClipRect(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.crib_rounded,
color: Colors.white,
size: width * 0.18,
),
],
),
),
),
SizedBox(
height: height * 0.001,
),
Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Fantom Carpentry",
style: TextStyle(
fontSize: width * 0.06,
color: Colors.white,
fontWeight: FontWeight.bold,
fontFamily: "Roboto"),
),
],
),
),
SizedBox(
height: height * 0.05,
),
Center(
child: Text(
"Login",
style: TextStyle(
fontSize: 25,
color: Colors.white,
fontWeight: FontWeight.bold,
fontFamily: "Roboto",
),
),
), SizedBox(
height: height * 0.02,
),
],
),
),
Expanded(
flex: 2,
child: Center(
child: Padding(
padding: EdgeInsets.only(left: 25, right: 25),
child: Container(),
),
),
),
],
),
),
Result->

You are getting overflow because the screen resizes when keyboard option. If you change the size of container when keyboard opens, your UI may not look as desired, so I would suggest to wrap your entire widget in a list view.

Related

Flutter- The submit button won't go down, How do I move the submit button to bottom center

Here is part of the code that I made and This is the result that I get.
Widget _buildPage() {
return SafeArea(
child: Container(
decoration: BoxDecoration(color: Colors.grey[300]),
child: Form(
key: formkey,
child: Column(
children: <Widget>[
Container(
width: screenWidth,
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(width: 1.0, color: Colors.grey)),
color: Colors.white),
child: Padding(
padding: EdgeInsets.fromLTRB(
screenWidth * 0.05, 0, screenWidth * 0.03, 0),
child: Row(children: [
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text('Craft',
style: TextStyle(
color: Colors.black,
fontSize: baseDimens.baseFontSize16,
fontWeight: FontWeight.bold))
],
),
Text('-',
style: TextStyle(
color: Colors.lightBlueAccent,
fontSize: baseDimens.baseFontSize16,
))
],
)
),
Visibility(
visible: true,
child: GestureDetector(
child: Image.asset(
baseAssets.addIcon,
fit: BoxFit.cover,
height: contHeight * 0.6,
width: contHeight * 0.6,
),
onTap: () async {
},
),
),
],
),
),
),
Container(
width: screenWidth,
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(width: 1.0, color: Colors.grey)),
color: Colors.white),
child: Padding(
padding: EdgeInsets.fromLTRB(
screenWidth * 0.05, 0, screenWidth * 0.03, 0),
child: Row(children: [
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text('Labor',
style: TextStyle(
color: Colors.black,
fontSize: baseDimens.baseFontSize16,
fontWeight: FontWeight.bold))
],
),
Text('-',
style: TextStyle(
color: Colors.lightBlueAccent,
fontSize: baseDimens.baseFontSize16,
))
],
)
),
Visibility(
visible: true,
child: GestureDetector(
child: Image.asset(
baseAssets.addIcon,
fit: BoxFit.cover,
height: contHeight * 0.6,
width: contHeight * 0.6,
),
onTap: () async {
},
),
),
],
),
),
),
_label('Skill Level', '-'),
// Project Status
_label('Quantity', '0'),
// Location
_label('Regular Hours', '0'),
// Customer
_label('Required Date', 'DD/MM/YYYY'),
Visibility(
visible: true,
child: Align(
alignment: Alignment.bottomCenter,
child: Row(
children: [
Expanded(
child: TextButton(
onPressed: () async {
},
child: Text("Submit"),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(
baseColors.baseColor))),
)
],
),
),
),
],
),
),
),
);
}
}
}
The result that I expected was supposed to be the submit button at the bottom of the screen and still cannot figure out how to move it to bottom even after I used alignment bottom center. Any suggestion on what I should fix?
Align wont work here as it only takes the space column provides it. So add spacer before it. so that it pushes the button till the full height.
_label('Required Date', 'DD/MM/YYYY'),
Spacer(), //add here
Visibility(
visible: true,
child: Align(
alignment: Alignment.bottomCenter,
child: Row(
children: [
Expanded(
child: TextButton(
onPressed: () async {
},
child: Text("Submit"),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(
baseColors.baseColor))),
)
],
),
),
),
you can simply pass button in bottomNavigationBar as shown below:
scaffold(
body: ///your current code
bottomNavigationBar: Visibility(
visible: true,
child: Align(
alignment: Alignment.bottomCenter,
child: Row(
children: [
Expanded(
child: TextButton(
onPressed: () async {
},
child: Text("Submit"),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(
baseColors.baseColor))),
)
],
),
),
),
)
You can achieve it using Expanded().
Wrap you button with Expanded.
Example :
Expanded(
child: Visibility(
visible: true,
child: Align(
alignment: Alignment.bottomCenter,
child: Row(
children: [
Expanded(
child: TextButton(
onPressed: () async {},
child: Text("Submit"),
),
)
],
),
),
)),
You can create a child of SafeArea as Scaffold and pass that submit button in bottomSheet or bottomNavigationBar-
Widget _buildPage() {
return SafeArea(
child: Scaffold(
bottomSheet: Container( height:60, width:100, child: Visibility(
visible: true,
child: Align(
alignment: Alignment.bottomCenter,
child: Row(
children: [
Expanded(
child: TextButton(
onPressed: () async {},
child: Text("Submit"),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(
baseColors.baseColor))),
)
],
),
),
),
),
body: Container(
decoration: BoxDecoration(color: Colors.grey[300]),
child: Form(
key: formkey,
child: Column(
children: <Widget>[
Container(
width: screenWidth,
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(width: 1.0, color: Colors.grey)),
color: Colors.white),
child: Padding(
padding: EdgeInsets.fromLTRB(
screenWidth * 0.05, 0, screenWidth * 0.03, 0),
child: Row(children: [
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text('Craft',
style: TextStyle(
color: Colors.black,
fontSize: baseDimens.baseFontSize16,
fontWeight: FontWeight.bold))
],
),
Text('-',
style: TextStyle(
color: Colors.lightBlueAccent,
fontSize: baseDimens.baseFontSize16,
))
],
)
),
Visibility(
visible: true,
child: GestureDetector(
child: Image.asset(
baseAssets.addIcon,
fit: BoxFit.cover,
height: contHeight * 0.6,
width: contHeight * 0.6,
),
onTap: () async {},
),
),
],
),
),
),
Container(
width: screenWidth,
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(width: 1.0, color: Colors.grey)),
color: Colors.white),
child: Padding(
padding: EdgeInsets.fromLTRB(
screenWidth * 0.05, 0, screenWidth * 0.03, 0),
child: Row(children: [
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text('Labor',
style: TextStyle(
color: Colors.black,
fontSize: baseDimens.baseFontSize16,
fontWeight: FontWeight.bold))
],
),
Text('-',
style: TextStyle(
color: Colors.lightBlueAccent,
fontSize: baseDimens.baseFontSize16,
))
],
)
),
Visibility(
visible: true,
child: GestureDetector(
child: Image.asset(
baseAssets.addIcon,
fit: BoxFit.cover,
height: contHeight * 0.6,
width: contHeight * 0.6,
),
onTap: () async {},
),
),
],
),
),
),
_label('Skill Level', '-'),
// Project Status
_label('Quantity', '0'),
// Location
_label('Regular Hours', '0'),
// Customer
_label('Required Date', 'DD/MM/YYYY'),
],
),
),
),
),
);
}
}
}

How can I wrap text and an icon in a row such that text is exactly at the center and icon is at the right end in flutter

I want to wrap text and an icon in a row such that text is exactly at the center and icon is at the right end in flutter
Row(
children: [
Center(
child: Text(
"Add Child",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20,
color: Colors.indigo[900],
),
),
),
Padding(
padding: const EdgeInsets.only(top: 1),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
IconButton(
icon: Icon(Icons.close),
iconSize: 18,
color: Colors.black,
onPressed: () {
Navigator.pop(context);
},
),
],
),
),
],
),
Try this
Widget _iconButton() {
return Container(
height: 40,
width: MediaQuery.of(context).size.width - 80,
decoration: BoxDecoration(
color: Color(0xff303030),
borderRadius: BorderRadius.circular(5),
),
child: Stack(
alignment: Alignment.center,
children: [
Text(
'Add',
style: TextStyle(color: Colors.white, fontSize: 18),
),
Positioned(
right: 8,
child: Container(
height: 30,
width: 30,
padding: EdgeInsets.all(6),
child: Icon(Icons.add),
),
),
],
),
);
}

How to center text and prevent text from overflowing using Flutter

My UI currently looks like this:
I want to center the text in the middle of the space that is left over after the image is placed. However, I also want to make sure that my text does not overflow due to the size. How can I do that? My code is as follows:
Widget build(BuildContext context) {
return Card(
color: Theme.of(context).scaffoldBackgroundColor,
elevation: 0,
child: Column(
children: [
Divider(
thickness: 2,
color: Colors.white,
height: 0,
),
Row(
children: [
Container(
padding: EdgeInsets.all(0),
width: 100,
height: 100,
child: CircleAvatar(
radius: 50,
backgroundImage: NetworkImage(imageUrl),
),
),
Container(
padding: EdgeInsets.all(40),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
alignment: Alignment.topCenter,
child: Text(
name,
style: TextStyle(
fontSize: 30,
color: Colors.white,
),
),
),
Container(
alignment: Alignment.bottomLeft,
padding: EdgeInsets.all(15),
child: Text(
modalityText,
style: TextStyle(
fontSize: 10,
color: Colors.white,
),
),
),
],
),
),
],
),
],
),
);
}
Here, this is one way of doing what you want
Widget build(BuildContext context) {
return Card(
color: Theme.of(context).scaffoldBackgroundColor,
elevation: 0,
child: Column(
children: [
Divider(
thickness: 2,
color: Colors.white,
height: 0,
),
Row(
children: [
Container(
padding: EdgeInsets.all(0),
width: 100,
height: 100,
child: CircleAvatar(
radius: 50,
backgroundImage: NetworkImage("imageUrl"),
),
),
Expanded(
child: Container(
padding: EdgeInsets.all(40),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
alignment: Alignment.topCenter,
child: Text(
"name",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 30,
color: Colors.white,
),
),
),
Container(
alignment: Alignment.bottomLeft,
padding: EdgeInsets.all(15),
child: Text(
"modalityText",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 10,
color: Colors.white,
),
),
),
],
),
),
),
],
),
],
),
);
}

I want to do the expandable list view as below in attached image. How can I achieve this type of functionality in flutter?

How can I achieve this?. I have tried customizing ExpansionTile but not able to get similar effects on expansion and collapse. Mainly the prefix icon is bigger in size and so the expandable text is not close to the date. Also, the suffix icon for expanding/collapsing not fully covered with the background color.
I am also attaching an image that I have tried. I have used https://pub.dev/packages/expandable#-readme-tab- to achieve a similar effect but no luck.
I am really stuck at this place and want any kind of help.
Your help will be appreciated.
Thanks.
Just implemented, try this:
ListView.builder(
itemCount: 20,
itemBuilder: (context, index) {
return ExpandableNotifier(
child: Card(
elevation: 4,
child: Expandable(
collapsed: Container(
width: MediaQuery.of(context).size.width,
height: 105,
child: ExpandableButton(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: EdgeInsets.all(10),
child: ClipOval(
child: Container(
height: 80,
width: 80,
color: Colors.yellow,
),
),
),
Expanded(
child: Padding(
padding: EdgeInsets.symmetric(vertical: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Welkom bij Haaer',
style: TextStyle(
fontSize: 14.0,
fontWeight: FontWeight.bold,
),
),
Text(
'2019/06/01 11:04',
style: TextStyle(
color: Colors.grey,
fontSize: 12.0,
),
),
Text(
'blablablablablablablablablablablablablablablablablablablablablabla'
'blablablablablablablablablablablablablablablablablablablablablabla'
'blablablablablablablablablablablablablablablablablablablablablabla',
softWrap: true,
overflow: TextOverflow.ellipsis,
maxLines: 2,
),
],
),
),
),
Container(
color: Colors.yellow,
width: 30,
height: 105,
child: Icon(
Icons.keyboard_arrow_right,
color: Colors.white,
),
),
],
),
),
),
expanded: Container(
height: 200,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: EdgeInsets.all(10),
child: ClipOval(
child: Container(
height: 80,
width: 80,
color: Colors.purple,
),
),
),
Expanded(
child: Padding(
padding: EdgeInsets.symmetric(vertical: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Welkom bij Haaer',
style: TextStyle(
fontSize: 14.0,
fontWeight: FontWeight.bold,
),
),
Text(
'2019/06/01 11:04',
style: TextStyle(
color: Colors.grey,
fontSize: 12.0,
),
),
Text(
'blablablablablablablablablablablablablablablablablablablablablabla'
'blablablablablablablablablablablablablablablablablablablablablabla'
'blablablablablablablablablablablablablablablablablablablablablabla',
softWrap: true,
),
SizedBox(
height: 5,
),
Container(
width: 80,
height: 20,
child: RaisedButton(
padding: EdgeInsets.all(0),
color: Colors.purple,
child: Text('show'),
onPressed: () {},
),
),
],
),
),
),
ExpandableButton(
child: Container(
color: Colors.purple,
width: 30,
height: 200,
child: Icon(
Icons.keyboard_arrow_down,
color: Colors.white,
),
),
),
],
),
),
),
),
);
},
),

SingleChildScrollView not working in Column

I am building an app facing a singleChildScrollView not able to scroll the page the text has been cut from bottom after the contact button i want to scroll the page but but spending so much time can't fix problem.
enter image description here
enter code here
import 'package:flutter/material.dart';
class DetailScreen extends StatefulWidget {
final electricain;
DetailScreen(this.electricain);
#override
_DetailScreenState createState() => _DetailScreenState();
}
class _DetailScreenState extends State<DetailScreen> {
#override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: Stack(
children: <Widget>[
Container(
height: MediaQuery.of(context).size.height / 3 + 20,
width: MediaQuery.of(context).size.width,
child: Stack(
fit: StackFit.expand,
children: <Widget>[
Image.asset(
'assets/images/detail_bg.jpg',
fit: BoxFit.fill,
),
Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
color: Colors.purple.withOpacity(0.1),
),
],
),
),
Positioned(
top: 50,
left: 20,
child: IconButton(
icon: Icon(
Icons.arrow_back_ios,
color: Colors.white,
),
onPressed: () {
Navigator.pop(context);
},
),
),
Positioned(
top: MediaQuery.of(context).size.height / 3.6 - 40,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(60),
),
),
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 30),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(
height: 130,
),
Text(
'Description',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20,
),
),
SizedBox(
height: 10,
),
Text(
'${widget.electricain['desc']}',
style: TextStyle(
color: Colors.grey,
),
textAlign: TextAlign.justify,
),
SizedBox(
height: 10,
),
Text(
"\n Services List",
style: TextStyle(
fontSize: 20.0, fontWeight: FontWeight.bold),
),
SizedBox(height: 10),
Text(
'${widget.electricain['services']}',
style: TextStyle(
color: Colors.grey,
),
),
SizedBox(height: 30),
MaterialButton(
onPressed: () {},
color: Colors.orange,
child: Text(
"Contact",
style: TextStyle(
color: Colors.white, fontSize: 16.0),
),
),
SizedBox(height: 10),
Text(
'${widget.electricain['services']}',
style: TextStyle(
color: Colors.grey,
),
),
],
),
),
),
),
),
),
Positioned(
top: MediaQuery.of(context).size.height / 3 - 90,
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 30),
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width / 3 - 20,
height: MediaQuery.of(context).size.height / 6 + 20,
decoration: BoxDecoration(
color: widget.electricain['bgColor'],
borderRadius: BorderRadius.circular(20),
),
child: Stack(
fit: StackFit.expand,
children: <Widget>[
Positioned(
top: 10,
right: -25,
child: Image.asset(
widget.electricain['imgUrl'],
scale: 1.7,
),
),
],
),
),
SizedBox(
width: 20,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
widget.electricain['electricainName'],
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20,
),
),
SizedBox(
height: 5,
),
Text(
widget.electricain['shopName'],
style: TextStyle(
fontWeight: FontWeight.w300,
color: Colors.grey,
),
),
SizedBox(
height: 10,
),
Row(
children: <Widget>[
Icon(
Icons.star,
size: 16,
color: Color(0xffFF8573),
),
SizedBox(width: 5),
Text(
widget.electricain['rating'],
style: TextStyle(
color: Color(0xffFF8573),
),
),
SizedBox(
width: 5,
),
Text(
'(${widget.electricain['rateAmount']})',
style: TextStyle(
color: Colors.grey,
),
),
],
)
],
),
],
),
),
),
],
),
),
);
}
}
try this:
LayoutBuilder(builder: (context, constraints) {
return SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(minWidth: constraints.maxWidth, minHeight: constraints.maxHeight),
child: IntrinsicHeight(
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
//your children here
]
),
)
)
);
})
IntrinsicHeight class
A widget that sizes its child to the child's intrinsic height.
This class is useful, for example, when unlimited height is available and you would like a child that would otherwise attempt to expand infinitely to instead size itself to a more reasonable height.