Related
Bottom align clipped image in Flutter
Hello!
I'm beginner in Flutter
The following image:
I clipped the lettuce image in half with ClipPath:
I'm trying to move it into bottom right to be similar to the following image:
I tried many times with my available experience with no luck
Here's the code:
class GroceryPage extends StatelessWidget {
const GroceryPage({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(15.0),
child: SingleChildScrollView(
child: Column(
children: [
const SizedBox(height: 10.0),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30.0),
color: const Color(0xFFE9F9F2),
),
width: double.infinity,
child: Stack(
children: [
ClipPath(
clipper: HalfClip(),
child: Align(
alignment: Alignment.bottomRight,
child: Image.asset(
'${kProductsImagesAsset}lettuce.png',
height: 150,
// width: 150,
fit: BoxFit.cover,
),
),
),
Padding(
padding: const EdgeInsets.all(40.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Get Up To',
style: kGreenTitleStyle.copyWith(
fontSize: 20.0,
),
),
Text(
'%10 off',
style: kGreenTitleStyle.copyWith(
fontSize: 40.0,
),
),
],
),
),
],
),
),
],
),
),
),
),
);
}
}
Can anyone help me doing so?
Use Positioned widget as Stack child.
Positioned(
top: 0,
left: 0,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Get Up To',
style: kGreenTitleStyle.copyWith(
fontSize: 20.0,
),
),
Text(
'%10 off',
style: kGreenTitleStyle.copyWith(
fontSize: 40.0,
),
),
],
),
),
More about using Stack
class GroceryPage extends StatelessWidget {
const GroceryPage({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(15.0),
child: SingleChildScrollView(
child: Column(
children: [
const SizedBox(height: 10.0),
Container(
height: 300, //cardHeight
clipBehavior: Clip.hardEdge,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30.0),
color: const Color(0xFFE9F9F2),
),
child: Stack(
children: [
Align(
child: Container(
height: 600, // full image height= cardHeight*2
color: Colors.red,
),
// child: Image.asset(
// '${kProductsImagesAsset}lettuce.png',
// height: 150,
// // width: 150,
// fit: BoxFit.cover,
// ),
),
Positioned(
top: 0,
left: 0,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Get Up To',
style: TextStyle(
fontSize: 20.0,
),
),
Text(
'%10 off',
style: TextStyle(
fontSize: 40.0,
),
),
],
),
),
],
),
),
],
),
),
),
),
);
}
}
I have tried almost all the solution on stackoverflow like using Expanded widget with single child scroll view and physics property and what not but still cannot enable scroll inside futurebuilder which occupy second half of my screen, the first half is static but second half contains listview inside future builder but it's not scrollable !!
The Error is Bottom Overflowed by 1313 pixels
This Is My Code
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
resizeToAvoidBottomInset: true,
body:Container(
child: Column(
children: [
Column(
children: [
Padding(
padding: const EdgeInsets.fromLTRB(15,12,15,0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Image.asset('assets/hamburger.png',height: 25,width: 25,alignment: Alignment.topLeft,),
Image.asset('assets/log.png',height: 37,width: 37,alignment: Alignment.center,),
Image.asset('assets/searc.png',height: 25,width: 25,alignment: Alignment.topRight,),
],
),
),
SizedBox(height: 10,),
Padding(
padding: const EdgeInsets.fromLTRB(15, 0, 0, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
CircleAvatar(
radius: 30,
backgroundImage: NetworkImage(img)
),
// split(data[index]["image"])
SizedBox(width: 20,),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
// mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
children: [
Text('Hello',style: TextStyle(
color: Colors.black,
fontSize: 15,
),textAlign: TextAlign.start,),
SizedBox(width: 5,),
Text(name,style: TextStyle(
color: Colors.black,
fontSize: 15,
fontWeight: FontWeight.bold
),textAlign: TextAlign.start,),
],
),
Text('Welcome To Quad Life',style: TextStyle(
color: Colors.grey,
fontSize: 13,
),textAlign: TextAlign.start,),
],
),
],
),
),
SizedBox(height: 10,),
Padding(
padding: const EdgeInsets.fromLTRB(15, 0, 15, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SizedBox(
width:MediaQuery.of(context).size.width*0.4,
height: 70,
child: Card(
elevation: 5,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
) ,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 5),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(data.length.toString(),
style:
TextStyle(color: Colors.black,
fontSize: 15,
fontWeight: FontWeight.bold),),
SizedBox(height: 5,),
Text('Operators',style:
TextStyle(color: Colors.grey,
fontSize: 15,
fontWeight: FontWeight.bold),),
],
),
),
),
),
SizedBox(
width:MediaQuery.of(context).size.width*0.4,
height: 70,
child: Card(
elevation: 5,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
) ,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 5),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(data1.length.toString(),style:
TextStyle(color: Colors.black,
fontSize: 15,
fontWeight: FontWeight.bold),),
SizedBox(height: 5,),
Text('Supervisors',style:
TextStyle(color: Colors.grey,
fontSize: 15,
fontWeight: FontWeight.bold),),
],
),
),
),
),
],
),
),
Column(
children: [
Padding(
padding: const EdgeInsets.fromLTRB(0, 15, 0, 0),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 15),
child: Card(
elevation: 20,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
) ,
child: SizedBox(
width: MediaQuery.of(context).size.width,
height: 150,
child: LineChart(
LineChartData(
borderData: FlBorderData(
show: true,
border: Border.all(width: 0)
),
gridData: FlGridData(
show: false,
),
titlesData: FlTitlesData(
show: false,
bottomTitles: SideTitles(
showTitles: true,
)
),
maxX: 50,
maxY: 100,
minX: 0,
minY: 0,
lineBarsData: [
LineChartBarData(
spots: [
FlSpot(0, 50),
FlSpot(10, 60),
FlSpot(15, 55),
FlSpot(20, 60),
FlSpot(30, 70),
FlSpot(40, 65),
FlSpot(50, 90),
],
isCurved: true,
colors: [Colors.orange,Colors.orangeAccent.shade700],
barWidth: 5,
belowBarData: BarAreaData(
show: true,
colors: gradientcolors.map((e) => e.withOpacity(0.3)).toList()
)
),
],
)
),
),
),
),
),
SizedBox(height: 10,),
Padding(
padding: const EdgeInsets.fromLTRB(15, 0, 15, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SizedBox(
width:MediaQuery.of(context).size.width*0.45,
height: 70,
child: Card(
elevation: 3,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(7),
) ,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 5),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('New Operator',style:
TextStyle(color: Colors.black,
fontSize: 14,),),
SizedBox(height: 5,),
Text('Register new verfied Operator',
textAlign: TextAlign.center,
style:
TextStyle(color: Colors.grey,
fontSize: 9,
fontWeight: FontWeight.bold),),
],
),
),
),
),
SizedBox(
width:MediaQuery.of(context).size.width*0.45,
height: 70,
child: Card(
elevation: 3,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(7),
) ,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 5),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('New Supervisors',style:
TextStyle(color: Colors.black,
fontSize: 14,),),
SizedBox(height: 5,),
Text('Register new verfied Supervisors',
textAlign: TextAlign.center,
style:
TextStyle(color: Colors.grey,
fontSize: 9,
fontWeight: FontWeight.bold),),
],
),
),
),
),
],
),
),
],
),
SizedBox(height: 5,),
Padding(
padding: EdgeInsets.fromLTRB(15, 0, 0, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text('Verify Operators',style: TextStyle(
color: Colors.grey.shade500,
fontSize: 15,
fontWeight: FontWeight.bold,
),
),
],
),
),
],
),
FutureBuilder(
builder: (context, snapshot){
if(snapshot != null){
return Column(
children: [
ListView.builder(
scrollDirection: Axis.vertical,
physics:NeverScrollableScrollPhysics(),
shrinkWrap: true,
// builder: (BuildContext context, int index) {
// return SizedBox(height: 0);
// },
itemCount: data == null ? 0 :data.length ,
itemBuilder: (context, index){
return InkWell(
onTap: (){},
child: Padding(
padding: const EdgeInsets.all(0),
child: Container(
height: MediaQuery.of(context).size.height*0.1,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(20)),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
margin: EdgeInsets.only(left: 15),
child: SizedBox(
height: 50,
width: 50,
child: ClipRRect(
borderRadius: BorderRadius.circular(15),
child: Image(
image: NetworkImage(split(data[index]["image"])),
),
),
),
),
SizedBox(width: 10,),
Padding(
padding: const EdgeInsets.only(top: 25),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(data[index]["fullName"],
textAlign: TextAlign.left,
style: TextStyle(
fontSize: 15,
color: Colors.black,
fontWeight: FontWeight.bold,
),),
Text(capitalize(data[index]["experience"][data[index]["experience"].length-1]['designation']),
textAlign: TextAlign.left,
style: TextStyle(
fontSize: 15,
color: Colors.grey,
fontWeight: FontWeight.w100
),),
],
),
),
],
),
Padding(
padding: const EdgeInsets.only(right: 20),
child: TextButton(onPressed: (){},
child: Text('Verify Now',style:
TextStyle(color: Colors.green,fontWeight: FontWeight.bold,
fontSize: 15),),),
)
],
),
),
),
);
},
),
],
);
}else{
return CircularProgressIndicator();
}
},
),
],
),
),
),
);
}
=>Change Second half with this
Expanded(
flex: 1,
child: FutureBuilder(
builder: (context, snapshot) {
if (snapshot != null) {
return ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
// builder: (BuildContext context, int index) {
// return SizedBox(height: 0);
// },
itemCount: data == null ? 0 : data.length,
itemBuilder: (context, index) {
return InkWell(
onTap: () {},
child: Padding(
padding: const EdgeInsets.all(0),
child: Container(
height:
MediaQuery.of(context).size.height * 0.1,
decoration: BoxDecoration(
borderRadius:
BorderRadius.all(Radius.circular(20)),
),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Row(
mainAxisAlignment:
MainAxisAlignment.start,
children: [
Container(
margin: EdgeInsets.only(left: 15),
child: SizedBox(
height: 50,
width: 50,
child: ClipRRect(
borderRadius:
BorderRadius.circular(15),
child: Image(
image: NetworkImage(split(
data[index]["image"])),
),
),
),
),
SizedBox(
width: 10,
),
Padding(
padding:
const EdgeInsets.only(top: 25),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
data[index]["fullName"],
textAlign: TextAlign.left,
style: TextStyle(
fontSize: 15,
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
Text(
capitalize(data[index]
["experience"][data[index]
["experience"]
.length -
1]['designation']),
textAlign: TextAlign.left,
style: TextStyle(
fontSize: 15,
color: Colors.grey,
fontWeight:
FontWeight.w100),
),
],
),
),
],
),
Padding(
padding: const EdgeInsets.only(right: 20),
child: TextButton(
onPressed: () {},
child: Text(
'Verify Now',
style: TextStyle(
color: Colors.green,
fontWeight: FontWeight.bold,
fontSize: 15),
),
),
)
],
),
),
));
});
} else {
return CircularProgressIndicator();
}
},
),
),
Try below format hope its helpful to you. Wrap your FutureBuilder inside Expanded or Flexible
body: Column(
children: [
Container(),
Expanded(
child: FutureBuilder(
future: yourFutureCall();
builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
return ListView.builder(
shrinkWrap: true,
physics:
const NeverScrollableScrollPhysics(), //OR use -> const ClampingScrollPhysics(),
itemBuilder: (BuildContext context, int index) {
return Container();
},
);
},
),
),
],
),
I'm not sure , cause I could not run the code , but What I see is the unbounded widgets from lack of the specified width and height which is a common mistake in flutter world .
if #Jasmin Sojitra's answer does not work try putting height and width of full screen on the first Container , If still there is a problemt put child of the Container inside a SingleChildScrollView .
I have three tab. One of the tab is for edit photo page (retrieve image which already have in API, edit and return capture image to API with Update button in that page). All is work and fine. But after capture image with camera, and change to other tab and return back to this tab (in this state not save), Already capture image not show and only API image show. I capture again to save. I want to remain the capture image in container although I don't save to API and change tab.
This is picture of my app contain tab bar view which contain edit image tab bar
This is my tab bar view dart file.
var width = MediaQuery.of(context).size.width;
final tabText = TextStyle(fontSize: width * 0.03);
return Scaffold(
appBar: new AppBar(
title: new Text(
'EDIT CLIENT',
style: new TextStyle(color: accentColor, fontFamily: 'Dosis'),
),
bottom: PreferredSize(
preferredSize: Size(40, 40),
child: Container(
height: getScreenHeightRation(40.0),
decoration: BoxDecoration(
color: Color(0xFFF0C185),
border: Border.all(color: Colors.grey[600]),
//0xFFF0C185
),
child: TabBar(
indicatorPadding: EdgeInsets.symmetric(horizontal: 40),
//isScrollable: true,
//change here
labelPadding: EdgeInsets.only(left: 10),
indicatorSize: TabBarIndicatorSize.tab,
indicatorColor: Colors.transparent,
indicator: BoxDecoration(
color: Color(0xFFD2A368),
),
tabs: [
Container(
decoration: BoxDecoration(
border: Border(right: BorderSide(color: Colors.grey))),
child: Tab(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ImageIcon(
AssetImage('assets/images/icon_ext/menu.png'),
size: 12,
),
SizedBox(
width: 5.0,
),
Text('Customer Data',style: tabText, ),
],
),
),
),
Container(
decoration: BoxDecoration(
border: Border(right: BorderSide(color: Colors.grey))),
child: Tab(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ImageIcon(
AssetImage('assets/images/icon_ext/image.png'),
size: 12,
),
SizedBox(
width: 5.0,
),
Text('Profile',style: tabText, )
],
),
),
),
Container(
child: Tab(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ImageIcon(
AssetImage('assets/images/icon_ext/placeholder.png'),
size: 12,
),
SizedBox(
width: 5.0,
),
Text('Location',style: tabText, )
],
),
),
)
],
controller: tabController,
),
),
),
iconTheme: new IconThemeData(color: accentColor),
centerTitle: true,
),
body: TabBarView(
controller: tabController,
children: [
EditClientInformation(
customerNo: widget.customerNo,
branchId: _branchId,
defaultBranchId: _defaultBranchId,
userId: _userId,
systemFormatDate: _systemFormatDate,
),
EditClientProfile(
customerNo: widget.customerNo,
branchId: _branchId,
defaultBranchId: _defaultBranchId,
userId: _userId,
systemFormatDate: _systemFormatDate,
),
EditClientMap(
customerNo: widget.customerNo,
branchId: _branchId,
defaultBranchId: _defaultBranchId,
userId: _userId,
systemFormatDate: _systemFormatDate,
),
],
),
);
}
This is capture image tab.
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Stack(
children: [
Container(
width: 300.0,
height: 170.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(20)),
border:
Border.all(width: 1, style: BorderStyle.solid),
),
child: Center(
child: Container(
width: 170.0,
height: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topRight: Radius.circular(20),
topLeft: Radius.circular(10),
bottomLeft: Radius.circular(10),
bottomRight: Radius.circular(10)),
//border: Border.all(width: 1, style: BorderStyle.solid),
image: DecorationImage(
image: _profileCaptImg == ""
? NetworkImage(_profileImg)
: FileImage(profile),
fit: BoxFit.cover,
),
),
),
),
),
Positioned(
right: 62.0,
top: 0.0,
child: _profileCaptImg != ''
? GestureDetector(
onTap: () {
setState(() {
profile = null;
_profileCaptImg = '';
});
},
child: Container(
width: 20.0,
height: 20.0,
child: Icon(
Icons.close,
color: Colors.white,
size: 20.0,
),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.black,
),
),
)
: Container(),
),
],
),
Container(
width: 50.0,
height: 50.0,
child: FloatingActionButton(
onPressed: profileImgPicker,
heroTag: null,
child: new Icon(Icons.camera_alt),
)),
],
),
Try this solution:
/// Add with AutomaticKeepAliveClientMixin:
class _YourWidgetState extends State<YourWidget> with AutomaticKeepAliveClientMixin {
/// Add these 2 lines:
#override
bool get wantKeepAlive => true;
/// Add super.build(context) to your build method
#override
Widget build(BuildContext context) {
super.build(context);
return YourWidgets();
}
}
I need to make this favourite icon to the right of the container. I can use padding but is it ok? I mean is it going to work with all devices. Is there any solid way to align these 3 containers? I made a list view because I am adding more stuff like this one. can you guys help me with this?
Here is the image
Here is my code
class _OrdersState extends State<Orders> {
#override
Widget build(BuildContext context) {
return Material(
child: SafeArea(
child: Stack(
children: [
Background(),
Positioned(
top: 10,
left: 5,
child: SizedBox(
// width: 10,
// height: 10,
child: Container(
color: Colors.transparent,
child: IconButton(
icon: Icon(Icons.arrow_back),
color: Colors.white,
//go back
onPressed: () => Navigator.of(context).pop(),
),
),
),
),
Positioned(
top: 90,
left: 22,
right: 22,
child: SizedBox(
width: 350,
height: 900,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10),
topRight: Radius.circular(10),
),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 3,
blurRadius: 7,
),
],
),
child: Row(
children: [
Container(
color: Colors.blue,
margin: EdgeInsets.all(2),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'3:32',
style: TextStyle(fontSize: 20),
),
),
),
Container(
color: Colors.red,
child: Text(
'Order 1',
style: TextStyle(fontSize: 20),
),
),
Container(
color: Colors.amber,
child: Icon(Icons.favorite),
)
],
),
),
),
),
],
),
),
);
}
}
In the Row try to use and Expanded widget like this
Row(
children: [
Expanded(
child: Row(
children: [
Container(
color: Colors.blue,
margin: EdgeInsets.all(2),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'3:32',
style: TextStyle(fontSize: 20),
),
),
),
Container(
color: Colors.red,
child: Text(
'Order 1',
style: TextStyle(fontSize: 20),
),
),
],
),
),
Container(
color: Colors.amber,
child: Icon(Icons.favorite),
)
],
)
Hi I am trying to create login screen. It is working fine for me. When I open the keyboard then it is giving me an error Bottom overloaded by 213 pixels.
Widget LoginPage() {
return new Scaffold(body: Container(
height: MediaQuery.of(context).size.height,
decoration: BoxDecoration(
color: Colors.white,
image: DecorationImage(
colorFilter: new ColorFilter.mode(
Colors.black.withOpacity(0.05), BlendMode.dstATop),
image: AssetImage('assets/images/mountains.jpg'),
fit: BoxFit.cover,
),
),
child: new Column(
children: <Widget>[
Container(
padding: EdgeInsets.all(120.0),
child: Center(
child: Icon(
Icons.headset_mic,
color: Colors.redAccent,
size: 50.0,
),
),
),
new Row(
children: <Widget>[
new Expanded(
child: new Padding(
padding: const EdgeInsets.only(left: 40.0),
child: new Text(
"EMAIL",
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.redAccent,
fontSize: 15.0,
),
),
),
),
],
),
new Container(
width: MediaQuery.of(context).size.width,
margin: const EdgeInsets.only(left: 40.0, right: 40.0, top: 10.0),
alignment: Alignment.center,
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: Colors.redAccent,
width: 0.5,
style: BorderStyle.solid),
),
),
padding: const EdgeInsets.only(left: 0.0, right: 10.0),
child: new Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
new Expanded(
child: TextField(
obscureText: true,
textAlign: TextAlign.left,
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'samarthagarwal#live.com',
hintStyle: TextStyle(color: Colors.grey),
),
),
),
],
),
),
Divider(
height: 24.0,
),
new Row(
children: <Widget>[
new Expanded(
child: new Padding(
padding: const EdgeInsets.only(left: 40.0),
child: new Text(
"PASSWORD",
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.redAccent,
fontSize: 15.0,
),
),
),
),
],
),
new Container(
width: MediaQuery.of(context).size.width,
margin: const EdgeInsets.only(left: 40.0, right: 40.0, top: 10.0),
alignment: Alignment.center,
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: Colors.redAccent,
width: 0.5,
style: BorderStyle.solid),
),
),
padding: const EdgeInsets.only(left: 0.0, right: 10.0),
child: new Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
new Expanded(
child: TextField(
obscureText: true,
textAlign: TextAlign.left,
decoration: InputDecoration(
border: InputBorder.none,
hintText: '*********',
hintStyle: TextStyle(color: Colors.grey),
),
),
),
],
),
),
Divider(
height: 24.0,
),
new Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(right: 20.0),
child: new FlatButton(
child: new Text(
"Forgot Password?",
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.redAccent,
fontSize: 15.0,
),
textAlign: TextAlign.end,
),
onPressed: () => {},
),
),
],
),
new Container(
width: MediaQuery.of(context).size.width,
margin: const EdgeInsets.only(left: 30.0, right: 30.0, top: 20.0),
alignment: Alignment.center,
child: new Row(
children: <Widget>[
new Expanded(
child: new FlatButton(
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0),
),
color: Colors.redAccent,
onPressed: () => {},
child: new Container(
padding: const EdgeInsets.symmetric(
vertical: 20.0,
horizontal: 20.0,
),
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Expanded(
child: Text(
"LOGIN",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold),
),
),
],
),
),
),
),
],
),
),
new Container(
width: MediaQuery.of(context).size.width,
margin: const EdgeInsets.only(left: 30.0, right: 30.0, top: 20.0),
alignment: Alignment.center,
child: Row(
children: <Widget>[
new Expanded(
child: new Container(
margin: EdgeInsets.all(8.0),
decoration: BoxDecoration(border: Border.all(width: 0.25)),
),
),
Text(
"OR CONNECT WITH",
style: TextStyle(
color: Colors.grey,
fontWeight: FontWeight.bold,
),
),
new Expanded(
child: new Container(
margin: EdgeInsets.all(8.0),
decoration: BoxDecoration(border: Border.all(width: 0.25)),
),
),
],
),
),
new Container(
width: MediaQuery.of(context).size.width,
margin: const EdgeInsets.only(left: 30.0, right: 30.0, top: 20.0),
child: new Row(
children: <Widget>[
new Expanded(
child: new Container(
margin: EdgeInsets.only(right: 8.0),
alignment: Alignment.center,
child: new Row(
children: <Widget>[
new Expanded(
child: new FlatButton(
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0),
),
color: Color(0Xff3B5998),
onPressed: () => {},
child: new Container(
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Expanded(
child: new FlatButton(
padding: EdgeInsets.only(
top: 20.0,
bottom: 20.0,
),
child: new Row(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: <Widget>[
Icon(
const IconData(0xea90,
fontFamily: 'icomoon'),
color: Colors.white,
size: 15.0,
),
Text(
"FACEBOOK",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold),
),
],
),
),
),
],
),
),
),
),
],
),
),
),
new Expanded(
child: new Container(
margin: EdgeInsets.only(left: 8.0),
alignment: Alignment.center,
child: new Row(
children: <Widget>[
new Expanded(
child: new FlatButton(
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0),
),
color: Color(0Xffdb3236),
onPressed: () => {},
child: new Container(
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Expanded(
child: new FlatButton(
padding: EdgeInsets.only(
top: 20.0,
bottom: 20.0,
),
child: new Row(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: <Widget>[
Icon(
const IconData(0xea88,
fontFamily: 'icomoon'),
color: Colors.white,
size: 15.0,
),
Text(
"GOOGLE",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold),
),
],
),
),
),
],
),
),
),
),
],
),
),
),
],
),
)
],
),
));
}
Does anyone know what could be the issue ?
I would suggest replacing the top Column widget with a ListView, that automatically resizes on keyboard input, whilst also supporting scrolling.
If you really want this setup as it is, you can edit your Scaffold with the parameter
resizeToAvoidBottomPadding: false
That should make the error disappear
Scaffold(
resizeToAvoidBottomInset: false, // set it to false
...
)
As Andrey said, you may have issues with scrolling, so you may try
Scaffold(
resizeToAvoidBottomInset: false, // set it to false
body: SingleChildScrollView(child: YourBody()),
)
With resizeToAvoidBottomPadding: false in Scaffold, You don't see all the widgets that are below the open textfield. The solution is to insert a container with a SingleChildScrollView inside. Example:
Container(
alignment: Alignment.center,
width: double.infinity,
height: double.infinity,
color: viewModel.color,
child: SingleChildScrollView(child:"Your widgets"));
you usually need to provide a scroll widget on top of your widgets because if you try to open the keyboard or change the orientation of your phone, flutter needs to know how to handle the distribution of the widgets on the screen.
Please review this resource, you can check the different options that flutter provide Out of the box, and choose the best option for your scenario.
https://flutter.io/widgets/scrolling/
wrap your child view into ListView will solve the prob. Please check this
class _LoginScreenState extends State<LoginScreen> {
#override
Widget build(BuildContext context) {
return new Scaffold(
body: new Container(
child: ListView(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Padding(
padding: EdgeInsets.only(left: 1,top: 50,right: 1,bottom: 1),
child: new Text("jk", style: TextStyle(fontFamily: "mono_bold")),
),
new Padding(
padding: EdgeInsets.only(left: 1,top: 50,right: 1,bottom: 1),
child: new TextField(
style: new TextStyle(),
decoration: InputDecoration(
labelText: "Email",
contentPadding: EdgeInsets.all(8.0)
),
keyboardType: TextInputType.emailAddress,
)
),
new Padding(
padding: EdgeInsets.only(left: 1,top: 50,right: 1,bottom: 1),
child: new TextField(
style: new TextStyle(
),
decoration: InputDecoration(
labelText: "Password"
),
keyboardType: TextInputType.text,
obscureText: true,
),
),
],
),
),
],
)
),
);
}
wrap your column into SingleChildScrollView will solve the problem. Please check this:
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: Center(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextField(),
TextField(),
],
),
))));
}
And You also use for removing yellow black overflow line
resizeToAvoidBottomPadding: false
but in this case, TextField does not move up on click time.
wrap with SingleChildScrollView Widget here's my code to solve this situation:
it is best and easiest method
SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Hero(
tag: 'logo',
child: Container(
height: 200.0,
child: Image.asset('images/logo.png'),
),
),
SizedBox(
height: 48.0,
),
TextField(
onChanged: (value) {
//Do something with the user input.
},
decoration: kTextFieldDecoration.copyWith(hintText: 'Enter username'),
),
SizedBox(
height: 8.0,
),
TextField(
onChanged: (value) {
//Do something with the user input.
},
decoration: kTextFieldDecoration.copyWith(hintText: 'Enter password'),
),
SizedBox(
height: 24.0,
),
RoundedButton(
colour: Colors.blueAccent,
text: 'Register',
onPressed: () {
//later todo
},
),
],
),
),
You can set resizeToAvoidBottomInset: false for avoiding overflow, but you can't reach fields in bottom of page, which can be covered by keyboard.
Or you can wrap body of Scaffold inside SingleChildScrollView
You can enclose all the widgets within the ListView.
So you can scroll it and the overloaded will disappear.
you should add resizeToAvoidBottomInset: false, and put your button in child:SingleChildScrollView() like the following code below :
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
appBar: PreferredSize(
preferredSize:const Size(double.infinity,100),
child:(ResponsiveLayout.isTinyLimit(context) ||
ResponsiveLayout.isTinyHeightLimit(context))
? Container()
: const AppBarWidget(),
),
body: Center(
child:SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center ,
children: [
Text("Temperature"),
LineChartSample2(),
Text("Gas Level"),
LineChartSample2(),
on?Icon(Icons.lightbulb,
size:100,
color: Colors.lightBlue.shade700 ,
):const Icon(Icons.lightbulb_outline,
size:100,
),
ElevatedButton(
style: TextButton.styleFrom(
backgroundColor: on? Colors.green: Colors.white10),
onPressed: (){
dbR.child("movement").set({"Switch":!on});
setState(() {
on = !on;
});
},
child:on ? const Text("On"):const Text("Off"))
],
),
),
) ),
),
);
Put your content in to SingleChildScrollView and add a ConstrainedBox and try
https://api.flutter.dev/flutter/widgets/SingleChildScrollView-class.html
Wrap your top column inside SingleChildScrollView.
Make you layout scrollable.
You can wrap your Fields in single child ScrollView of Flutter.
This align items bottom to top,
Try this..
child: SizedBox(
height: MediaQuery.of(context).size.height,
child: SingleChildScrollView(
reverse: true,
Remove unwanted padding top and bottom
child: Container(
height: size.height,
width: size.width,
padding: EdgeInsets.only(
left: size.width * 0.15,
right: size.width * 0.15,
top: size.width * 0.15,
bottom: size.width * 0.15,
),
to change by this
child: Container(
height: size.height,
width: size.width,
padding: EdgeInsets.only(
left: size.width * 0.15,
right: size.width * 0.15,
),
This worked for me.
please set resizeToAvoidBottomPadding: false and set scrollPadding in textField
Instead of column widget try to use flex widget, which might solve your problem.
Try wrapping your main Column with
1.(ListView and give property shrinkWrap: true,) List view has property children: [], or
2.( SingleChildScrollView() )but it has only child: , .
Something like:
child: ListView(shrinkWrap: true, children: <Widget>[
new Column(children: <Widget>[
Container(
padding: EdgeInsets.all(120.0),
child: Center(
child: Icon(
Icons.headset_mic,
color: Colors.redAccent,
size: 50.0,
),
),
),
new Row(
children: <Widget>[
new Expanded(
child: new Padding(
padding: const EdgeInsets.only(left: 40.0),
child: new Text(
"EMAIL",
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.redAccent,
fontSize: 15.0,
),
),
),
),
],
),
new Container(
width: MediaQuery.of(context).size.width,
margin: const EdgeInsets.only(
left: 40.0, right: 40.0, top: 10.0),
alignment: Alignment.center,
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: Colors.redAccent,
width: 0.5,
style: BorderStyle.solid),
),
),
padding: const EdgeInsets.only(left: 0.0, right: 10.0),
child: new Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
new Expanded(
child: TextField(
obscureText: true,
textAlign: TextAlign.left,
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'samarthagarwal#live.com',
hintStyle: TextStyle(color: Colors.grey),
),
),
),
],
),
),
Divider(
height: 24.0,
),
new Row(
children: <Widget>[
new Expanded(
child: new Padding(
padding: const EdgeInsets.only(left: 40.0),
child: new Text(
"PASSWORD",
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.redAccent,
fontSize: 15.0,
),
),
),
),
],
),
new Container(
width: MediaQuery.of(context).size.width,
margin: const EdgeInsets.only(
left: 40.0, right: 40.0, top: 10.0),
alignment: Alignment.center,
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: Colors.redAccent,
width: 0.5,
style: BorderStyle.solid),
),
),
padding: const EdgeInsets.only(left: 0.0, right: 10.0),
child: new Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
new Expanded(
child: TextField(
obscureText: true,
textAlign: TextAlign.left,
decoration: InputDecoration(
border: InputBorder.none,
hintText: '*********',
hintStyle: TextStyle(color: Colors.grey),
),
),
),
],
),
),
])
]),