I have this error I have no idea what it means. please help!
E/flutter (17371): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: Scaffold.of() called with a context that does not contain a Scaffold.
E/flutter (17371): No Scaffold ancestor could be found starting from the context that was passed to Scaffold.of(). This usually happens when the context provided is from the same StatefulWidget as that whose build function actually creates the Scaffold widget being sought.
E/flutter (17371): There are several ways to avoid this problem. The simplest is to use a Builder to get a context that is "under" the Scaffold. For an example of this, please see the documentation for Scaffold.of():
E/flutter (17371): A more efficient solution is to split your build function into several widgets. This introduces a new context from which you can obtain the Scaffold. In this solution, you would have an outer widget that creates the Scaffold populated by instances of your new inner widgets, and then in these inner widgets you would use Scaffold.of().
E/flutter (17371): A less elegant but more expedient solution is assign a GlobalKey to the Scaffold, then use the key.currentState property to obtain the ScaffoldState rather than using the Scaffold.of() function.
E/flutter (17371): The context used was:
E/flutter (17371): LoginPage(state: _LoginPageState#93206)
here is my code: for the log in file
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 _formkey = GlobalKey<FormState>();
//final GlobalKey<FormState> _formkey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return Form(
key: _formkey,
child: Scaffold(
body:Form(
child: Column(
children: <Widget>[
TextFormField(
validator: (input){
if(input.isEmpty){
return 'Please put you remai';
}
return null;
},
onSaved: (input) => _email = input ,
decoration: InputDecoration(
labelText: 'Email'
) ,
),
TextFormField(
validator: (input){
if(input.length < 6){
return 'Please enter you r 6 or over passport';
}
return null;
//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
},
),*/
Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: RaisedButton(
onPressed: () {
signIn();
},
child: Text('Submit'),
),
),
],
),
),
),
);
}
Future<void> signIn() async{
final formState1 = _formkey.currentState;
if (_formkey.currentState.validate()) {
formState1.save();
Scaffold.of(context)
.showSnackBar(SnackBar(content: Text('Processing Data')));
}
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(),
);
}
}