Bottom overflowed by 182 pixels - flutter

I am trying to add textfields in a widget on Flutter, and it renders correctly, but when the text is pressed to enter the data, appears the following error:
"Bottom overflowed by 182 pixels"
The error is when the default keyboard appears. I don't know why is it happening since i am wrapping everything in a SingleChildScrollView widget, therefore, should work just fine.
Attached the code:
class TextFieldsState extends State<TextFields> {
#override
Widget build(BuildContext context) {
const colorRed = Color(0xFFF0786E);
return SingleChildScrollView(
child: Container(
margin: EdgeInsets.symmetric(
horizontal: 20.0,
vertical: 20.0,
),
//color: Colors.greenAccent,
height: 500,
child: Stack(
//alignment: Alignment.bottomCenter,
children: <Widget>[
Container (
height: 500,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(22.0),
color: colorRed,
),
child: Container (
height: 500,
margin: EdgeInsets.only(right: 10,),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(22),
),
),
),
Center(
child: Positioned (
child: SizedBox(
height: 136,
//width: size.width,
child: Column(
children: <Widget>[
Container(
height: 30,
width: 160,
child: TextField(
decoration: InputDecoration(
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.blue,
),
borderRadius: BorderRadius.circular(10.0),
),
hintText: 'Name',
),
textAlign: TextAlign.center,
),
),
SizedBox(height: 20.0),
Container(
height: 30,
width: 160,
child: TextField(
decoration: InputDecoration(
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.blue,
),
borderRadius: BorderRadius.circular(10.0),
),
hintText: 'Surname',
),
textAlign: TextAlign.center,
),
),
SizedBox(height: 20.0),
Container(
height: 30,
width: 160,
child: TextField(
decoration: InputDecoration(
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.blue,
),
borderRadius: BorderRadius.circular(10.0),
),
hintText: 'Nationality',
),
textAlign: TextAlign.center,
),
),
],
),
),
),
),
],
),
),
);
}
}
What is the solution, please?

try this please
SingleChildScrollView(
column( // your column
)
)
overflow error is in column and you should add SingleChildScrollView as parent of this column.

Please check the edited below code.
class TextFieldsState extends State<TextFields> {
#override
Widget build(BuildContext context) {
const colorRed = Color(0xFFF0786E);
return Scaffold(
body: SingleChildScrollView(
child: Container(
margin: EdgeInsets.symmetric(
horizontal: 20.0,
vertical: 20.0,
),
//color: Colors.greenAccent,
height: 500,
child: Stack(
//alignment: Alignment.bottomCenter,
children: <Widget>[
Container(
height: 500,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(22.0),
color: colorRed,
),
child: Container(
height: 500,
margin: EdgeInsets.only(
right: 10,
),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(22),
),
),
),
Center(
child: SizedBox(
height: 136,
//width: size.width,
child: SingleChildScrollView(
child: Column(
children: <Widget>[
Container(
height: 30,
width: 160,
child: TextField(
decoration: InputDecoration(
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.blue,
),
borderRadius: BorderRadius.circular(10.0),
),
hintText: 'Name',
),
textAlign: TextAlign.center,
),
),
SizedBox(height: 20.0),
Container(
height: 30,
width: 160,
child: TextField(
decoration: InputDecoration(
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.blue,
),
borderRadius: BorderRadius.circular(10.0),
),
hintText: 'Surname',
),
textAlign: TextAlign.center,
),
),
SizedBox(height: 20.0),
Container(
height: 30,
width: 160,
child: TextField(
decoration: InputDecoration(
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.blue,
),
borderRadius: BorderRadius.circular(10.0),
),
hintText: 'Nationality',
),
textAlign: TextAlign.center,
),
),
],
),
),
),
),
],
),
),
),
);
}
}

I ended up wrapping everything with a Expanded widget and the column with the Text fields I wrapped it with a SingleChilsScrollView and it worked perfectly.

Related

flutter problem : How to make country image in circular?

I want to make a flag in circular. I am using "country_calling_code_picker: ^2.0.0" plugin and i got a image that image i want in circular. when I am trying to make in circular then its not becoming.
this is my code.
Row(
children: [
Expanded(
flex: 0,
child: Container(
decoration: BoxDecoration(
color: whiteColor.withOpacity(0.4),
border: Border(
bottom: BorderSide(
color:greyColor,
width: 1.7,
),
)
),
child: InkWell(onTap: (){
_onPressedShowBottomSheet();
},
child: Row(
children: [
Image.asset(
country.flag,
package: countryCodePackageName,
width: 40,
height: 50,
),SizedBox(width: 5,),
Icon(Icons.arrow_drop_down_sharp,size: 30,color: greyColor,)
],
),
),
),
),
SizedBox(
width: 15,
),
Expanded(
flex: 3,
child: Container( decoration: BoxDecoration(
color: whiteColor.withOpacity(0.4),
),
child: TextFormField(
cursorColor: Theme.of(context).cursorColor,
decoration: const InputDecoration(
hintText: "Enter Number",
enabledBorder: UnderlineInputBorder(
borderSide:
BorderSide(color:greyColor,width: 1.7),
), contentPadding: EdgeInsets.only(left: 12,right: 12),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: greyColor,width: 1.7),
),
),
),
),
),
],
),
I want to make like this my flag
But this is becoming like this
You can wrap your image in a ClipRRect.
Row(
children: [
Expanded(
flex: 0,
child: Container(
decoration: BoxDecoration(
color: whiteColor.withOpacity(0.4),
border: Border(
bottom: BorderSide(
color: greyColor,
width: 1.7,
),
)
),
child: InkWell(onTap: () {
_onPressedShowBottomSheet();
},
child: Row(
children: [
ClipRRect(
borderRadius: BorderRadius.circular(100),
Image.asset(
country.flag,
package: countryCodePackageName,
width: 40,
height: 50,
),
),
SizedBox(width: 5,),
Icon(Icons.arrow_drop_down_sharp, size: 30,
color: greyColor,)
],
),
),
),
),
SizedBox(
width: 15,
),
Expanded(
flex: 3,
child: Container(decoration: BoxDecoration(
color: whiteColor.withOpacity(0.4),
),
child: TextFormField(
cursorColor: Theme
.of(context)
.cursorColor,
decoration: const InputDecoration(
hintText: "Enter Number",
enabledBorder: UnderlineInputBorder(
borderSide:
BorderSide(color: greyColor, width: 1.7),
), contentPadding: EdgeInsets.only(left: 12, right: 12),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: greyColor, width: 1.7),
),
),
),
),
),
],
),

Unable to build center () and text() widget

I am working on my new app. While creating the login page, i faced some issue. My code works fine till a point and after that point or line, it stops building more widgets.
My code(working portion):
void main() => runApp(
MaterialApp(
debugShowCheckedModeBanner:false,
home: Background1(),
),
);
class Background1 extends StatelessWidget {
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold( //Whole screen
body: Container(
padding: EdgeInsets.all(20),
width: double.infinity,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
colors: [
Colors.purple.shade700,
Colors.purple.shade500,
Colors.purple.shade300,
],
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox (height: 80),
Padding(
padding: EdgeInsets.all(20),
child: Column(
children: <Widget>[
Text("LOGIN", style: TextStyle(color: Colors.white,fontSize: 40,fontWeight: FontWeight.bold)),
],
),
),
Expanded(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(topLeft: Radius.circular(20), topRight: Radius.circular(20),bottomLeft: Radius.circular(20),bottomRight: Radius.circular(20)),
color: Colors.transparent,
),
child: Padding(
padding: EdgeInsets.all(20),
child: Column(
children: <Widget>[
SizedBox(
height: 20,
),
Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
boxShadow: [BoxShadow(
color: Color.fromRGBO(225, 95, 27, 0.3),
blurRadius: 20,
offset: Offset(0,10),
)],
),
child: Column(
children: <Widget>[
Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
border: Border(bottom: BorderSide(color: Colors.grey[200])),
),
child: TextField(
decoration: InputDecoration(
hintText: "Email or phone number",
hintStyle: TextStyle(color: Colors.grey),
border: InputBorder.none,
),
),
),
SizedBox(height: 10),
Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
border: Border(bottom: BorderSide(color: Colors.grey[200])),
),
child: TextField(
decoration: InputDecoration(
hintText: "Password",
hintStyle: TextStyle(color: Colors.grey),
border: InputBorder.none,
),
),
),
],
),
),
SizedBox(height: 40),
Text("Forgot Password?", style: TextStyle(color: Colors.white)),
SizedBox(height: 40),
Container(
height: 40,
margin: EdgeInsets.symmetric(horizontal: 50),
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.purple.shade800,
borderRadius: BorderRadius.circular(20)),
child: Center(
child: Text("LOGIN", style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
),
),
],
),
),
),
),
],
),
),
),
);
}
}
Couldn't able to create center() and Text() widget, which is at the end of the code.
child: Text("LOGIN", style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
),
),
And also it doesn't build widgets as i write further. I've attached an image showing my emulator where it doesn't show LOGIN in white color on the purple button. enter image description here
just remove the padding of the container and it will work fine.
code after removing the container padding:
void main() => runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
home: Background1(),
),
);
class Background1 extends StatelessWidget {
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
//Whole screen
body: Container(
padding: EdgeInsets.all(20),
width: double.infinity,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
colors: [
Colors.purple.shade700,
Colors.purple.shade500,
Colors.purple.shade300,
],
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(height: 80),
Padding(
padding: EdgeInsets.all(20),
child: Column(
children: <Widget>[
Text("LOGIN",
style: TextStyle(
color: Colors.white,
fontSize: 40,
fontWeight: FontWeight.bold)),
],
),
),
Expanded(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20),
bottomLeft: Radius.circular(20),
bottomRight: Radius.circular(20)),
color: Colors.transparent,
),
child: Padding(
padding: EdgeInsets.all(20),
child: Column(
children: <Widget>[
SizedBox(
height: 20,
),
Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color: Color.fromRGBO(225, 95, 27, 0.3),
blurRadius: 20,
offset: Offset(0, 10),
)
],
),
child: Column(
children: <Widget>[
Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
border: Border(
bottom:
BorderSide(color: Colors.grey[200])),
),
child: TextField(
decoration: InputDecoration(
hintText: "Email or phone number",
hintStyle: TextStyle(color: Colors.grey),
border: InputBorder.none,
),
),
),
SizedBox(height: 10),
Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
border: Border(
bottom:
BorderSide(color: Colors.grey[200])),
),
child: TextField(
decoration: InputDecoration(
hintText: "Password",
hintStyle: TextStyle(color: Colors.grey),
border: InputBorder.none,
),
),
),
],
),
),
SizedBox(height: 40),
Text("Forgot Password?",
style: TextStyle(color: Colors.white)),
SizedBox(height: 40),
Container(
height: 40,
margin: EdgeInsets.symmetric(horizontal: 50),
decoration: BoxDecoration(
color: Colors.purple.shade800,
borderRadius: BorderRadius.circular(20)),
child: Center(
child: Text("LOGIN",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold)),
),
),
],
),
),
),
),
],
),
),
),
);
}
}
You might be using all of the space on the screen, rather then using a column use a listview, this will allow you to scroll. Additionally Listview.builder will allow you to build the children of the list view dynamically.
checkout https://api.flutter.dev/flutter/widgets/ListView-class.html for info on the listview class

How to style this kind of Text Field

I want to style this kind of TextField.
The main problem that I'm facing is to design the US$ part in leading the TextField. This is my code so far.
/// My Place Bid Text Field
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.circular(4),
),
child: Row(
mainAxisSize: MainAxisSize.max,
children: [
SizedBox(
child: Container(
//width: mySize.width * 0.2,
//height: 50,
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(4),
bottomLeft: Radius.circular(4),
),
color: Colors.grey[200]),
child: Text(
"RS \u20B9",
style: TextStyle(fontSize: 24),
),
),
),
Expanded(
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
labelText: "Place Bid",
labelStyle: TextStyle(fontSize: 24)),
),
),
],
),
),
Which gives me output
I know this question is not that complicated, but I'm still relatively new to flutter so your help would be much appreciated.
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Sample"),
),
body: Padding(
padding: EdgeInsets.all(10),
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.grey[500],
),
borderRadius: BorderRadius.all(Radius.circular(8))),
width: double.infinity,
height: 50,
child: Row(
children: <Widget>[
Container(
padding: EdgeInsets.all(10),
color: Colors.grey.shade300,
height: 50,
child: Align(
alignment: Alignment.center,
child: Text(
"RS \u20B9",
style: TextStyle(
fontSize: 24, fontWeight: FontWeight.bold),
),
)),
SizedBox(
width: 10,
),
Expanded(
child: Container(
height: 50,
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: "Enter Bid",
labelStyle: TextStyle(fontSize: 24)),
)))
],
),
),
));
}
Output
You can use the prefixIcon to add a widget at the beginning of the textfield:
Container(
child: Row(
children: [
Expanded(
child: TextField(
decoration: InputDecoration(
prefixIcon: Padding(
padding: const EdgeInsetsDirectional.only(start: 2.0),
child: Container(
padding: const EdgeInsets.all(13),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(4),
bottomLeft: Radius.circular(4),
),
color: Colors.grey[200]),
child: Text(
"RS \u20B9",
style: TextStyle(fontSize: 24),
),
),
),
border: const OutlineInputBorder(),
labelText: 'Hint Text',
),
),
),
],
),
)
example:
https://dartpad.dev/a89aff20d67e2cb31da6a07ba7c17910
Based on your solution.
Notice the "IntrinsicHeight" widget. It makes all the children inside the child the same size (depending on the biggest one). The "Center" widget inside the prefix makes the Container go max height + center the text inside of it. Just make sure not to use IntrinsicHeight too much, since the docs state that it's a bit resource heavy.
Container(
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
border: Border.all(color: Colors.grey[200]),
),
child: IntrinsicHeight(
child: Row(
children: <Widget>[
Container(
padding: EdgeInsets.symmetric(horizontal: 10.0),
decoration: BoxDecoration(
color: Colors.grey[100],
border: Border(
right: BorderSide(color: Colors.grey[200]),
),
),
child: Center(
child: Text(
'RS \u20B9',
style: TextStyle(fontSize: 24),
),
),
),
Expanded(
child: TextField(
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(horizontal: 20.0, vertical: 10.0),
border: InputBorder.none,
labelText: "Place Bid",
),
),
),
],
),
),
),
The second code is almost the same, except there's no label after typing the text inside the TextField.
Container(
margin: EdgeInsets.symmetric(horizontal: 20.0),
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
border: Border.all(color: Colors.grey[200]),
),
child: IntrinsicHeight(
child: Row(
children: <Widget>[
Container(
padding: EdgeInsets.symmetric(horizontal: 10.0),
decoration: BoxDecoration(
color: Colors.grey[100],
border: Border(
right: BorderSide(color: Colors.grey[200]),
),
),
child: Center(
child: Text(
'RS \u20B9',
style: TextStyle(fontSize: 24),
),
),
),
Expanded(
child: TextField(
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(
horizontal: 20.0,
vertical: 20.0,
),
border: InputBorder.none,
hintText: "Place Bid",
),
),
),
],
),
),
),
Container(
decoration: BoxDecoration(
),
child: Row(
mainAxisSize: MainAxisSize.max,
children: [
SizedBox(
child: Container(
//width: mySize.width * 0.2,
//height: 50,
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
border:Border.all(color:Colors.grey),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(4),
bottomLeft:Radius.circular(4),
),
color: Colors.grey[200]),
child: Text(
"RS \u20B9",
style: TextStyle(fontSize: 24),
),
),
),
Expanded(
child: TextField(
decoration: InputDecoration(
border: new OutlineInputBorder(
borderRadius: BorderRadius.only(
topRight: Radius.circular(4),
bottomRight:
Radius.circular(4),
),
),
isDense: true,
labelText: "Place Bid",
labelStyle:
TextStyle(fontSize:24)),
),
),
],
),
),

Flutter :- How to scroll the sceen without shrink the screen on the Stack view?(Scroll the the whole screen when the keyboard appears )

Description I am creating the login screen in which I have used the Stack widget, Currently, everything works fine but only one issue of the shrinking the view. When I use the resizeToAvoidBottomPadding: false inside the Scaffold then screen shrinking disappear but another problem arise that whole screen scroll not working, please check below lines of code
class _LoginScreen extends State<LoginScreen> {
#override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
resizeToAvoidBottomPadding: false,
body: Stack(
children: <Widget>[
Container(
height: double.infinity,
width: double.infinity,
child: Column(
children: <Widget>[
Expanded(
flex: 4,
child: Column(
children: <Widget>[
Expanded(
flex: 9,
child: Container(
color: Colors.blue,
child: Align(
alignment: Alignment.centerLeft,
child: RotatedBox(
quarterTurns: 3,
child: Container(
child: Padding(
padding: EdgeInsets.all(5),
child: Text(
"Login !!",
style: TextStyle(
fontSize: 30.0,
color: Colors.white),
),
),
),
),
)),
),
Expanded(
flex: 1,
child: Container(
color: Colors.white,
),
)
],
)),
Expanded(
flex: 6,
child: Container(
color: Colors.white,
),
)
],
),
),
Padding(
padding: EdgeInsets.only(left: 20.0, right: 20.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Image(
image: new AssetImage("images/logo.png"),
color: null,
height: 100.0,
width: 100.0,
fit: BoxFit.scaleDown,
alignment: Alignment.center,
),
SizedBox(
height: 20.0,
),
TextField(
keyboardType: TextInputType.number,
inputFormatters: [
LengthLimitingTextInputFormatter(10),
],
decoration: new InputDecoration(
focusedBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Colors.blue, width: 2.0),
),
enabledBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Colors.grey, width: 2.0),
),
hintText: "Please enter mobile number")),
SizedBox(
height: 10.0,
),
TextField(
obscureText: true,
inputFormatters: [
LengthLimitingTextInputFormatter(16),
],
keyboardType: TextInputType.visiblePassword,
decoration: new InputDecoration(
focusedBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Colors.blue, width: 2.0),
),
enabledBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Colors.grey, width: 2.0),
),
hintText: "Password")),
SizedBox(
height: 3.0,
),
Align(
alignment: Alignment.topRight,
child: Text(
"Forgot Password?",
style: TextStyle(fontSize: 12.0),
)),
SizedBox(
height: 3.0,
),
SizedBox(
height: 10.0,
),
RaisedButton(
onPressed: () {},
color: Colors.blue,
child: const Text(
'Login',
style: TextStyle(fontSize: 15.0, color: Colors.black45),
),
)
],
),
),
],
));
}
}
From Above code, I am getting the following screen
I have used the ListView and SingleChildScrollView but it not working properly, please check my code with SingleChildScrollView, which i have tried
class _LoginScreen extends State<LoginScreen> {
#override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
resizeToAvoidBottomPadding: false,
body: SingleChildScrollView(
child: IntrinsicHeight(
child: Stack(
children: <Widget>[
Container(
height: double.infinity,
width: double.infinity,
child: Column(
children: <Widget>[
Expanded(
flex: 4,
child: Column(
children: <Widget>[
Expanded(
flex: 9,
child: Container(
color: Colors.blue,
child: Align(
alignment: Alignment.centerLeft,
child: RotatedBox(
quarterTurns: 3,
child: Container(
child: Padding(
padding: EdgeInsets.all(5),
child: Text(
"Login !!",
style: TextStyle(
fontSize: 30.0,
color: Colors.white),
),
),
),
),
)),
),
Expanded(
flex: 1,
child: Container(
color: Colors.white,
),
)
],
)),
Expanded(
flex: 6,
child: Container(
color: Colors.white,
),
)
],
),
),
Padding(
padding: EdgeInsets.only(left: 20.0, right: 20.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Image(
image: new AssetImage("images/logo.png"),
color: null,
height: 100.0,
width: 100.0,
fit: BoxFit.scaleDown,
alignment: Alignment.center,
),
SizedBox(
height: 20.0,
),
TextField(
keyboardType: TextInputType.number,
inputFormatters: [
LengthLimitingTextInputFormatter(10),
],
decoration: new InputDecoration(
focusedBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Colors.blue, width: 2.0),
),
enabledBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Colors.grey, width: 2.0),
),
hintText: "Please enter mobile number")),
SizedBox(
height: 10.0,
),
TextField(
obscureText: true,
inputFormatters: [
LengthLimitingTextInputFormatter(16),
],
keyboardType: TextInputType.visiblePassword,
decoration: new InputDecoration(
focusedBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Colors.blue, width: 2.0),
),
enabledBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Colors.grey, width: 2.0),
),
hintText: "Password")),
SizedBox(
height: 3.0,
),
Align(
alignment: Alignment.topRight,
child: Text(
"Forgot Password?",
style: TextStyle(fontSize: 12.0),
)),
SizedBox(
height: 3.0,
),
SizedBox(
height: 10.0,
),
RaisedButton(
onPressed: () {},
color: Colors.blue,
child: const Text(
'Login',
style: TextStyle(fontSize: 15.0, color: Colors.black45),
),
)
],
),
),
],
)),
));
}
}
And From the above code getting this result by using the SingleChildScrollView
Problem:- I want to scroll the whole screen when the keyboard appears, I have used all the Listview and SingleChildScrollView but not getting the solution, please help me on it. Thanks
The problem is you're using Expanded widgets, you see expanded widgets are flexible in nature they will consume and shrink according to the available space. If you don't want that you need to specify a height.
https://i.imgur.com/wVgAUlN.mp4
class StacScroll extends StatefulWidget {
StacScroll({Key key}) : super(key: key);
#override
_StacScrollState createState() => _StacScrollState();
}
class _StacScrollState extends State<StacScroll> {
#override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: true,
body: Container(
height: double.infinity,
width: double.infinity,
// margin:
// EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
child: SingleChildScrollView(
child: Stack(
children: <Widget>[
Container(
color: Colors.blue,
height: MediaQuery.of(context).size.height * 0.3,
width: MediaQuery.of(context).size.width,
child: RotatedBox(
quarterTurns: 3,
child: Container(
child: Padding(
padding: EdgeInsets.all(5),
child: Text(
"Login !!",
style:
TextStyle(fontSize: 30.0, color: Colors.white),
),
),
)),
),
Container(
margin: EdgeInsets.only(
top: MediaQuery.of(context).size.height * 0.3),
child: Padding(
padding: EdgeInsets.only(left: 20.0, right: 20.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Image(
image: new AssetImage("images/logo.png"),
color: null,
height: 100.0,
width: 100.0,
fit: BoxFit.scaleDown,
alignment: Alignment.center,
),
SizedBox(
height: 20.0,
),
TextField(
keyboardType: TextInputType.number,
decoration: new InputDecoration(
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.blue, width: 2.0),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.grey, width: 2.0),
),
hintText: "Please enter mobile number")),
SizedBox(
height: 10.0,
),
TextField(
obscureText: true,
keyboardType: TextInputType.visiblePassword,
decoration: new InputDecoration(
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.blue, width: 2.0),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.grey, width: 2.0),
),
hintText: "Password")),
SizedBox(
height: 3.0,
),
Align(
alignment: Alignment.topRight,
child: Text(
"Forgot Password?",
style: TextStyle(fontSize: 12.0),
)),
SizedBox(
height: 3.0,
),
SizedBox(
height: 10.0,
),
RaisedButton(
onPressed: () {},
color: Colors.blue,
child: const Text(
'Login',
style: TextStyle(
fontSize: 15.0, color: Colors.black45),
),
)
],
),
),
),
],
),
),
));
}
}
Thanks #Nadeem by which problem has resolved
Whenever we want to scroll the full screen when keyboard appear then we should not use the Expand widget for it.I was also doing the same mistake, for the other user i have modified the code for full scroll when keyboard appear, I have used the MediaQuery for it,Please check my below code of it.
import 'package:flutter/material.dart';
class LoginScreen extends StatefulWidget {
#override
State<StatefulWidget> createState() {
// TODO: implement createState
return _LoginScreen();
}
}
class _LoginScreen extends State<LoginScreen> {
#override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
appBar: AppBar(
title: Text("Login"),
),
body: Container(
height: double.infinity,
width: double.infinity,
child: SingleChildScrollView(
child: Stack(
children: <Widget>[
Container(
color: Colors.blue,
height: MediaQuery.of(context).size.height * 0.3,
),
Container(
color: Colors.white,
height: MediaQuery.of(context).size.height * 0.59,
padding: EdgeInsets.all(10.0),
margin: EdgeInsets.only(
top: MediaQuery.of(context).size.height * 0.3),
child: Container(
margin: EdgeInsets.only(top: 70.0),
child: Column(
children: <Widget>[
TextFormField(
decoration: InputDecoration(
labelText: 'Enter your username')),
TextFormField(
decoration: InputDecoration(labelText: 'Password')),
SizedBox(
height: 20.0,
),
RaisedButton(
color: Colors.yellow,
child: Text("Submit",
style: TextStyle(color: Colors.blue)),
onPressed: () {},
)
],
),
)),
Center(
child: Card(
color: Colors.yellow,
elevation: 8,
margin: EdgeInsets.only(
top: MediaQuery.of(context).size.height * .25),
child: Container(
child: Center(
child: Text(
"Radhe",
style: TextStyle(color: Colors.blue, fontSize: 20.0),
)),
height: MediaQuery.of(context).size.height * .1,
width: MediaQuery.of(context).size.width * .3,
),
),
)
],
),
),
),
);
}
}
Please check the output of it.

Flutter Navigation undefined "context"

I´m new to flutter and dart and I´m trying to build a Sign up for an app.
I got a start screen (StartPage) with options "login", "login FB", "sign up with email".
When I hit "login" I can navigate to the signup_email_screen. From there I want to navigate to the signup_email_screen_two but it throws "undefined name context".
class StartPage extends StatefulWidget {
#override
_StartPageState createState() => _StartPageState();
}
class _StartPageState extends State<StartPage> {
bool isAuth = false; //isAuth provides a bool if the user is already signed in
Widget buildAuthScreen() {
return Text('Angemeldet');
}
Scaffold buildUnAuthScreen() {
return Scaffold(
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/tenor.gif'),
fit: BoxFit.cover)),
alignment: Alignment.center,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(height: SizeConfig.blockSizeVertical * 10),
Container(
width: SizeConfig.blockSizeHorizontal * 65,
height: SizeConfig.blockSizeVertical * 20,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/Insta_transparent.png'),
fit: BoxFit.scaleDown,
),
),
),
SizedBox(height: SizeConfig.blockSizeVertical * 0),
Text(
'Nie mehr Langeweile',
style: TextStyle(
fontFamily: "Signatra",
fontSize: SizeConfig.blockSizeHorizontal *8,
color: Colors.white,
),
),
SizedBox(height: SizeConfig.blockSizeVertical * 7),
GestureDetector(
onTap: () => _navigateToLogin(context),
child: Container(
width: SizeConfig.blockSizeHorizontal * 70,
height: SizeConfig.blockSizeVertical * 7,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/Log_In_Button.png'),
fit: BoxFit.scaleDown,
),
),
)),
SizedBox(height: SizeConfig.blockSizeVertical * 2),
GestureDetector(
onTap: () => print('facebook signin'),
child: Container(
width: SizeConfig.blockSizeHorizontal * 70,
height: SizeConfig.blockSizeVertical * 7,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/Log_In_Button_FB.png'),
fit: BoxFit.scaleDown,
),
),
),
),
SizedBox(height: SizeConfig.blockSizeVertical * 2),
GestureDetector(
onTap: () => _navigateToEmailRegister(context),
child: Container(
width: SizeConfig.blockSizeHorizontal * 60,
height: SizeConfig.blockSizeVertical *7,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
'assets/images/button-email-registration.png'),
fit: BoxFit.scaleDown,
),
),
),
),
],
),
),
);
}
void _navigateToLogin(BuildContext context) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => LoginScreen(),
));
}
void _navigateToEmailRegister(BuildContext context) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SignupEmailScreen(),
));
}
#override
Widget build(BuildContext context) {
SizeConfig().init(context);
return isAuth ? buildAuthScreen() : buildUnAuthScreen();
}
}
class SignupEmailScreen extends StatelessWidget {
Scaffold signupEmailScreen() {
return Scaffold(
body: Stack(
children: [
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/StartPage_Background.jpg'),
fit: BoxFit.cover)),
alignment: Alignment.center,
),
//AppBar transparent and background full screen with Stack and Positioned
Positioned(
top: 0.0,
left: 0.0,
right: 0.0,
child: AppBar(
title: Text('Registrierung'),
backgroundColor: Colors.transparent, //transparent
elevation: 0.0, //Shadow gone
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
SizedBox(height: SizeConfig.blockSizeVertical * 15),
//Insta image
Container(
width: SizeConfig.blockSizeHorizontal * 50,
height: SizeConfig.blockSizeVertical * 10,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/Insta_transparent.png'),
fit: BoxFit.scaleDown,
),
),
),
SizedBox(height: SizeConfig.blockSizeVertical * 7),
//Email text field
Padding(
padding: EdgeInsets.symmetric(
horizontal: SizeConfig.safeBlockHorizontal * 5),
child: TextField(
keyboardType: TextInputType.text,
style: TextStyle(color: Colors.white, fontSize: 20.0),
decoration: InputDecoration(
labelText: "Accountname",
labelStyle: TextStyle(
color: Colors.white,
),
hasFloatingPlaceholder: true,
enabledBorder: UnderlineInputBorder(
//Enables the border to change color
borderSide:
BorderSide(color: Colors.white, width: 2.0)),
focusedBorder: UnderlineInputBorder(
borderSide:
BorderSide(color: Colors.white, width: 2.0)),
),
),
),
//Password text field
Padding(
padding: EdgeInsets.symmetric(
horizontal: SizeConfig.safeBlockHorizontal * 5),
child: TextField(
keyboardType: TextInputType.emailAddress,
style: TextStyle(color: Colors.white, fontSize: 20.0),
decoration: InputDecoration(
labelText: "Email",
labelStyle: TextStyle(
color: Colors.white,
),
hasFloatingPlaceholder: true,
enabledBorder: UnderlineInputBorder(
//Enables the border to change color
borderSide:
BorderSide(color: Colors.white, width: 2.0)),
focusedBorder: UnderlineInputBorder(
borderSide:
BorderSide(color: Colors.white, width: 2.0)),
),
),
),
Padding(
padding: EdgeInsets.symmetric(
horizontal: SizeConfig.safeBlockHorizontal * 5),
child: TextField(
keyboardType: TextInputType.visiblePassword,
style: TextStyle(color: Colors.white, fontSize: 20.0),
decoration: InputDecoration(
labelText: "Passwort",
labelStyle: TextStyle(
color: Colors.white,
),
hasFloatingPlaceholder: true,
enabledBorder: UnderlineInputBorder(
//Enables the border to change color
borderSide:
BorderSide(color: Colors.white, width: 2.0)),
focusedBorder: UnderlineInputBorder(
borderSide:
BorderSide(color: Colors.white, width: 2.0)),
),
),
),
Padding(
padding: EdgeInsets.symmetric(
horizontal: SizeConfig.safeBlockHorizontal * 5),
child: TextField(
keyboardType: TextInputType.visiblePassword,
style: TextStyle(color: Colors.white, fontSize: 20.0),
decoration: InputDecoration(
labelText: "Passwort wiederholen",
labelStyle: TextStyle(
color: Colors.white,
),
hasFloatingPlaceholder: true,
enabledBorder: UnderlineInputBorder(
//Enables the border to change color
borderSide:
BorderSide(color: Colors.white, width: 2.0)),
focusedBorder: UnderlineInputBorder(
borderSide:
BorderSide(color: Colors.white, width: 2.0)),
),
),
),
SizedBox(height: SizeConfig.blockSizeVertical * 10),
//log in button
GestureDetector(
onTap: () => _navigateToSignupEmailScreenTwo(context),
child: Container(
width: SizeConfig.blockSizeHorizontal * 70,
height: SizeConfig.blockSizeVertical * 7,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/Log_In_Button.png'),
fit: BoxFit.scaleDown,
),
),
)),
],
),
],
),
);
}
//ACTIONS
void _navigateToSignupEmailScreenTwo(BuildContext context) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SignupEmailScreenTwo(),
));
}
//BUILD
#override
Widget build(BuildContext context) {
return signupEmailScreen();
}
}
class SignupEmailScreenTwo extends StatelessWidget {
Scaffold signupEmailScreenTwo() {
return Scaffold(
body: Stack(
children: [
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/StartPage_Background.jpg'),
fit: BoxFit.cover)),
alignment: Alignment.center,
),
//AppBar transparent and background full screen with Stack and Positioned
Positioned(
top: 0.0,
left: 0.0,
right: 0.0,
child: AppBar(
title: Text('Registrierung'),
backgroundColor: Colors.transparent, //transparent
elevation: 0.0, //Shadow gone
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
SizedBox(height: SizeConfig.blockSizeVertical * 15),
Container(
width: SizeConfig.blockSizeHorizontal * 50,
height: SizeConfig.blockSizeVertical * 10,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/Insta_transparent.png'),
fit: BoxFit.scaleDown,
),
),
),
SizedBox(height: SizeConfig.blockSizeVertical * 7),
//Email text field
Padding(
padding: EdgeInsets.symmetric(
horizontal: SizeConfig.safeBlockHorizontal * 5),
child: TextField(
keyboardType: TextInputType.text,
style: TextStyle(color: Colors.white, fontSize: 20.0),
decoration: InputDecoration(
labelText: "Dein Vorname",
labelStyle: TextStyle(
color: Colors.white,
),
hasFloatingPlaceholder: true,
enabledBorder: UnderlineInputBorder(
//Enables the border to change color
borderSide:
BorderSide(color: Colors.white, width: 2.0)),
focusedBorder: UnderlineInputBorder(
borderSide:
BorderSide(color: Colors.white, width: 2.0)),
),
),
),
//Password text field
Padding(
padding: EdgeInsets.symmetric(
horizontal: SizeConfig.safeBlockHorizontal * 5),
child: TextField(
keyboardType: TextInputType.datetime,
style: TextStyle(color: Colors.white, fontSize: 20.0),
decoration: InputDecoration(
labelText: "Dein Geburtsdatum",
labelStyle: TextStyle(
color: Colors.white,
),
hasFloatingPlaceholder: true,
enabledBorder: UnderlineInputBorder(
//Enables the border to change color
borderSide:
BorderSide(color: Colors.white, width: 2.0)),
focusedBorder: UnderlineInputBorder(
borderSide:
BorderSide(color: Colors.white, width: 2.0)),
),
),
),
SizedBox(height: SizeConfig.blockSizeVertical * 10),
//log in button
GestureDetector(
onTap: () => print("Einlogggggeeeeeen"),
child: Container(
width: SizeConfig.blockSizeHorizontal * 70,
height: SizeConfig.blockSizeVertical * 7,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/Log_In_Button.png'),
fit: BoxFit.scaleDown,
),
),
)),
],
),
],
),
);
}
#override
Widget build(BuildContext context) {
return signupEmailScreenTwo();
}
}
Why is the context undefined?
Appreciate any help!
Because context undefined inside your function :)
**Edit: ** You cant reach context object inside StatelessWidget
These are what you can do:
1- Use StatefulWidget instead of StatelessWidget,
2- You can pass BuildContext context as a parameter into your functions.
3- You can write all widgets inside build method instead of extra function.