How to Turn Some Functions to an Independent Widget in Flutter? - flutter

I need to turn these two functions : _collectKeywords and _matchKeywords into a Widget, so I can reuse them another time. I have tried it, but I don't know how and where to instatiate the a widget that only processes data without returning any value. Can somebody help me?
//please don't mind the UI, button's color, etc
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:fluttermatchcard/cardButton.dart';
class MainMenu extends StatelessWidget {
void _accessCardMatcher(String butKeyword)
{
_collectKeywords(butKeyword);
}
//================================================
String _keyword_1;
String _keyword_2;
void _collectKeywords(String _keyword_now){
if(_keyword_1==null)
{
_keyword_1=_keyword_now;
}
else{
_keyword_2=_keyword_now;
_matchKeyword(_keyword_1,_keyword_2);
}
}
void _matchKeyword(_keyWord_one, _keyWord_two){
if(_keyWord_one==_keyWord_two){
//Lock the But
print("MATCH!!!!");
}
_keyword_1=null;
_keyword_1=null;
}
//================================================
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
//textBaseline: ,
children: <Widget>[
Container(
child: Text("Match Card", style: TextStyle(
fontSize: 50,
color: Colors.amber,
fontFamily: "FreeHand"
),
),
),
Icon( Icons.filter_none,
color: Colors.amber,
size: 40,
),
SizedBox(
height: 30,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
//But Start
CardButton(
onTapExecute:_accessCardMatcher,
keyword: "start",
text: Text("STA", style: TextStyle(
fontSize: 20,
),),
alignment: Alignment.centerRight,
),
//But Start2
CardButton(
onTapExecute:_accessCardMatcher,
keyword: "start",
text: Text("RT", style: TextStyle(
fontSize: 20,
),),
alignment: Alignment.centerLeft,
),
SizedBox(
width: 10,
),
//But Option
CardButton(
onTapExecute:_accessCardMatcher,
keyword: "option",
text: Text("OPT", style: TextStyle(
fontSize: 20,
),),
alignment: Alignment.centerRight,
),
CardButton(
onTapExecute:_accessCardMatcher,
keyword: "option",
text: Text("ION", style: TextStyle(
fontSize: 20,
),),
alignment: Alignment.centerLeft,
),
],
),
SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
//But
CardButton(
onTapExecute:_accessCardMatcher,
keyword: "credit",
text: Text("CRE", style: TextStyle(
fontSize: 20,
),),
alignment: Alignment.centerRight,
),
CardButton(
onTapExecute:_accessCardMatcher,
keyword: "credit",
text: Text("DIT", style: TextStyle(
fontSize: 20,
),),
alignment: Alignment.centerLeft,
),
],
)
],
)
);
}
}

Its a sample, Modify as your requirement !
class MyWidget extends StatefulWidget {
#override
_MyWidgetState createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget> {
int buttonCount = 0;
String textYouWantToModify = '';
TextEditingController te;
CommonMethods methods = CommonMethods();
#override
void initState() {
super.initState();
te = TextEditingController();
}
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(title: Text('Title')),
body: Container(
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
//Other widgets like TextFiled to save text......or whatever
TextField(
controller: te,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Type something 1',
labelStyle: TextStyle(color: Colors.black)),
style: TextStyle(color: Colors.black)
),
RaisedButton(
color: Colors.black,
onPressed: () {
setState(() {
buttonCount++;
if (buttonCount == 2) {
methods.method1(te.text);
methods.method2();
}
});
},
child:
Text('Button 1', style: TextStyle(color: Colors.white))),
RaisedButton(
onPressed: () {
setState(() {
buttonCount++;
if (buttonCount == 2) {
methods.method1(te.text);
methods.method2();
}
});
},
child:
Text('Button 2', style: TextStyle(color: Colors.black))),
//Other widgets.....
]))));
}
}
class CommonMethods {
void method1(String s) {
//your code.....
print(s);
}
void method2() {
//your code.....
}
}

Related

How to achieve this design using flutter?

I want to achieve this:
For now, I have this:
This is my code:
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class LogInEnterEmailPassword extends StatefulWidget {
const LogInEnterEmailPassword({Key? key}) : super(key: key);
#override
State<LogInEnterEmailPassword> createState() => _LogInEnterEmailPasswordState();
}
class _LogInEnterEmailPasswordState extends State<LogInEnterEmailPassword> {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0xffF6F6F6),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text("Enter Email",
style: TextStyle(
fontSize: 25,
fontStyle: FontStyle.normal,
fontWeight: FontWeight.normal,
color: Color(0xff313640),
),),
Text("______________________________",
style: TextStyle(
fontSize: 25,
fontStyle: FontStyle.normal,
fontWeight: FontWeight.normal,
color: Color(0xff313640),
),),
Text("Enter Password",
style: TextStyle(
fontSize: 25,
fontStyle: FontStyle.normal,
fontWeight: FontWeight.normal,
color: Color(0xff313640),
),),
Text("______________________________",
style: TextStyle(
fontSize: 25,
fontStyle: FontStyle.normal,
fontWeight: FontWeight.normal,
color: Color(0xff313640),
),),
],
)
)
);
}
}
I tried using sizedBox(), but no luck, my design shows a lot of space and I don't like that, it doesn't look great in my opinion, so, I have to erase the MainAxisAlignment to achieve the first design? Or what properties do I have to write?
Thank you in advance
Could you try to change MainAxisAlignment from spaceEvenly to center? You could see the difference between them.
Actually, I fully use SizeBox to separate them with specific spaces.
mainAxisAlignment: MainAxisAlignment.spaceEvenly
mainAxisAlignment: MainAxisAlignment.center
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Padding(
padding: EdgeInsets.symmetric(horizontal: 24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Flexible(
child: Hero(
tag: 'logo',
child: Container(
height: 200.0,
child: Image.asset('images/logo.png'),
),
),
),
SizedBox(
height: 48.0,
),
TextField(
keyboardType: TextInputType.emailAddress,
textAlign: TextAlign.center,
onChanged: (value) {
email = value;
//Do something with the user input.
}, decoration: kTextFieldDecoration.copyWith(hintText: 'Eenter your email')),
SizedBox(
height: 8.0,
),
TextField(
obscureText: true,
textAlign: TextAlign.center,
onChanged: (value) {
password = value;
//Do something with the user input.
},
decoration: kTextFieldDecoration.copyWith(hintText: 'Eenter your password')),
SizedBox(
height: 24.0,
),
RoundButton(
title: 'Register',
colour: Colors.blueAccent,
onPressed: () async{
print(email);
print(password);
print('Register');
//Go to login screen.
// Navigator.pushNamed(context, RegistrationScreen.id);
try{
final newUser = await _auth.createUserWithEmailAndPassword(email: email, password: password);
if (newUser != null) {
Navigator.pushNamed(context, ChatScreen.id);
}
}
catch(e) {
print(e);
}
},
),
],
),
),
);
enter image description here

How to align button in onboarding screen flutter

I wanted to add a login button below the onboarding screen: how could I do that? Below I have provided the picture of the screen and the code I have implemented so far. Appreciate your help on this.
class OnBoardingScreen extends StatefulWidget {
const OnBoardingScreen({Key? key}) : super(key: key);
#override
_OnBoardingScreenState createState() => _OnBoardingScreenState();
}
class _OnBoardingScreenState extends State<OnBoardingScreen> {
PageController _controller = PageController();
//keep track of if we are on the last page or not
bool onLastPage = false;
#override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
PageView(
onPageChanged: (index) {
setState(() {
onLastPage = (index == 2);
});
},
controller: _controller,
children: [
IntroPageOne(),
IntroPageTwo(),
IntroPageThree(),
],
),
//dot indicators
Container(
alignment: Alignment(0, 0.6),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
//skip
GestureDetector(
onTap: () {
_controller.jumpTo(2);
},
child: Text('Skip', style: TextStyle(
height: 1.2,
fontFamily: "Roboto",
fontSize: 15,
color: MainGreen,
fontWeight: FontWeight.w500,
// fontWeight: FontWeight.w100,
))),
SmoothPageIndicator(
controller: _controller,
count: 3,
effect: WormEffect(
dotColor: Colors.grey,
activeDotColor: MainGreen,
),
),
//next or done
onLastPage
? GestureDetector(
onTap: () {
Get.to(() => const LoginScreen());
},
child: Text('Done',
style: TextStyle(
height: 1.2,
fontFamily: "Roboto",
fontSize: 15,
color: MainGreen,
fontWeight: FontWeight.w500,
// fontWeight: FontWeight.w100,
)),
)
: GestureDetector(
onTap: () {
_controller.nextPage(
duration: Duration(milliseconds: 500),
curve: Curves.easeIn,
);
},
child: Text('Next', style: TextStyle(
height: 1.2,
fontFamily: "Roboto",
fontSize: 15,
color: MainGreen,
fontWeight: FontWeight.w500,
// fontWeight: FontWeight.w100,
)),
)
],
)),
MainButton("Login")
],
));
}
}
Step by step:
Wrap your Stack by Expanded.
Wrap Expanded by Column.
Move MainButton("Login") from Stack children to Column children.
Like this:
#override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(child: Stack(...)),
MainButton("Login"),
]
),
);
}
Since your goal is to have 2 widgets displayed in a vertical way, then you should use a Column instead of stacking everything.
Something like this
import 'package:flutter/material.dart';
class OnBoardingScreen extends StatefulWidget {
const OnBoardingScreen({Key? key}) : super(key: key);
#override
_OnBoardingScreenState createState() => _OnBoardingScreenState();
}
class _OnBoardingScreenState extends State<OnBoardingScreen> {
PageController _controller = PageController();
//keep track of if we are on the last page or not
bool onLastPage = false;
#override
Widget build(BuildContext context) {
return Scaffold(
body: Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Stack(
children: [
PageView(
onPageChanged: (index) {
setState(() {
onLastPage = (index == 2);
});
},
controller: _controller,
children: [
IntroPageOne(),
IntroPageTwo(),
IntroPageThree(),
],
),
//dot indicators
Container(
alignment: Alignment(0, 0.6),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
//skip
GestureDetector(
onTap: () {
_controller.jumpTo(2);
},
child: Text(
'Skip',
style: TextStyle(
height: 1.2,
fontFamily: "Roboto",
fontSize: 15,
color: MainGreen,
fontWeight: FontWeight.w500,
// fontWeight: FontWeight.w100,
),
),
),
SmoothPageIndicator(
controller: _controller,
count: 3,
effect: WormEffect(
dotColor: Colors.grey,
activeDotColor: MainGreen,
),
),
//next or done
onLastPage
? GestureDetector(
onTap: () {
Get.to(() => const LoginScreen());
},
child: Text('Done',
style: TextStyle(
height: 1.2,
fontFamily: "Roboto",
fontSize: 15,
color: MainGreen,
fontWeight: FontWeight.w500,
// fontWeight: FontWeight.w100,
)),
)
: GestureDetector(
onTap: () {
_controller.nextPage(
duration: Duration(milliseconds: 500),
curve: Curves.easeIn,
);
},
child: Text(
'Next',
style: TextStyle(
height: 1.2,
fontFamily: "Roboto",
fontSize: 15,
color: MainGreen,
fontWeight: FontWeight.w500,
// fontWeight: FontWeight.w100,
),
),
)
],
),
),
],
),
MainButton("Login"),
],
),
),
);
}
}
Try below code hope its helpful to you. I have try without Stack widget Wrap your Button inside Expanded and give its to alignment
Column(
children: <Widget>[
Text('All Leads'),
Text('Widget 2'),
Text('Widget 3'),
Text('Widget 4'),
Expanded(
child: Align(
alignment: FractionalOffset.bottomCenter,
child: ElevatedButton(
onPressed: () {},
child: Text('Login'),
),
),
),
],
),
Result Screen->

DioError [DioErrorType.response] Http status error [404] - flutter

DioError [DioErrorType.response] Http status error [404] - flutter
I'm creating a forget password screen for my app. I want to display "email sent" message when I click "Reset password " button.. instead of that ,I'm getting above error when I'm enter already registered email address. postman request is successfully working. how to solve this issue. appreciate your help on this.
import 'package:dio/dio.dart';
import 'package:doctor_app/constants/Button.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import '../constants/colors.dart';
class ForgetPassword extends StatelessWidget {
const ForgetPassword({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.leanBack);
return Scaffold(
resizeToAvoidBottomInset: false,
body: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
SizedBox(
height: 20,
),
Text('DOCTOR',
style: TextStyle(
fontFamily: 'Dubai',
fontSize: 30,
color: Color(0xff05ABA3),
fontWeight: FontWeight.w500,
)),
],
),
Spacer(
flex: 1,
),
Row(mainAxisAlignment: MainAxisAlignment.start, children: [
Text('Forgot your password?',
style: TextStyle(
height: 1.2,
fontFamily: 'Dubai',
fontSize: 25,
color: Color(0xff040000),
fontWeight: FontWeight.w500,
)),
]),
Spacer(
flex: 1,
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text('Confirm your email and we will send the Instructions ',
style: TextStyle(
height: 1.2,
fontFamily: 'Dubai',
fontSize: 18,
color: Color(0xff707070),
fontWeight: FontWeight.w100,
)),
],
),
Spacer(
flex: 1,
),
ForgetPasswordForm(), //email
Spacer(
flex: 1,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'didnt receive an email?',
style: TextStyle(
height: 1.2,
fontFamily: 'Dubai',
fontSize: 13,
color: Colors.grey,
fontWeight: FontWeight.w500,
),
),
SizedBox(
width: 5,
),
Align(
alignment: Alignment.bottomLeft,
child: InkWell(
onTap: () {
// add action here whatever you want.
},
child: Text('send again ',
style: TextStyle(
height: 1.2,
fontFamily: 'Dubai',
fontSize: 13,
color: Colors.blue,
fontWeight: FontWeight.w500,
))))
],
),
Spacer(
flex: 1,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5.0),
color: Color(0xff05ABA3),
),
height: 5,
width: 120,
),
],
),
],
),
),
);
}
}
class ForgetPasswordForm extends StatefulWidget {
const ForgetPasswordForm({Key? key}) : super(key: key);
#override
_ForgetPasswordFormState createState() => _ForgetPasswordFormState();
}
class _ForgetPasswordFormState extends State<ForgetPasswordForm> {
final _formKey = GlobalKey<FormState>();
//String _userName = "";
String email = "";
Future Resetpassword() async {
try {
var response = await Dio().post(
'https://doctor-app2-hit.herokuapp.com/user/forgotpassword',
data: {
"email": email,
});
if (response.data["data"] ==
"Please check your email to reset password.") {
Get.snackbar("success", "Email Sent Successfully!");
//Get.to(VideoScreen());
}else{
Get.snackbar("error", "No User Found");
}
print("res: $response");
} catch (e) {
Get.snackbar("error", "Server Error");
print(e);
}
}
#override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Form(
child: Container(
key: _formKey,
child: Container(
child: Padding(
padding: const EdgeInsets.all(30.0),
child: Column(children: [
TextFormField(
keyboardType: TextInputType.emailAddress,
decoration: const InputDecoration(
hintText: "Email",
hintStyle: TextStyle(
color: textGrey,
fontFamily: "Dubai",
fontSize: 14)),
validator: (String? Email) {
if (Email != null && Email.isEmpty) {
return "Email can't be empty";
}
return null;
}),
SizedBox(
height: 50,
),
Container(
child: GestureDetector(
child: ButtonM("Reset Password"),
onTap: () async {
Resetpassword();
},
),
)
]),
)))));
}
}
404 is thrown since the endpoint you are trying to call cannot be found. Notice that the URL you try to call has two forward slashes before the user path.
Change this: https://doctor-app2-hit.herokuapp.com//user/forgotpassword
to this: https://doctor-app2-hit.herokuapp.com/user/forgotpassword

email validation flutter before running API

I'm making forget password screen for my app and API has integrated in my code. when I click "reset password" button by submitting empty field it running my API code. but I want to run email validation when I submit empty field and click "reset button". how can I do that part in my code. appreciate your help on this.
import 'package:dio/dio.dart';
import 'package:doctor_app/constants/Button.dart';
import 'package:doctor_app/constants/base_api.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import '../constants/colors.dart';
class ForgetPassword extends StatelessWidget {
const ForgetPassword({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.leanBack);
return Scaffold(
resizeToAvoidBottomInset: false,
body: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
SizedBox(
height: 20,
),
Text('DOCTOR',
style: TextStyle(
fontFamily: 'Dubai',
fontSize: 30,
color: Color(0xff05ABA3),
fontWeight: FontWeight.w500,
)),
],
),
SizedBox(
height: 90,
),
Row(mainAxisAlignment: MainAxisAlignment.start, children: [
Text('Forgot your password?',
style: TextStyle(
height: 1.2,
fontFamily: 'Dubai',
fontSize: 25,
color: Color(0xff040000),
fontWeight: FontWeight.w500,
)),
]),
// Spacer(
// flex: 1,
// ),
SizedBox(
height: 20,
),
Column(
//mainAxisAlignment: MainAxisAlignment.center,
//crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text('Confirm your email and we will send the Instructions ',
style: TextStyle(
height: 1.2,
fontFamily: 'Dubai',
fontSize: 18,
color: Color(0xff707070),
fontWeight: FontWeight.w100,
)),
],
),
SizedBox(
height: 20,
),
ForgetPasswordForm(), //email
SizedBox(
height: 5,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'didnt receive an email?',
style: TextStyle(
height: 1.2,
fontFamily: 'Dubai',
fontSize: 13,
color: Colors.grey,
fontWeight: FontWeight.w500,
),
),
SizedBox(
width: 5,
),
Align(
alignment: Alignment.bottomLeft,
child: InkWell(
onTap: () {
// add action here whatever you want.
},
child: Text('send again ',
style: TextStyle(
height: 1.2,
fontFamily: 'Dubai',
fontSize: 13,
color: Colors.blue,
fontWeight: FontWeight.w500,
))))
],
),
Spacer(
flex: 1,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5.0),
color: Color(0xff05ABA3),
),
height: 5,
width: 120,
),
],
),
],
),
),
);
}
}
class ForgetPasswordForm extends StatefulWidget {
const ForgetPasswordForm({Key? key}) : super(key: key);
#override
_ForgetPasswordFormState createState() => _ForgetPasswordFormState();
}
class _ForgetPasswordFormState extends State<ForgetPasswordForm> {
final _formKey = GlobalKey<FormState>();
//String _userName = "";
String email = "";
Future Resetpassword() async {
try {
var response = await Dio().post(BASE_API+'user/forgotpassword', data: {
"email": email,
});
if (response.data["data"] ==
"Please check your email to reset password.") {
Get.snackbar("success", "Email Sent Successfully!");
//Get.to(VideoScreen());
} else {
Get.snackbar("Error", "No Server Found",
backgroundColor: textWhite.withOpacity(0.5),
borderWidth: 1,
borderColor: textGrey,
colorText: textGrey,
icon: Icon(
Icons.error_outline_outlined,
color: heartRed,
size: 30,
));
}
print("res: $response");
} catch (e) {
Get.snackbar("Error", "Something went wrong.Please contact admin",
backgroundColor: textWhite.withOpacity(0.5),
borderWidth: 1,
borderColor: textGrey,
colorText: textGrey,
icon: Icon(
Icons.error_outline_outlined,
color: heartRed,
size: 30,
));
print(e);
}
}
#override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Form(
child: Container(
key: _formKey,
child: Container(
child: Padding(
padding: const EdgeInsets.all(30.0),
child: Column(children: [
TextFormField(
keyboardType: TextInputType.emailAddress,
decoration: const InputDecoration(
hintText: "Email",
hintStyle: TextStyle(
color: textGrey,
fontFamily: "Dubai",
fontSize: 14)),
validator: (String? Email) {
if (Email != null && Email.isEmpty) {
return "Email can't be empty";
}
return null;
},
onChanged: (String? text) {
email = text!;
print(email);
},
),
SizedBox(
height: 50,
),
Container(
child: GestureDetector(
child: ButtonM("Reset Password"),
onTap: () async {
Resetpassword();
},
),
)
]),
)))));
}
}
Just wrap your ResetPassword() method like below:
if (_formKey.currentState!.validate()) {
Resetpassword();
}
This will check the validation.
Make sure key in attached to Form widget not Container
class ForgetPasswordForm extends StatefulWidget {
const ForgetPasswordForm({Key? key}) : super(key: key);
#override
_ForgetPasswordFormState createState() => _ForgetPasswordFormState();
}
class _ForgetPasswordFormState extends State<ForgetPasswordForm> {
final _formKey = GlobalKey<FormState>();
String email = "";
Future Resetpassword() async {
print("123");
}
#override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Form(
key: _formKey,
autovalidateMode: AutovalidateMode.disabled,
child: Container(
child: Container(
child: Padding(
padding: const EdgeInsets.all(30.0),
child: Column(children: [
TextFormField(
keyboardType: TextInputType.emailAddress,
decoration: const InputDecoration(
hintText: "Email",
hintStyle: TextStyle(
color: Colors.grey,
fontFamily: "Dubai",
fontSize: 14)),
validator: (String? Email) {
if (Email != null && Email.isEmpty) {
return "Email can't be empty";
}
return null;
},
onChanged: (String? text) {
email = text!;
print(email);
},
),
SizedBox(
height: 50,
),
Container(
child: TextButton(
child: Text("Reset Password"),
onPressed: () async {
if (_formKey.currentState!.validate()) {
Resetpassword();
}
},
),
)
]),
)))));
}
}
Add variable
final GlobalKey<FormState> keys = GlobalKey<FormState>();
validate like that
if (_keys.currentState!.validate()) {
Resetpassword();
}

Two screen overlapping flutter?

I am new to flutter development and i am doing it from past 3 months and i never have that issue when i press back.
Whenever i press back and back to home screen screen overlap:
here is my code of home screen:
class HomePage extends StatefulWidget {
#override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
BannerAd _bottomBannerAd;
bool _isBottomBannerAdLoaded = false;
final BannerAd myBanner = BannerAd(
adUnitId: 'ca-app-pub-3940256099942544/6300978111',
size: AdSize.banner,
request: AdRequest(),
listener: BannerAdListener(),
);
#override
void initState() {
super.initState();
myBanner.load();
}
#override
Widget build(BuildContext context) {
return Container(
child: Scaffold(
bottomNavigationBar: Container(
height: 50,
width: 320,
child: AdWidget(ad: myBanner,),
) ,
backgroundColor: Colors.transparent,
body: SingleChildScrollView(
child: Column(
children: <Widget>[NavBar(), Body()],
)),
));
}
}
class Body extends StatelessWidget {
#override
Widget build(BuildContext context) {
return ResponsiveLayout(
largeScreen: LargeChild(),
smallScreen: SmallChild(),
);
}
}
class LargeChild extends StatelessWidget {
#override
Widget build(BuildContext context) {
return SizedBox(
height: 600,
child: Stack(
fit: StackFit.expand,
children: <Widget>[
FractionallySizedBox(
alignment: Alignment.centerLeft,
widthFactor: .6,
child: Padding(
padding: EdgeInsets.only(left: 48),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
"Memory Game",
style: TextStyle(
fontSize: 60,
fontWeight: FontWeight.bold,
fontFamily: "Montserrat-Regular",
color: Color(0xFF111111)),
),
RichText(
text: TextSpan(
text: "Say Hi to ",
style: TextStyle(
fontSize: 60, color: Color(0xFF8591B0)),
children: [
TextSpan(
text: "🐱",
style: TextStyle(
fontSize: 60,
fontWeight: FontWeight.bold,
// color: Colors.black54
))
],
),
),
SizedBox(
height: 40,
),
Search()
])))
],
),
);
}
}
class SmallChild extends StatelessWidget {
#override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Padding(
padding: EdgeInsets.all(40),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
"Memory Game!",
style: TextStyle(
fontSize: 60,
fontWeight: FontWeight.bold,
fontFamily: "Montserrat-Regular",
color: Colors.white),
),
RichText(
text: TextSpan(
text: "Play Now",
style: TextStyle(fontSize: 60, color: Color(0xFF8591B0)),
children: [
TextSpan(
text: "🐱",
style: TextStyle(
fontSize: 40,
fontWeight: FontWeight.bold,
))
],
),
),
SizedBox(
height: 32,
),
Search(),
SizedBox(
height: 30,
)
],
),
));
}
}
Problem:Whenever i press back whole screen apears in back of home screen as you can see in the provided gif.
Can someone please tell me that why is this happening?
Its happening just because you have written backgroundColor: Colors.transparent, in your Scaffold
Try to change it with some another color and check it out, you will not face the problem.