Hello all, I am getting this error can you please help me. [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: NoSuchMethodError: The method 'validate' was called on null.
E/flutter (13281): Receiver: null
E/flutter (13281): Tried calling: validate()
E/flutter (13281): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:50:5)
here is the code for the log in page
import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter_app_dating/pages/home.dart';
class LoginPage extends StatefulWidget {
@override
_LoginPageState createState( ) => _LoginPageState();
}
class _LoginPageState extends State<LoginPage> {
String _email, _password;
final GlobalKey<FormState> _formkey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('AppBar Ddemo'),
actions: <Widget>[
],
),
body:Form(
child: Column(
children: <Widget>[
TextFormField(
validator: (input){
if(input.isEmpty){
return 'Please put you remai';
}
//return(input);
},
onSaved: (input) => _email = input ,
decoration: InputDecoration(
labelText: 'Email'
) ,
),
TextFormField(
autovalidate: (),
validator: (input){
if(input.length < 6){
return 'Please enter you r 6 or over passport';
}
//return(input);
},
onSaved: (input) => _password = input ,
decoration: InputDecoration(
labelText: 'Enter you rpass'
) ,
obscureText: true,
),
RaisedButton(
onPressed:(){
SizedBox(
child: Text('dfedc '),
height: 22,
width: 52,
);
},
child: Text('sighn ic '),
),
IconButton(
icon: Icon(Icons.info),
onPressed:(){ signIn();
// Do something
},
)
],
),
),
);
}
Future<void> signIn() async{
final formState1 = _formkey.currentState;
if(formState1.validate()){
formState1.save();
}
try{
FirebaseUser user = await FirebaseAuth.instance.signInWithEmailAndPassword(email: _email, password: _password);
Navigator.push(context, MaterialPageRoute(builder: (context) => Home() ));
}catch(e){
print(e.message);
}
}
}
HERE IS THE CODE FOR THE HOME PAGE IN A DIFFRENT DART FILE
import 'package:flutter/material.dart';
class Home extends StatefulWidget {
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Home'),
),
);
}
}
HERE IS THE CODE FOR THE MAIN FILe
import 'package:flutter/material.dart';
import 'package:flutter_app_dating/SetUp/Login.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demhho',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: LoginPage(),
);
}
}