How can I display the error message in a seperate snackbar or toast in Flutter? - flutter

This is my very first question if I make a faux pas kindly correct me :)
Coding in : Android Studio
Language is: Flutter/Dart
Question: How do I display the error message that is displayed just under the textformfield in a separate toast/snack bar/flush bar ?
Video-Link of the issue : https://youtu.be/4hJtR11o1GU
Code:
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
//import 'package:video_player/video_player.dart';
class LoginForm extends StatefulWidget {
LoginForm(this.submitFn, this.isLoading);
final bool isLoading;
final void Function(
String email,
String password,
String mobile,
bool isLogin,
BuildContext ctx,
) submitFn;
#override
_LoginFormState createState() => _LoginFormState();
}
class _LoginFormState extends State<LoginForm> {
final _formKey = GlobalKey<FormState>();
var _isLogin = true;
String _userEmail = '';
String _userPassword = '';
String _userMobile = '';
void _trySubmit() {
final isValid = _formKey.currentState.validate();
FocusScope.of(context).unfocus();
if (isValid) {
_formKey.currentState.save();
widget.submitFn(
_userEmail.trim(),
_userPassword.trim(),
_userMobile.trim(),
_isLogin,
context
);
}
}
Widget _buildEmailTF() {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
alignment: Alignment.centerLeft,
height: 50.0,
child: TextFormField(
key: ValueKey('email'),
validator: (value) { if (value.isEmpty || !value.contains('#')) {return
'enter a valid email';} return null;},
keyboardType: TextInputType.emailAddress,
style: TextStyle(color: Colors.white, fontFamily: 'OpenSans',),
decoration: InputDecoration(
isDense: true,
hintText: 'username#xyz.com',
hintStyle: TextStyle(color: Colors.white, ),
contentPadding: EdgeInsets.only(top: 14.0),
errorMaxLines: 1,
errorText: 'Null',
errorStyle: TextStyle(
color: Colors.transparent,
fontSize: 0,
),
prefixIcon: Icon(
Icons.email,
color: Colors.orange ,
),
),
onSaved:(value){_userEmail = value;},
),
),
],
);
}
Widget _buildMobileTF() {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
alignment: Alignment.centerLeft,
height: 50.0,
child: TextFormField(
key: ValueKey('mobile'),
validator: (value) { if (value.isEmpty || !value.contains('91') || value.length > 12 || value.length < 12) {
return '';} return null;},
keyboardType: TextInputType.number,
style: TextStyle(
color: Colors.white,
fontFamily: 'OpenSans',
),
decoration: InputDecoration(
errorMaxLines: 1,
errorText: 'Null',
errorStyle: TextStyle(
color: Colors.transparent,
fontSize: 0,
),
hintText: '91 xxx-xxx-xxxx',
hintStyle: TextStyle(color: Colors.white, ),
border: InputBorder.none,
contentPadding: EdgeInsets.only(top: 14.0),
prefixIcon: Icon(
Icons.phone_android,
color: Colors.orange,
),
),
onSaved:(value){_userMobile = value;},
),
),
],
);
}
Widget _buildPasswordTF() {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(height: 10.0),
Container(
alignment: Alignment.centerLeft,
height: 60.0,
child: TextFormField(
key: ValueKey('password'),
validator: (value) {if (value.isEmpty || value.length < 7) {
return '';} return null;},
obscureText: true,
style: TextStyle(
color: Colors.white,
fontFamily: 'OpenSans',
),
decoration: InputDecoration(
errorMaxLines: 1,
errorText: 'Null',
errorStyle: TextStyle(
color: Colors.transparent,
fontSize: 0,
),
contentPadding: EdgeInsets.only(top: 14.0),
prefixIcon: Icon(
Icons.lock,
color: Colors.orange,
),
hintText: 'Password',
hintStyle: TextStyle(color: Colors.white, )
),
onSaved:(value){
_userPassword = value;
},
),
),
],
);
}
Widget _buildLoginBtn() {
return Container(
padding: EdgeInsets.symmetric(vertical: 25.0),
width: double.infinity,
child: RaisedButton(
onPressed: _trySubmit,
elevation: 5.0,
padding: EdgeInsets.all(15.0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
),
color: Colors.white,
child: Text(_isLogin ? 'Login In' : 'Sign Up',
style: TextStyle(
color: Colors.orange,
letterSpacing: 1.5,
fontSize: 18.0,
fontWeight: FontWeight.bold,
fontFamily: 'OpenSans',
),
),
),
);
}
Widget _buildSignUpWithText() {
return Column(
children: <Widget>[
FlatButton(
textColor: Theme.of(context).primaryColor,
child: Text(_isLogin ? 'Sign Up With An Email Account' : 'I Already Have An Account',
style: TextStyle(
color: Colors.orange,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
onPressed: () {
setState(() {
_isLogin = !_isLogin;
});
},
),
SizedBox(height: 20.0),
Text(
'- OR -',
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
],
);
}
Widget _buildSocialBtn(Function onTap, AssetImage logo) {
return GestureDetector(
onTap: (){
setState(() {
});
_isLogin = !_isLogin;
},
child: Container(
height: 60.0,
width: 60.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black26,
offset: Offset(0, 2),
blurRadius: 6.0,
),
],
image: DecorationImage(
image: logo,
),
),
),
);
}
Widget _buildSocialBtnRow() {
return Padding(
padding: EdgeInsets.symmetric(vertical: 30.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
_buildSocialBtn(
() => print('Sign Up with Google'),
AssetImage(
'assets/logos/google.jpg',
),
),
],
),
);
}
Widget _buildHomeChefSignUp() {
return GestureDetector(onTap: () => print('Chef\'s Sign Up Process'),
child: RichText(
text: TextSpan(
children: [
TextSpan(text: 'Passionate About Cooking ? ',
style: TextStyle(
color: Colors.white,
fontSize: 12.0,
fontWeight: FontWeight.w400,
),),
TextSpan(text: 'Join Us',
style: TextStyle(
color: Colors.orange,
fontSize: 12.0,
fontWeight: FontWeight.w400,
),),
])),
);
}
#override
Widget build(BuildContext context) {
//Keeps Back Ground Fixed even with Keyboard Opened
return Scaffold(resizeToAvoidBottomPadding: false,
//Top Status Bar Overlay Dark or Light
body: AnnotatedRegion<SystemUiOverlayStyle>(value: SystemUiOverlayStyle.light,
child: GestureDetector(onTap: ()=>FocusScope.of(context).unfocus(),
//Main Tree holding All the necessary Containers
child: Stack(children: <Widget>[
//Holds the background Video
Container(),
//Creates a black overlay to the background
Container(
height: double.infinity,
color: Colors.black.withAlpha(120),),
//Hold the Login Form
Container(
height: double.infinity,
child: SingleChildScrollView(
physics: AlwaysScrollableScrollPhysics(),
padding: EdgeInsets.symmetric(horizontal: 40.0, vertical: 100.0,),
child: Form(
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Mother\'s Kitchen',
style: TextStyle(
color: Colors.orange,
fontFamily: 'MomsFonts',
fontSize: 40.0,
fontWeight: FontWeight.bold,),),
SizedBox(height: 10.0),
Text(
'Mumbai\'s First & Only Home Cooked Delivery Service',
style: TextStyle(
color: Colors.orange,
fontFamily: 'OpenSans',
fontSize: 12.0,
fontWeight: FontWeight.bold,),),
SizedBox(height: 30.0),
_buildEmailTF(),
SizedBox(height: 10.0,),
if(!_isLogin)
_buildMobileTF(),
_buildPasswordTF(),
if(widget.isLoading)
Column(
children: <Widget>[
SizedBox(height: 10.0),
CircularProgressIndicator(),
],
),
if(!widget.isLoading)
_buildLoginBtn(),
_buildSignUpWithText(),
_buildSocialBtnRow(),
_buildHomeChefSignUp(),
],),
),),
),],
),),
),);
}
}

Related

Error: Undefined name 'isRememberMe' Error: Required named parameter 'onChanged' must be provided

When I'm trying to define isRememberme widget, some errors occurred. I'm trying to build a login app UI using flutter and android studio. I'm very new to this and struggling to find the error. I have highlighted the code that gives me error.
bool isRememberMe =false; //
class LoginScreen extends StatefulWidget {
#override
_LoginScreenState createState() => _LoginScreenState();
}
Widget buildEmail() {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Email',
style: TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight:
FontWeight.bold
),
),
SizedBox(height: 10),
Container(
alignment: Alignment.centerLeft,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
boxShadow: [
BoxShadow(
color: Colors.black26,
blurRadius: 6,
offset: Offset(0, 2)
)
]
),
height: 60,
child: TextField(
keyboardType: TextInputType.emailAddress,
style: TextStyle(color: Colors.black87),
decoration: InputDecoration(
border: InputBorder.none,
contentPadding: EdgeInsets.only(top: 14),
prefixIcon: Icon(
Icons.email,
color: Color(0xff5ac18e),
),
hintText: 'Email',
hintStyle: TextStyle(color: Colors.black38)),
)
)
],
);
}
///////////////////////////////
Widget buildPassword() {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Password',
style: TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight:
FontWeight.bold
),
),
SizedBox(height: 10),
Container(
alignment: Alignment.centerLeft,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
boxShadow: [
BoxShadow(
color: Colors.black26,
blurRadius: 6,
offset: Offset(0, 2)
)
]
),
height: 60,
child: TextField(
obscureText: true,
style: TextStyle(color: Colors.black87),
decoration: InputDecoration(
border: InputBorder.none,
contentPadding: EdgeInsets.only(top: 14),
prefixIcon: Icon(
Icons.lock,
color: Color(0xff5ac18e),
),
hintText: 'Password',
hintStyle: TextStyle(color: Colors.black38)),
)
)
],
);
}
Widget buildForgotPassBtn(){
return Container(
alignment: Alignment.centerRight,
child: TextButton(
onPressed: () => print("Forget Password pressed"),
// padding: EdgeInsets.only(right:0),
child: Text(
'Forgot Passsword?',
style: TextStyle(
color: Colors.white,
fontWeight : FontWeight.bold
),
),
),
);
}
**Widget buildRememberCb(){
return Container(
height: 20,
child: Row(
children: <Widget>[
Theme(
data: ThemeData(unselectedWidgetColor :Colors.white),
child: Checkbox(
value: isRememberMe,
),
)
],
),
)
}
class _LoginScreenState extends State<LoginScreen> {
bool isRememberMe =false;**
#override
Widget build(BuildContext context) {
return Scaffold(
body: AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle.light,
child: GestureDetector(
child: Stack(
children: <Widget>[
Container(
height: double.infinity,
width: double.infinity,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color(0x665ac18e),
Color(0x995ac18e),
Color(0xcc5ac18e),
Color(0xff5ac18e),
]
)
),
child: SingleChildScrollView(
physics: AlwaysScrollableScrollPhysics(),
padding: EdgeInsets.symmetric(
horizontal: 25,
vertical: 120,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Sign In',
style: TextStyle(
color: Colors.white,
fontSize: 40,
fontWeight: FontWeight.bold),
),
SizedBox(height: 50),
buildEmail(),
SizedBox(height: 20),
buildPassword(),
buildForgotPassBtn(),
buildRememberCb(),
],
),
),
),
],
),
),
),
);
}
}
Move your buildRememberCb method to your _LoginScreenState class so you can use setState method as within the on change method of CheckBox widget.
Widget buildRememberCb({bool isRememberMe : false}){
return Container(
height: 20,
child: Row(
children: <Widget>[
Theme(
data: ThemeData(unselectedWidgetColor :Colors.white),
child: Checkbox(
value: isRememberMe,
onChanged: (bool? value) {
setState((){
isRememberMe = value ?? false;
});
},
),
)
],
),
);
You have defined all of your functions outside the scope of your widget. Since buildRememberCb function is outside the scope, you can't access isRememberMe variable here.
Also onChanged callback of Checkbox widget is required. You can't leave it undefined.
class LoginScreen extends StatefulWidget {
const LoginScreen({Key? key}) : super(key: key);
#override
_LoginScreenState createState() => _LoginScreenState();
}
class _LoginScreenState extends State<LoginScreen> {
bool isRememberMe = false;
#override
Widget build(BuildContext context) {
return Scaffold(
body: AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle.light,
child: GestureDetector(
child: Stack(
children: <Widget>[
Container(
height: double.infinity,
width: double.infinity,
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color(0x665ac18e),
Color(0x995ac18e),
Color(0xcc5ac18e),
Color(0xff5ac18e),
])),
child: SingleChildScrollView(
physics: const AlwaysScrollableScrollPhysics(),
padding: const EdgeInsets.symmetric(
horizontal: 25,
vertical: 120,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'Sign In',
style: TextStyle(
color: Colors.white,
fontSize: 40,
fontWeight: FontWeight.bold),
),
const SizedBox(height: 50),
buildEmail(),
const SizedBox(height: 20),
buildPassword(),
buildForgotPassBtn(),
buildRememberCb(),
],
),
),
),
],
),
),
),
);
}
Widget buildEmail() {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
const Text(
'Email',
style: TextStyle(
color: Colors.white, fontSize: 16, fontWeight: FontWeight.bold),
),
const SizedBox(height: 10),
Container(
alignment: Alignment.centerLeft,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
boxShadow: const [
BoxShadow(
color: Colors.black26,
blurRadius: 6,
offset: Offset(0, 2))
]),
height: 60,
child: const TextField(
keyboardType: TextInputType.emailAddress,
style: TextStyle(color: Colors.black87),
decoration: InputDecoration(
border: InputBorder.none,
contentPadding: EdgeInsets.only(top: 14),
prefixIcon: Icon(
Icons.email,
color: Color(0xff5ac18e),
),
hintText: 'Email',
hintStyle: TextStyle(color: Colors.black38)),
))
],
);
}
Widget buildPassword() {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
const Text(
'Password',
style: TextStyle(
color: Colors.white, fontSize: 16, fontWeight: FontWeight.bold),
),
const SizedBox(height: 10),
Container(
alignment: Alignment.centerLeft,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
boxShadow: const [
BoxShadow(
color: Colors.black26,
blurRadius: 6,
offset: Offset(0, 2))
]),
height: 60,
child: const TextField(
obscureText: true,
style: TextStyle(color: Colors.black87),
decoration: InputDecoration(
border: InputBorder.none,
contentPadding: EdgeInsets.only(top: 14),
prefixIcon: Icon(
Icons.lock,
color: Color(0xff5ac18e),
),
hintText: 'Password',
hintStyle: TextStyle(color: Colors.black38)),
))
],
);
}
Widget buildForgotPassBtn() {
return Container(
alignment: Alignment.centerRight,
child: TextButton(
onPressed: () => print("Forget Password pressed"),
// padding: EdgeInsets.only(right:0),
child: const Text(
'Forgot Passsword?',
style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
),
),
);
}
Widget buildRememberCb() {
return SizedBox(
height: 20,
child: Row(
children: <Widget>[
Theme(
data: ThemeData(unselectedWidgetColor: Colors.white),
child: Checkbox(
value: isRememberMe,
onChanged: (bool? value) {
setState(() {
isRememberMe = !isRememberMe;
});
},
),
)
],
),
);
}
}

Flutter bottomNavigationBar under put row section

I'm a beginner in the flutter, Im added my flutter page to bottomNavigationBar: Container to button and i want to to put under bottom button to this section
like this my image
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
RichText(
textAlign: TextAlign.center,
text: TextSpan(children: <TextSpan>[
TextSpan(
text: "Already have an account?",
style: TextStyle(color: m_titleColor,fontWeight: FontWeight.normal, fontFamily: "regular")),
TextSpan(
text: " Sign in",
style: TextStyle(
color: Color(0xFF2A3476),
fontWeight: FontWeight.w600,
fontFamily: "medium")),
]),
)
],
),
any idea how can i put it correctly ?
Thanks
import 'dart:ui';
import 'package:cmapp/widgets/components/alert.dart';
import 'package:cmapp/widgets/theme/constants.dart';
import 'package:cmapp/widgets/theme/constants.dart';
import 'package:cmapp/widgets/theme/constants.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class SignUpScreen extends StatefulWidget {
#override
_SignUpScreenState createState() => _SignUpScreenState();
}
class _SignUpScreenState extends State< SignUpScreen > {
//validation controller
TextEditingController fNameController = new TextEditingController();
TextEditingController lNameController = new TextEditingController();
TextEditingController nickNameController = new TextEditingController();
TextEditingController phoneController = new TextEditingController();
bool _isButtonEnabled = false;
//final _controller = TextEditingController();
bool isConfirm=false;
check (BuildContext context){
if(fNameController.text.isNotEmpty &&
lNameController.text.isNotEmpty &&
nickNameController.text.isNotEmpty &&
phoneController.text.isNotEmpty){
setState(() {
_isButtonEnabled = true;
});
} else {
setState(() {
_isButtonEnabled = false;
});
}
}
final GlobalKey<FormState> formKey = GlobalKey<FormState>();
#override
Widget build(BuildContext context) {
/* double height = MediaQuery.of(context).size.height;
double width = MediaQuery.of(context).size.width;*/
return Scaffold(
body: SafeArea(
child: Stack(
fit: StackFit.expand,
children: [
_signUp(),
],
),
),
bottomNavigationBar: Container(
padding: EdgeInsets.all(8.0),
child: Row(
children: [
Expanded(
child: MaterialButton(
height: 44,
onPressed: () {
FocusScope.of(context).requestFocus(FocusNode());
},
shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(8.0))),
color: _isButtonEnabled ? Color(0xFF2A3476) : Color(0x201E1E99),
elevation: 0,
highlightElevation: 0,
child: Container(
child: Text(
"Next",
style: TextStyle(color: m_fillColor,fontSize: 18,fontWeight: FontWeight.w600 ,
fontFamily: "regular",),
),
),
),
),
],
),
),
);
}
Widget _signUp() {
return Container(
constraints: BoxConstraints.expand(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
),
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Color(0xFF2A3476),
Color(0xFF2A3476),
],
begin: Alignment.topLeft,
end: Alignment.centerRight,
),
),
child: Form(
key: formKey,
child: Container(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding:
const EdgeInsets.symmetric(vertical: 36.0, horizontal: 24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Create Account",
style: TextStyle(
color: Colors.white,
fontSize: 34.0,fontFamily: "medium",
fontWeight: FontWeight.w800,
),
),
/* SizedBox(
height: 10.0,
),*/
/* Text(
"Enter to a beautiful world",
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
fontWeight: FontWeight.w300,
),
)*/
],
),
),
Container(
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30),
topRight: Radius.circular(30),
),
),
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Hello, sign up to",
style: TextStyle(
fontSize: 29,
fontFamily: "regular",
fontWeight: FontWeight.w300,
color: Colors.black,
),
),
Text(
"continue",
style: TextStyle(
fontSize: 29,
fontFamily: "regular",
fontWeight: FontWeight.w300,
color: Colors.black,
),
),
SizedBox(
height: 20.0,
),
Text(
'First Name',
style:
TextStyle( fontSize: 15,
fontFamily: "regular",),
),
SizedBox(
height: 12.0,
),
TextFormField(
/* keyboardType: TextInputType.emailAddress,*/
controller: fNameController,
onChanged: (val){
check(context);
},
decoration: InputDecoration(
contentPadding: EdgeInsets.all(8),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: BorderSide.none,
),
filled: true,
fillColor: Color(0xFFE1E8F7),
hintText: "",
/* prefixIcon: Icon(
Icons.people_outline_rounded,
color: Colors.grey[600],
)*/),
),
SizedBox(
height: 20.0,
),
Text(
'Last Name',
style:
TextStyle(
fontSize: 15,
fontFamily: "regular",
),
),
SizedBox(
height: 12.0,
),
TextField(
controller: lNameController,
onChanged: (val){
check(context);
},
/* keyboardType: TextInputType.emailAddress,*/
decoration: InputDecoration(
contentPadding: EdgeInsets.all(8),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: BorderSide.none,
),
filled: true,
fillColor: Color(0xFFE1E8F7),
hintText: "",
/* prefixIcon: Icon(
Icons.people_outline_rounded,
color: Colors.grey[600],
)*/),
),
SizedBox(
height: 20.0,
),
Text(
'Nick Name',
style:
TextStyle( fontSize: 15,
fontFamily: "regular",),
),
SizedBox(
height: 12.0,
),
TextField(
/* keyboardType: TextInputType.emailAddress,*/
controller: nickNameController,
onChanged: (val){
check(context);
},
decoration: InputDecoration(
contentPadding: EdgeInsets.all(8),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: BorderSide.none,
),
filled: true,
fillColor: Color(0xFFE1E8F7),
hintText: "",
/*prefixIcon: Icon(
Icons.people_outline_rounded,
color: Color(0xFFE1E8F7),
)*/),
),
SizedBox(
height: 20.0,
),
Text(
'Mobile Number',
style:
TextStyle( fontSize: 15,
fontFamily: "regular",),
),
SizedBox(
height: 12.0,
),
TextFormField(
controller: phoneController,
onChanged: (val){
check(context);
},
maxLength: 10,
/* validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter some text';
}
return null;
},*/
keyboardType: TextInputType.phone,
/* keyboardType: TextInputType.emailAddress,*/
decoration: InputDecoration(
contentPadding: EdgeInsets.all(8),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: BorderSide.none,
),
filled: true,
fillColor: Color(0xFFE1E8F7),
hintText: "077xxxxxxx",
),
),
SizedBox(
height: 20.0,
),
/*
Container( alignment: Alignment.bottomCenter,
padding: EdgeInsets.symmetric(horizontal: 0),
child: Row(
children: [
Expanded(
child: MaterialButton(
height: 44,
onPressed: () {
FocusScope.of(context).requestFocus(FocusNode());
},
shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(8.0))),
color: _isButtonEnabled ? Color(0xFF2A3476) : Color(0x201E1E99),
elevation: 2,
highlightElevation: 0,
child: Container(
child: Text(
"Next",
style: TextStyle(color: m_fillColor,fontSize: 18,fontWeight: FontWeight.w600 ,
fontFamily: "regular",),
),
),
),
),
],
),
),*/
/* Container(
child: Container(
width: MediaQuery.of(context).size.width,
padding: EdgeInsets.symmetric(vertical: 15),
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(5)),
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.grey.shade200,
offset: Offset(2, 4),
blurRadius: 5,
spreadRadius: 2)
],
gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [
Color(0xFF2A3476),
Color(0xFF2A3476)
])),
child: Text(
'Next',
style: TextStyle(fontSize: 20, color: Colors.white),
),
),
),*/
SizedBox(
height: 20.0,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
RichText(
textAlign: TextAlign.center,
text: TextSpan(children: <TextSpan>[
TextSpan(
text: "Already have an account?",
style: TextStyle(color: m_titleColor,fontWeight: FontWeight.normal, fontFamily: "regular")),
TextSpan(
text: " Sign in",
style: TextStyle(
color: Color(0xFF2A3476),
fontWeight: FontWeight.w600,
fontFamily: "medium")),
]),
)
],
), SizedBox(
height:100.0,
),
],
),
),
),
],
),
),
),
),
);
}
}
Use Column inside Container for Button and Text.
Container(
padding: EdgeInsets.all(8.0),
child: Column(
children: [
// first row
Row(children: [
Expanded(
child: MaterialButton(
height: 44,
onPressed: () {
FocusScope.of(context).requestFocus(FocusNode());
},
shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(8.0))),
color: _isButtonEnabled ? Color(0xFF2A3476) : Color(0x201E1E99),
elevation: 0,
highlightElevation: 0,
child: Container(
child: Text(
"Next",
style: TextStyle(color: m_fillColor,fontSize: 18,fontWeight: FontWeight.w600 ,
fontFamily: "regular",),
),
),
),
),
])
//second row
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
RichText(
textAlign: TextAlign.center,
text: TextSpan(children: <TextSpan>[
TextSpan(
text: "Already have an account?",
style: TextStyle(color: m_titleColor,fontWeight: FontWeight.normal, fontFamily: "regular")),
TextSpan(
text: " Sign in",
style: TextStyle(
color: Color(0xFF2A3476),
fontWeight: FontWeight.w600,
fontFamily: "medium")),
]),
)
],
), ],)
),

Flutter TextField hide by Keyboard

I'm a beginner in the flutter, I have a conflict, when I'm focusing on a TexFiled, the keyboard hidden over the TextField, and bottom button not showing i attached my conflict here
any solution for this
Thanks
code here
import 'dart:ui';
import 'package:crapp/pages/create_password/password_screen.dart';
import 'package:crapp/widgets/components/alert.dart';
import 'package:crapp/widgets/components/page_animation.dart';
import 'package:crapp/widgets/theme/constants.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:crapp/provider/theme_provider.dart';
class PasswordScreen extends StatefulWidget {
#override
_PasswordScreenState createState() => _PasswordScreenState();
}
class _PasswordScreenState extends State< PasswordScreen > {
final _controller = TextEditingController();
//validation controller
TextEditingController sQuastionController = new TextEditingController();
TextEditingController answerQController = new TextEditingController();
TextEditingController passController = new TextEditingController();
TextEditingController conPassController = new TextEditingController();
final TextEditingController _pass = TextEditingController();
final TextEditingController _confirmPass = TextEditingController();
bool _isButtonEnabled = false;
//final _controller = TextEditingController();
bool isConfirm=false;
check (BuildContext context){
if(sQuastionController.text.isNotEmpty &&
answerQController.text.isNotEmpty &&
conPassController.text.isNotEmpty &&
passController.text.isNotEmpty){
setState(() {
_isButtonEnabled = true;
});
} else {
setState(() {
_isButtonEnabled = false;
});
}
}
checks (BuildContext context){
if(passController.text.isEmpty){
showDialog<void>(
context: context,
builder: (BuildContext dialogContext) {
return Alert(title: "Alert !!!",subTile: "Password must be 10 characters !",);
}
);
}else if(passController.text.length > 0 && passController.text.length < 10){
isConfirm = true;
showDialog<void>(
context: context,
builder: (BuildContext dialogContext) {
return Alert(title: "Alert !!!",subTile: "Password doesn't match !",);
}
);
}
}
checkChanged(){
if( secretVal != null
)
{
setState(() {
isSave = true;
});
}else{
isSave =false;
}
} bool isSave=false;
final GlobalKey<FormState> formKey = GlobalKey<FormState>();
#override
Widget build(BuildContext context) {
/* double height = MediaQuery.of(context).size.height;
double width = MediaQuery.of(context).size.width;*/
Provider.of<ThemeProvider>(context).themeMode == ThemeMode.dark
? 'DarkTheme'
: 'LightTheme';
return Scaffold(
resizeToAvoidBottomInset: false,
body: SafeArea(
child: Column(
children: <Widget>[
Expanded(
child: _signUp(),
),
],
),
), bottomNavigationBar: BottomAppBar(
elevation: 4,
child: Container(
height: 70,
child: Container(
padding: EdgeInsets.symmetric(horizontal: 16),
child: Row(
children: [
Expanded(
child: MaterialButton(
height: 44,
onPressed: () {
FocusScope.of(context).requestFocus(FocusNode());
//check();
},
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(4)),
color: Color(0xFF2A3476),
elevation: 0,
highlightElevation: 0,
child: Container(
child: Text(
"Save",
style: TextStyle(
color: Color(0xFF2A3476),
fontSize: 15,
fontFamily: 'medium'),
),
),
),
),
],
),
),
),
),
/* bottomNavigationBar: Container(
padding: EdgeInsets.all(25.0),
decoration: BoxDecoration(color: Colors.white,
),
child: Row(
children: [
Expanded(
child: MaterialButton(
height: 44,
onPressed: () {
FocusScope.of(context).requestFocus(FocusNode());
*//* Navigator.push(context, SlidePageRoute(page:PasswordScreen()));*//*
},
shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(8.0))),
color: _isButtonEnabled ? Color(0xFF2A3476) : Color(0x201E1E99),
elevation: 0,
highlightElevation: 0,
child: Container(
child: Text(
"Next",
style: TextStyle(color: m_fillColor,fontSize: 18,fontWeight: FontWeight.w600 ,
fontFamily: "regular",),
),
),
),
),
],
),
)*/
);
}
Widget _signUp() {
return Container(
constraints: BoxConstraints.expand(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
),
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Color(0xFF2A3476),
Color(0xFF2A3476),
],
begin: Alignment.topLeft,
end: Alignment.centerRight,
),
),
child: Form(
key: formKey,
child: Container(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding:
const EdgeInsets.symmetric(vertical: 36.0, horizontal: 24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Create Password",
style: TextStyle(
color: Colors.white,
fontSize: 30.0,fontFamily: "medium",
fontWeight: FontWeight.w800,
),
),
],
),
),
Container(
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30),
topRight: Radius.circular(30),
),
),
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Steps to set your",
style: TextStyle(
fontSize: 22,
fontFamily: "regular",
fontWeight: FontWeight.w300,
color: Colors.black,
),
),
Text(
"password",
style: TextStyle(
fontSize: 22,
fontFamily: "regular",
fontWeight: FontWeight.w300,
color: Colors.black,
),
),
SizedBox(
height: 20.0,
), Text(
'Secret Question',
style:
TextStyle( fontSize: 15,
fontFamily: "regular",),
), SizedBox(
height: 8.0,
),
Row(
children: [
Expanded(child: InkWell(
onTap: (){
FocusScope.of(context).requestFocus(FocusNode());
secretDialogue();
},
child: Stack(
children: <Widget>[
TextField(
/* textInputAction: TextInputAction.next,*/
controller: sQuastionController,
enabled: false,
onChanged: (val) {
check(context);
},
decoration: InputDecoration(
labelText: secretVal==null?"Select One":secretVal,
contentPadding: EdgeInsets.all(8),
border: OutlineInputBorder(
borderRadius:
BorderRadius.circular(8.0),
borderSide: BorderSide.none,
),
filled: true,
fillColor: Color(0xFFE1E8F7),
hintText: "",
/* prefixIcon: Icon(
Icons.people_outline_rounded,
color: Colors.grey[600],
)*/
),
),
Positioned.directional(
textDirection: Directionality.of(context),
end: 0,
top: 0,
bottom: 0,
child: Padding(
padding: const EdgeInsets.all(8.0),
child:Image.asset(
"assets/icons/ic_drop_arrow.png",
scale: 9,
)),
)
],
),
),
),
],
),
SizedBox(
height: 20.0,
),
Text(
'Answer',
style:
TextStyle( fontSize: 15,
fontFamily: "regular",),
),
SizedBox(
height: 8.0,
),
TextField(
/* keyboardType: TextInputType.emailAddress,*/
/* textInputAction: TextInputAction.next,*/
controller: answerQController,
onChanged: (val){
check(context);
},
decoration: InputDecoration(
contentPadding: EdgeInsets.all(8),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: BorderSide.none,
),
filled: true,
fillColor: Color(0xFFE1E8F7),
hintText: "",
/*prefixIcon: Icon(
Icons.people_outline_rounded,
color: Color(0xFFE1E8F7),
)*/),
),
SizedBox(
height: 20.0,
),
Text(
'Password',
style:
TextStyle( fontSize: 15,
fontFamily: "regular",),
),
SizedBox(
height: 8.0,
),
TextFormField(
/* keyboardType: TextInputType.emailAddress,*/
/* textInputAction: TextInputAction.next,*/
controller: passController,
onChanged: (val){
check(context);
},
//password validation
/* validator: (val){
if(val!.isEmpty)
return 'Empty';
return null;
},*/
decoration: InputDecoration(
contentPadding: EdgeInsets.all(8),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: BorderSide.none,
),
filled: true,
fillColor: Color(0xFFE1E8F7),
hintText: "************",
),
),
SizedBox(
height: 20.0,
),
Text(
'Confirm Password',
style:
TextStyle( fontSize: 15,
fontFamily: "regular",),
),
SizedBox(
height: 8.0,
),
TextFormField(
textInputAction: TextInputAction.done,
controller: conPassController,
onChanged: (val){
check(context);
},
//password validation
/* validator: (val){
if(val!.isEmpty)
return 'Empty';
if(val != _pass.text)
return 'Not Match';
return null;
},*/
decoration: InputDecoration(
contentPadding: EdgeInsets.all(8),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: BorderSide.none,
),
filled: true,
fillColor: Color(0xFFE1E8F7),
hintText: "************",
),
),
SizedBox(
height: 20.0,
),
SizedBox(
height: 8.0,
),
SizedBox(
height:200.0,
),
],
),
),
),
],
),
),
),
),
);
}
//
//Secret Qu Alert
List secretList =[
"-What’s your favorite team?",
"-What’s your astrological sign?",
"-What’s your favorite movie?",
"-What city were you born in?",
"-What was your first car?",
];
var secretVal;
void secretDialogue(){
showDialog<void>(
context: context,
// false = user must tap button, true = tap outside dialog
builder: (BuildContext dialogContext) {
return StatefulBuilder(
builder: (context,setState){
return Dialog(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
insetPadding: EdgeInsets.all(20),
child: Container(
padding: EdgeInsets.symmetric(vertical: 10),
child: Column(
mainAxisSize: MainAxisSize.min,
children: List.generate(secretList.length, (index){
return InkWell(
onTap: (){
setState(() {
secretVal = secretList[index];
Navigator.pop(context);
});
},
child: Container(
height: 50,
padding: EdgeInsets.symmetric(horizontal: 20),
alignment: Alignment.centerLeft,
child: Text(secretList[index],
style: TextStyle(
fontSize: 18,
fontFamily: "medium",
),),
),
);
})
),
),
);
}
);
},
);
}
}
Wrap your Column by SingleChildScrollView. It will solve your problem.
like this..
body: SafeArea(
child: SingleChildScrollView(
child: Column(
Also I think after this there is no need of
resizeToAvoidBottomInset: false,
in Scaffold.
Please check out and I have found some inconsistency in code, refactored some of them
import 'dart:ui';
import 'package:crapp/pages/create_password/password_screen.dart';
import 'package:crapp/widgets/components/alert.dart';
import 'package:crapp/widgets/components/page_animation.dart';
import 'package:crapp/widgets/theme/constants.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:crapp/provider/theme_provider.dart';
class PasswordScreen extends StatefulWidget {
#override
_PasswordScreenState createState() => _PasswordScreenState();
}
class _PasswordScreenState extends State< PasswordScreen > {
final _controller = TextEditingController();
//validation controller
TextEditingController sQuastionController = new TextEditingController();
TextEditingController answerQController = new TextEditingController();
TextEditingController passController = new TextEditingController();
TextEditingController conPassController = new TextEditingController();
final TextEditingController _pass = TextEditingController();
final TextEditingController _confirmPass = TextEditingController();
bool _isButtonEnabled = false;
//final _controller = TextEditingController();
bool isConfirm = false;
check(BuildContext context) {
if (sQuastionController.text.isNotEmpty &&
answerQController.text.isNotEmpty &&
conPassController.text.isNotEmpty &&
passController.text.isNotEmpty) {
setState(() {
_isButtonEnabled = true;
});
} else {
setState(() {
_isButtonEnabled = false;
});
}
}
void initState() {
SystemChannels.textInput.invokeMethod('TextInput.hide');
super.initState();
}
checks (BuildContext context){
if(passController.text.isEmpty){
showDialog<void>(
context: context,
builder: (BuildContext dialogContext) {
return Alert(title: "Alert !!!",subTile: "Password must be 10 characters !",);
}
);
}else if(passController.text.length > 0 && passController.text.length < 10){
isConfirm = true;
showDialog<void>(
context: context,
builder: (BuildContext dialogContext) {
return Alert(title: "Alert !!!",subTile: "Password doesn't match !",);
}
);
}
}
checkChanged() {
if (secretVal != null) {
setState(() {
isSave = true;
});
} else {
isSave = false;
}
}
bool isSave = false;
final GlobalKey<FormState> formKey = GlobalKey<FormState>();
#override
Widget build(BuildContext context) {
/* double height = MediaQuery.of(context).size.height;
double width = MediaQuery.of(context).size.width;*/
Provider.of<ThemeProvider>(context).themeMode == ThemeMode.dark
? 'DarkTheme'
: 'LightTheme';
return Scaffold(
// resizeToAvoidBottomInset: false,
body: _signUp(),
bottomNavigationBar: BottomAppBar(
elevation: 4,
child: Container(
height: 70,
child: Container(
padding: EdgeInsets.symmetric(horizontal: 16),
child: Row(
children: [
Expanded(
child: MaterialButton(
height: 44,
onPressed: () {
FocusScope.of(context).requestFocus(FocusNode());
//check();
},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4)),
color: Color(0xFF2A3476),
elevation: 0,
highlightElevation: 0,
child: Container(
child: Text(
"Save",
style: TextStyle(
color: Color(0xFF2A3476),
fontSize: 15,
fontFamily: 'medium'),
),
),
),
),
],
),
),
),
),
/* bottomNavigationBar: Container(
padding: EdgeInsets.all(25.0),
decoration: BoxDecoration(color: Colors.white,
),
child: Row(
children: [
Expanded(
child: MaterialButton(
height: 44,
onPressed: () {
FocusScope.of(context).requestFocus(FocusNode());
*/ /* Navigator.push(context, SlidePageRoute(page:PasswordScreen()));*/ /*
},
shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(8.0))),
color: _isButtonEnabled ? Color(0xFF2A3476) : Color(0x201E1E99),
elevation: 0,
highlightElevation: 0,
child: Container(
child: Text(
"Next",
style: TextStyle(color: m_fillColor,fontSize: 18,fontWeight: FontWeight.w600 ,
fontFamily: "regular",),
),
),
),
),
],
),
)*/
);
}
Widget _signUp() {
return Container(
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Color(0xFF2A3476),
Color(0xFF2A3476),
],
begin: Alignment.topLeft,
end: Alignment.centerRight,
),
),
child: SingleChildScrollView(
child: Form(
key: formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.symmetric(
vertical: 36.0, horizontal: 24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Create Password",
style: TextStyle(
color: Colors.white,
fontSize: 30.0,
fontFamily: "medium",
fontWeight: FontWeight.w800,
),
),
],
),
),
Container(
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30),
topRight: Radius.circular(30),
),
),
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Steps to set your",
style: TextStyle(
fontSize: 22,
fontFamily: "regular",
fontWeight: FontWeight.w300,
color: Colors.black,
),
),
Text(
"password",
style: TextStyle(
fontSize: 22,
fontFamily: "regular",
fontWeight: FontWeight.w300,
color: Colors.black,
),
),
SizedBox(
height: 20.0,
),
Text(
'Secret Question',
style: TextStyle(
fontSize: 15,
fontFamily: "regular",
),
),
SizedBox(
height: 8.0,
),
Row(
children: [
Expanded(
child: InkWell(
onTap: () {
FocusScope.of(context)
.requestFocus(FocusNode());
secretDialogue();
},
child: Stack(
children: <Widget>[
TextField(
/* textInputAction: TextInputAction.next,*/
controller: sQuastionController,
enabled: false,
onChanged: (val) {
check(context);
},
decoration: InputDecoration(
labelText: secretVal == null
? "Select One"
: secretVal,
contentPadding: EdgeInsets.all(8),
border: OutlineInputBorder(
borderRadius:
BorderRadius.circular(8.0),
borderSide: BorderSide.none,
),
filled: true,
fillColor: Color(0xFFE1E8F7),
hintText: "",
/* prefixIcon: Icon(
Icons.people_outline_rounded,
color: Colors.grey[600],
)*/
),
),
Positioned.directional(
textDirection: Directionality.of(context),
end: 0,
top: 0,
bottom: 0,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Image.asset(
"assets/icons/ic_drop_arrow.png",
scale: 9,
)),
)
],
),
),
),
],
),
SizedBox(
height: 20.0,
),
Text(
'Answer',
style: TextStyle(
fontSize: 15,
fontFamily: "regular",
),
),
SizedBox(
height: 8.0,
),
GestureDetector(
onTap: () {
FocusScope.of(context).requestFocus(new FocusNode());
},
child: TextField(
/* keyboardType: TextInputType.emailAddress,*/
/* textInputAction: TextInputAction.next,*/
controller: answerQController,
onChanged: (val) {
check(context);
},
decoration: InputDecoration(
contentPadding: EdgeInsets.all(8),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: BorderSide.none,
),
filled: true,
fillColor: Color(0xFFE1E8F7),
hintText: "",
/*prefixIcon: Icon(
Icons.people_outline_rounded,
color: Color(0xFFE1E8F7),
)*/
),
),
),
SizedBox(
height: 20.0,
),
Text(
'Password',
style: TextStyle(
fontSize: 15,
fontFamily: "regular",
),
),
SizedBox(
height: 8.0,
),
GestureDetector(
onTap: () {
FocusScope.of(context).requestFocus(new FocusNode());
},
child: TextFormField(
/* keyboardType: TextInputType.emailAddress,*/
/* textInputAction: TextInputAction.next,*/
controller: passController,
onChanged: (val) {
check(context);
},
//password validation
/* validator: (val){
if(val!.isEmpty)
return 'Empty';
return null;
},*/
decoration: InputDecoration(
contentPadding: EdgeInsets.all(8),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: BorderSide.none,
),
filled: true,
fillColor: Color(0xFFE1E8F7),
hintText: "************",
),
),
),
SizedBox(
height: 20.0,
),
Text(
'Confirm Password',
style: TextStyle(
fontSize: 15,
fontFamily: "regular",
),
),
SizedBox(
height: 8.0,
),
GestureDetector(
onTap: () {
FocusScope.of(context).requestFocus(new FocusNode());
},
child: TextFormField(
textInputAction: TextInputAction.done,
controller: conPassController,
onChanged: (val) {
check(context);
},
//password validation
/* validator: (val){
if(val!.isEmpty)
return 'Empty';
if(val != _pass.text)
return 'Not Match';
return null;
},*/
decoration: InputDecoration(
contentPadding: EdgeInsets.all(8),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: BorderSide.none,
),
filled: true,
fillColor: Color(0xFFE1E8F7),
hintText: "************",
),
),
),
SizedBox(
height: 20.0,
),
SizedBox(
height: 8.0,
),
SizedBox(
height: 200.0,
),
],
),
),
),
],
),
),
),
);
}
//
//Secret Qu Alert
List secretList = [
"-What’s your favorite team?",
"-What’s your astrological sign?",
"-What’s your favorite movie?",
"-What city were you born in?",
"-What was your first car?",
];
var secretVal;
void secretDialogue() {
showDialog<void>(
context: context,
// false = user must tap button, true = tap outside dialog
builder: (BuildContext dialogContext) {
return StatefulBuilder(builder: (context, setState) {
return Dialog(
shape:
RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
insetPadding: EdgeInsets.all(20),
child: Container(
padding: EdgeInsets.symmetric(vertical: 10),
child: Column(
mainAxisSize: MainAxisSize.min,
children: List.generate(secretList.length, (index) {
return InkWell(
onTap: () {
setState(() {
secretVal = secretList[index];
Navigator.pop(context);
});
},
child: Container(
height: 50,
padding: EdgeInsets.symmetric(horizontal: 20),
alignment: Alignment.centerLeft,
child: Text(
secretList[index],
style: TextStyle(
fontSize: 18,
fontFamily: "medium",
),
),
),
);
})),
),
);
});
},
);
}
}

Login and Signup form not validating

Login/Signup form is supposed to move to homepage on validation of the submit button (an arrow forward button icon) and if not validated, it ought to show a snackbar saying 'Error', but nothing works.
It keeps on giving this error message on button click "Another exception was thrown: NoSuchMethodError: The method 'validate' was called on null."
Here is my code:
import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:community_material_icon/community_material_icon.dart';
import 'package:time_to_eat_devotionals/screens/home.dart';
import 'package:time_to_eat_devotionals/theme/palette.dart';
class LoginSignupScreen extends StatefulWidget {
#override
_LoginSignupScreenState createState() => _LoginSignupScreenState();
}
class _LoginSignupScreenState extends State<LoginSignupScreen> {
bool isSignUpScreen = true;
bool isRememberMe = false;
final _formkey = GlobalKey<FormState>();
TextEditingController usernameController = TextEditingController();
TextEditingController emailController = TextEditingController();
TextEditingController passwordController = TextEditingController();
TextEditingController nationalityController = TextEditingController();
var countryName = ['Nigeria', 'Ghana'];
#override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [Colors.yellow, Palette.backgroundColor]
),
),
child: Scaffold(
backgroundColor: Colors.transparent,
body: Stack(
children: [
Positioned(
top: 0,
right: 0,
left: 0,
child: Container(
height: 300,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(isSignUpScreen? 'assets/images/signupbg.jpg' : 'assets/images/loginbg.jpg'),
fit: BoxFit.fill)),
child: Container(
padding: EdgeInsets.only(top: 90, left: 20),
color: Colors.black.withOpacity(.65),
child: Column(
children: [
RichText(
text: TextSpan(
text: isSignUpScreen? 'Welcome To' : 'Welcome Back',
style: TextStyle(
fontFamily: 'Raleway',
fontSize: 18,
color: Colors.white))),
Container(
height: 8.0,
),
Text(
'Time To Eat Devotionals',
style: TextStyle(
fontFamily: 'Kurale',
fontWeight: FontWeight.w600,
fontSize: 30.0,
color: Colors.white),
),
Container(
height: 8.0,
),
Text(
isSignUpScreen? 'Signup to continue': 'Login to continue',
style: TextStyle(
fontFamily: 'Raleway',
fontSize: 14.0,
color: Colors.white),
)
],
),
),
),
),
AnimatedPositioned(
duration: Duration(milliseconds: 700),
curve: Curves.bounceOut,
top: isSignUpScreen? 200 : 250,
child: AnimatedContainer(
duration: Duration(milliseconds: 700),
curve: Curves.bounceOut,
padding: EdgeInsets.only(top: 5, bottom: 20, right: 20, left: 20),
height: isSignUpScreen? 350 : 280,
width: MediaQuery.of(context).size.width - 40,
margin: EdgeInsets.symmetric(horizontal: 20),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(15),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.3),
blurRadius: 15,
spreadRadius: 5)
]),
child: SingleChildScrollView(
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
GestureDetector(
onTap: () {
setState(() {
isSignUpScreen = true;
});
},
child: Column(
children: [
Text(
"SIGNUP",
style: TextStyle(
fontFamily: 'baloo da 2',
fontSize: 21,
fontWeight: FontWeight.w500,
color: isSignUpScreen
? Palette.activeColor
: Colors.black),
),
if (isSignUpScreen)
Container(
margin: EdgeInsets.only(top: 1.0),
height: 2,
width: 55,
color: Colors.black,
)
],
),
),
GestureDetector(
onTap: () {
setState(() {
isSignUpScreen = false;
});
},
child: Column(
children: [
Text(
"LOGIN",
style: TextStyle(
fontFamily: 'baloo da 2',
fontSize: 21,
fontWeight: FontWeight.w500,
color: isSignUpScreen
? Colors.black
: Palette.activeColor),
),
if (!isSignUpScreen)
Container(
margin: EdgeInsets.only(top: 1.0),
height: 2,
width: 55,
color: Colors.black,
)
],
)),
],
),
isSignUpScreen?
Container(
key: _formkey,
margin: EdgeInsets.only(top: 10),
child: Column(
children: [
buidTextField(Icons.person, 'User Name', 'Enter your user name', false, false, usernameController, (username){
if (username.isEmpty) {
return 'Username is required';
} else if (username.length <6) {
return 'Username is short';
}
return null;
}),
buidTextField(Icons.email, 'Email', 'Enter your valid email address', false, true, emailController, (signupEmail){
if (signupEmail.isEmpty) {
return 'Email is required';
} else if (!signupEmail.contains('#')) {
return 'Please enter a valid email address';
}
return null;
}),
buidTextField(Icons.lock, 'Password', 'Enter your password', true, false, passwordController, (signupPword){
if (signupPword.isEmpty) {
return 'Password is required';
} else if (signupPword.length <8) {
return 'Password must be at least 8 characters';
}
return null;
}),
buidTextField(Icons.flag, 'Nationality', 'What country are you from', false, false, nationalityController, (nationality){
if (nationality.isEmpty) {
return 'Enter Your Nationality';
} else if (!nationality.contain(countryName)) {
return 'Please enter a valid Country name';
}
return null;
}),
RichText(
textAlign: TextAlign.center,
text: TextSpan(
text: "By pressing 'Submit', you agree to our \n",
style: TextStyle(
color: Colors.black,
fontFamily: 'raleway',
fontSize: 13.0, letterSpacing: 0.1
),
children: [
TextSpan(
recognizer: TapGestureRecognizer()
..onTap = () {
print('T&C is clicked');
},
text: 'Terms and Conditions',
style: TextStyle(
color: Palette.backgroundColor,
fontFamily: 'raleway',
fontSize: 13.0, letterSpacing: 0.1,
fontWeight: FontWeight.w500
)
)
]
),
),
],
),)
:
Container(
key: _formkey,
margin: EdgeInsets.only(top: 20),
child: Column(
children: [
buidTextField(Icons.email, 'Email', 'info#example.com', false, true, emailController, (signinEmail){
if (signinEmail.isEmpty) {
return 'Username is required';
} else if (signinEmail.length <6) {
return 'Username is short';
}
return null;
}),
buidTextField(Icons.lock, 'Password', '********', true, false, passwordController, (signinPword){
if (signinPword.isEmpty) {
return 'Password is required';
} else if (signinPword.length <8) {
return 'Password should be at least 8 characters';
}
return null;
}),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(children: [
Checkbox(
value: isRememberMe,
activeColor: Colors.black,
onChanged: (value) {
setState(() {
isRememberMe = !isRememberMe;
});
}
),
Text(
"Remember Me",
style: TextStyle(
fontFamily: 'raleway',
fontSize: 15.0,
),
)
],),
TextButton(
onPressed: () {
print('Forgot Password clicked');
},
child: Text(
'Forgot Password?',
style: TextStyle(
fontFamily: 'raleway',
fontSize: 15.0,
color: Palette.backgroundColor
)
)
)
],
)
],
)
)
],
),
),
)),
AnimatedPositioned(
duration: Duration(milliseconds: 700),
curve: Curves.easeIn,
top: isSignUpScreen? 500 : 480,
right: 0,
left:0,
child: Center(
child: Container(
padding: EdgeInsets.all(15),
height: 90,
width: 90,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(50),
),
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Colors.yellow, Palette.backgroundColor]),
borderRadius: BorderRadius.circular(30),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(.3),
spreadRadius: 1,
blurRadius: 2,
offset: Offset(0, 1)
),
]
),
child: IconButton(
onPressed: () {
setState(() {
if (_formkey.currentState.validate()) {
Navigator.push(context, MaterialPageRoute(builder: (context) => Home()));
} else {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error'))
);
}
});
},
icon: Icon(Icons.arrow_forward, color: Colors.white,)
),
),
),
)
),
Positioned(
top: MediaQuery.of(context).size.height-100,
right: 0,
left: 0,
child: Column(
children: [
Text(
"Or Signup with",
style: TextStyle(
fontFamily: 'raleway',
fontSize:15.0,
color: Colors.white,
fontWeight: FontWeight.w600
),
),
SizedBox(height: 10,),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
buildTextButton(CommunityMaterialIcons.facebook, 'Facebook', Palette.fbColor),
buildTextButton(CommunityMaterialIcons.google, 'Google', Palette.googleColor),
],
)
],
)
)
],
),
),
);
}
TextButton buildTextButton(IconData icon, String title, Color backgroundColor,) {
return TextButton(
onPressed: () {},
style: TextButton.styleFrom(
backgroundColor: backgroundColor,
primary: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
side:BorderSide(
width: 1.5,
color: Colors.white
),
minimumSize: Size(140, 40)
),
child: Row(
children: [
Icon(
icon,
color: Colors.white,
size: 22,
),
SizedBox(width: 10,),
Text(
title,
style: TextStyle(
color: Colors.white,
fontFamily: 'baloo da 2',
fontSize: 18
),
)
],
)
);
}
Widget buidTextField(
IconData icon, String labelText, String hintText, bool isPassword, bool isEmail, TextEditingController controller, Function validator) {
return Form(
child: Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: Column(
children:[
TextFormField(
validator: validator,
controller: controller,
obscureText: isPassword,
keyboardType: isEmail? TextInputType.emailAddress : TextInputType.text,
decoration: InputDecoration(
prefixIcon: Icon(
icon,
color: Colors.black,
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(15),
borderSide: BorderSide(color: Colors.black)),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(15),
borderSide: BorderSide(color: Colors.black)),
labelText: labelText,
labelStyle: TextStyle(fontFamily: 'raleway'),
hintText: hintText,
hintStyle: TextStyle(
fontSize: 14.0,
fontFamily: 'raleway',
),
contentPadding: EdgeInsets.all(10)),
),
]
),
),);
}
}
initialize your form key like this
final GlobalKey<FormState> _formkey = GlobalKey<FormState>();

How can I eliminate this error : Incorrect use of ParentDataWidget

I didn't make use of Expanded widget but I don't know why I keep getting for this error.
Uncaught exception by widget library, Incorrect use of ParentDataWidget in four places I can't get where exactly the error is coming from. though it doesn't stop me from using the application but I feel it should be fixed. please can anyone help me?
This is my code below:
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:erg_app/Anchors.dart';
import 'package:erg_app/api/api.dart';
import 'package:shared_preferences/shared_preferences.dart';
class LogIn extends StatefulWidget {
#override
_LogInState createState() => _LogInState();
}
class _LogInState extends State<LogIn> {
bool _isLoading = false;
TextEditingController mailController = TextEditingController();
TextEditingController passwordController = TextEditingController();
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
ScaffoldState scaffoldState;
_showMsg() {
final snackBar = SnackBar(
content: Text(
'Invalid Username or Password',
style: (TextStyle(fontSize: 18)),
),
backgroundColor: Colors.amber[900],
);
_scaffoldKey.currentState.showSnackBar(snackBar);
}
#override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
FocusScopeNode currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus) {
currentFocus.unfocus();
}
},
child: Scaffold(
key: _scaffoldKey,
body: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
stops: [0.0, 0.4, 0.9],
colors: [
Color(0XFF4CAF50),
Color(0xFF388E3C),
Color(0xFF075009),
],
),
),
child: ListView(
children: <Widget>[
/////////// background///////////
SizedBox(height: 30),
new Container(
width: 100.00,
height: 100.00,
decoration: new BoxDecoration(
image: new DecorationImage(
image: AssetImage('assets/images/icon.png'),
fit: BoxFit.contain,
),
)),
Column(
children: <Widget>[
Positioned(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Positioned(
left: 30,
top: 100,
child: Container(
margin: EdgeInsets.only(top: 50),
child: Center(
child: Text(
"Welcome",
style: TextStyle(
color: Colors.white,
fontSize: 23,
fontWeight: FontWeight.bold),
),
),
),
),
SizedBox(height: 30),
Card(
elevation: 4.0,
color: Colors.white,
margin: EdgeInsets.only(left: 20, right: 20),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15)),
child: Padding(
padding: const EdgeInsets.all(10.0),
// child: form(key: _formKey),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
///////////// Email//////////////
TextField(
style: TextStyle(color: Color(0xFF000000)),
controller: mailController,
cursorColor: Color(0xFF9b9b9b),
keyboardType: TextInputType.text,
decoration: InputDecoration(
prefixIcon: Icon(
Icons.account_circle,
color: Colors.grey,
),
hintText: "Username",
hintStyle: TextStyle(
color: Color(0xFF9b9b9b),
fontSize: 15,
fontWeight: FontWeight.normal),
focusedBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Colors.green)),
),
),
/////////////// password////////////////////
TextField(
style: TextStyle(color: Color(0xFF000000)),
cursorColor: Color(0xFF9b9b9b),
controller: passwordController,
keyboardType: TextInputType.number,
obscureText: true,
decoration: InputDecoration(
prefixIcon: Icon(
Icons.vpn_key,
color: Colors.grey,
),
focusedBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Colors.green)),
hintText: "Password",
hintStyle: TextStyle(
color: Color(0xFF9b9b9b),
fontSize: 15,
fontWeight: FontWeight.normal),
),
),
///////////// LogIn Botton///////////////////
Padding(
padding: const EdgeInsets.all(10.0),
child: FlatButton(
child: Padding(
padding: EdgeInsets.only(
top: 8,
bottom: 8,
left: 10,
right: 10),
child: Text(
_isLoading ? 'Loging...' : 'Login',
textDirection: TextDirection.ltr,
style: TextStyle(
color: Colors.white,
fontSize: 15.0,
decoration: TextDecoration.none,
fontWeight: FontWeight.normal,
),
),
),
color: Colors.green,
disabledColor: Colors.grey,
shape: new RoundedRectangleBorder(
borderRadius:
new BorderRadius.circular(20.0)),
onPressed: _isLoading ? null : _login,
),
),
],
),
),
),
//////////// new account///////////////
Padding(
padding: const EdgeInsets.only(top: 20),
child: InkWell(
onTap: () {
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => LogIn()));
},
child: Text(
'Forgot Your Password?',
textDirection: TextDirection.ltr,
style: TextStyle(
color: Colors.white,
fontSize: 15.0,
decoration: TextDecoration.none,
fontWeight: FontWeight.normal,
),
),
),
),
],
),
),
),
],
)
],
),
),
));
// Gesture ends here
}
}
this is the picture of the error message:
You have a Positioned widget inside Column widgets in different parts of your code.
A Positioned widget must be a descendant of a Stack, and the path from
the Positioned widget to its enclosing Stack must contain only
StatelessWidgets or StatefulWidgets
I pasted the above from Flutter docs and it says that a Positioned must be descendant of a Stack i.e you cannot have a position inside other Widgets aside from a Stack widget.
You should remove the Positioned widgets from your code. or wrap them with a Stack widget
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:erg_app/Anchors.dart';
import 'package:erg_app/api/api.dart';
import 'package:shared_preferences/shared_preferences.dart';
class LogIn extends StatefulWidget {
#override
_LogInState createState() => _LogInState();
}
class _LogInState extends State<LogIn> {
bool _isLoading = false;
TextEditingController mailController = TextEditingController();
TextEditingController passwordController = TextEditingController();
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
ScaffoldState scaffoldState;
_showMsg() {
final snackBar = SnackBar(
content: Text(
'Invalid Username or Password',
style: (TextStyle(fontSize: 18)),
),
backgroundColor: Colors.amber[900],
);
_scaffoldKey.currentState.showSnackBar(snackBar);
}
#override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
FocusScopeNode currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus) {
currentFocus.unfocus();
}
},
child: Scaffold(
key: _scaffoldKey,
body: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
stops: [0.0, 0.4, 0.9],
colors: [
Color(0XFF4CAF50),
Color(0xFF388E3C),
Color(0xFF075009),
],
),
),
child: ListView(
children: <Widget>[
/////////// background///////////
SizedBox(height: 30),
new Container(
width: 100.00,
height: 100.00,
decoration: new BoxDecoration(
image: new DecorationImage(
image: AssetImage('assets/images/icon.png'),
fit: BoxFit.contain,
),
)),
Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
margin: EdgeInsets.only(top: 50),
child: Center(
child: Text(
"Welcome",
style: TextStyle(
color: Colors.white,
fontSize: 23,
fontWeight: FontWeight.bold),
),
),
),
SizedBox(height: 30),
Card(
elevation: 4.0,
color: Colors.white,
margin: EdgeInsets.only(left: 20, right: 20),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15)),
child: Padding(
padding: const EdgeInsets.all(10.0),
// child: form(key: _formKey),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
///////////// Email//////////////
TextField(
style: TextStyle(color: Color(0xFF000000)),
controller: mailController,
cursorColor: Color(0xFF9b9b9b),
keyboardType: TextInputType.text,
decoration: InputDecoration(
prefixIcon: Icon(
Icons.account_circle,
color: Colors.grey,
),
hintText: "Username",
hintStyle: TextStyle(
color: Color(0xFF9b9b9b),
fontSize: 15,
fontWeight: FontWeight.normal),
focusedBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Colors.green)),
),
),
/////////////// password////////////////////
TextField(
style: TextStyle(color: Color(0xFF000000)),
cursorColor: Color(0xFF9b9b9b),
controller: passwordController,
keyboardType: TextInputType.number,
obscureText: true,
decoration: InputDecoration(
prefixIcon: Icon(
Icons.vpn_key,
color: Colors.grey,
),
focusedBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Colors.green)),
hintText: "Password",
hintStyle: TextStyle(
color: Color(0xFF9b9b9b),
fontSize: 15,
fontWeight: FontWeight.normal),
),
),
///////////// LogIn Botton///////////////////
Padding(
padding: const EdgeInsets.all(10.0),
child: FlatButton(
child: Padding(
padding: EdgeInsets.only(
top: 8,
bottom: 8,
left: 10,
right: 10),
child: Text(
_isLoading ? 'Loging...' : 'Login',
textDirection: TextDirection.ltr,
style: TextStyle(
color: Colors.white,
fontSize: 15.0,
decoration: TextDecoration.none,
fontWeight: FontWeight.normal,
),
),
),
color: Colors.green,
disabledColor: Colors.grey,
shape: new RoundedRectangleBorder(
borderRadius:
new BorderRadius.circular(20.0)),
onPressed: _isLoading ? null : _login,
),
),
],
),
),
),
//////////// new account///////////////
Padding(
padding: const EdgeInsets.only(top: 20),
child: InkWell(
onTap: () {
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => LogIn()));
},
child: Text(
'Forgot Your Password?',
textDirection: TextDirection.ltr,
style: TextStyle(
color: Colors.white,
fontSize: 15.0,
decoration: TextDecoration.none,
fontWeight: FontWeight.normal,
),
),
),
),
],
),
),
],
)
],
),
),
));
// Gesture ends here
}
}