'Not able to solve Unhandled Exception: Stack Overflow
I am trying to create a signUp page in flutter using Firebase Authentication. I ran into this error and I am not able to solve this please help me.
This is the SignUp page code
import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart';
class SignUp extends StatefulWidget {
@override
_SignUpState createState() => _SignUpState();
}
class _SignUpState extends State<SignUp> {
FirebaseAuth _auth = FirebaseAuth.instance;
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
late String _name, _email, _password;
checkAuthentication() async {
_auth.authStateChanges().listen((user) async {
if (user != null) {
Navigator.pushReplacementNamed(context, "/");
}
});
}
@override
void initState() {
super.initState();
this.checkAuthentication();
}
signUp() async {
if (_formKey.currentState!.validate()) {
_formKey.currentState!.save();
try {
UserCredential user = await _auth.createUserWithEmailAndPassword(
email: _email, password: _password);
await _auth.currentUser!.updateProfile(displayName: _name);
} catch (e) {
showError(e.toString());
print(e);
}
}
}
showError(String errormessage) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('ERROR'),
content: Text(errormessage),
actions: <Widget>[
FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text('OK'))
],
);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: Container(
child: Column(
children: <Widget>[
SizedBox(height: 50),
Container(
child: Image(
height: 200,
width: 200,
image: AssetImage("images/signuppic.png"),
fit: BoxFit.contain,
),
),
Container(
child: Form(
key: _formKey,
child: Column(
children: <Widget>[
Container(
child: TextFormField(
validator: (input) {
if (input!.isEmpty) return 'Enter Name';
},
decoration: InputDecoration(
labelText: 'Name',
prefixIcon: Icon(Icons.person),
),
onSaved: (input) => _name = input!),
),
SizedBox(height: 20),
Container(
child: TextFormField(
validator: (input) {
if (input!.isEmpty) return 'Enter Email';
},
decoration: InputDecoration(
labelText: 'Email',
prefixIcon: Icon(Icons.email)),
onSaved: (input) => _email = input!),
),
SizedBox(height: 20),
Container(
child: TextFormField(
validator: (input) {
if (input!.length < 6)
return 'Provide Minimum 6 Character';
},
decoration: InputDecoration(
labelText: 'Password',
prefixIcon: Icon(Icons.lock),
),
obscureText: true,
onSaved: (input) => _password = input!),
),
SizedBox(height: 40),
RaisedButton(
padding: EdgeInsets.fromLTRB(70, 10, 70, 10),
onPressed: signUp,
child: Text('SignUp',
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
fontWeight: FontWeight.bold)),
color: Colors.orange,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
),
)
],
),
),
),
],
),
),
));
}
}
This is the error I am getting
Restarted application in 2,098ms.
2
D/InputConnectionAdaptor( 9914): The input method toggled cursor monitoring on
I/TextInputPlugin( 9914): Composing region changed by the framework. Restarting the input method.
2
D/InputConnectionAdaptor( 9914): The input method toggled cursor monitoring on
E/flutter ( 9914): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Stack Overflow
E/flutter ( 9914): #0 Element.markNeedsBuild.<anonymous closure>
package:flutter/…/widgets/framework.dart:4402
E/flutter ( 9914): #1 Element.markNeedsBuild
package:flutter/…/widgets/framework.dart:4439
E/flutter ( 9914): #2 State.setState
package:flutter/…/widgets/framework.dart:1141
E/flutter ( 9914): #3 FormState._forceRebuild
package:flutter/…/widgets/form.dart:121
E/flutter ( 9914): #4 FormState.validate
package:flutter/…/widgets/form.dart:183
E/flutter ( 9914): #5 FormState.validate
package:flutter/…/widgets/form.dart:184
E/flutter ( 9914): #6 FormState.validate
package:flutter/…/widgets/form.dart:184
E/flutter ( 9914): #7 FormState.validate
package:flutter/…/widgets/form.dart:184
E/flutter ( 9914): #8 FormState.validate
package:flutter/…/widgets/form.dart:184
E/flutter ( 9914): #9 FormState.validate
package:flutter/…/widgets/form.dart:184
E/flutter ( 9914): #10 FormState.validate
package:flutter/…/widgets/form.dart:184
E/flutter ( 9914): #11 FormState.validate
package:flutter/…/widgets/form.dart:184
E/flutter ( 9914): #12 FormState.validate
package:flutter/…/widgets/form.dart:184
E/flutter ( 9914): #13 FormState.validate
package:flutter/…/widgets/form.dart:184
E/flutter ( 9914): #14 FormState.validate
package:flutter/…/widgets/form.dart:184
E/flutter ( 9914): #15 FormState.validate
package:flutter/…/widgets/form.dart:184
E/flutter ( 9914): #16 FormState.validate
package:flutter/…/widgets/form.dart:184
E/flutter ( 9914): #17 FormState.validate
package:flutter/…/widgets/form.dart:184
E/flutter ( 9914): #18 FormState.validate
package:flutter/…/widgets/form.dart:184
E/flutter ( 9914): #19 FormState.validate
package:flutter/…/widgets/form.dart:184
E/flutter ( 9914): #20 FormState.validate
package:flutter/…/widgets/form.dart:184
E/flutter ( 9914): #21 FormState.validate
package:flutter/…/widgets/form.dart:184
E/flutter ( 9914): #22 FormState.validate
package:flutter/…/widgets/form.dart:184
I didn't come across anyone who got this error. Is it a bug in Firebase Authentication error or Flutter Widget error?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
