I AM trying to create a login page with flutter and firebase the navigator worked properly in all files but when coming to this page it shows an error at the context in the navigator the error is
'The argument type 'Context' can't be assigned to the parameter type 'BuildContext'. the following are the details of my flutter version: version: 1.0.0+1
environment: sdk: ">=2.1.0 <3.0.0"
dependencies: flutter: sdk: flutter curved_navigation_bar: ^0.3.2 oktoast: firebase_auth: ^0.5.20 please help me to solve this
import 'package:path/path.dart';
import 'package:codej/effects.dart';
import 'package:flutter/material.dart';
import 'package:oktoast/oktoast.dart';
import 'package:firebase_auth/firebase_auth.dart';
class Auth extends StatefulWidget {
@override
_AuthState createState() => new _AuthState();
}
class _AuthState extends State<Auth>{
String _email, _password;
final GlobalKey<FormState> formkey = GlobalKey<FormState>();
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(appBar: AppBar(
title: Text("Authentication"),
),
// TODO: implement build
body: Form(
key: formkey,
child: Column(
children: <Widget>[
TextFormField(
validator: (input){
if(input.isEmpty){
showToastWidget(Text("please enter your user name"));
}
},
onSaved: (input) => _email = input,
decoration: InputDecoration(
labelText: 'Email'
),
),
TextFormField(
validator: (input){
if(input.length < 6){
showToastWidget(Text("please enter your password atleast 6 characters"));
}
},
onSaved: (input) => _password = input,
decoration: InputDecoration(
labelText: 'Password'
),
obscureText: true,
),
RaisedButton(onPressed: (){
},
child: Text("Sign in"),)
],
)),
);
}
void signinAuth() async{
final formState = formkey.currentState;
if(formState.validate()){
formState.save();
try{
FirebaseUser user = await FirebaseAuth.instance.signInWithEmailAndPassword(email: _email, password: _password);
Navigator.push(context, MaterialPageRoute(builder: (context) => BottomNav())); //BottomNav loacted in other file
}catch(e){
print(e.message);
}
}
}
}
This is working on my pc, so it is version problem. Try updating your flutter and dart sdk, if this is not the solution for you, just pass BuildContext to your signinAuth like this
void signinAuth(BuildContext context) async {
final formState = formkey.currentState;
if (formState.validate()) {
formState.save();
try {
FirebaseUser user = await FirebaseAuth.instance
.signInWithEmailAndPassword(email: _email, password: _password);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
BottomNav())); //BottomNav loacted in other file
} catch (e) {
print(e.message);
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.