Reputation: 175
class _HomeScreenState extends State<HomeScreen> {
String uid = "";
@override
void initState() {
FirebaseAuth.instance.currentUser().then((user) {
setState(() {
uid = user.uid;
super.initState();
});
});
}
I run the latest version of Flutter, and have never experienced any of these issues before. Flutter completes the xcode build, opens up on the emulator but only with a white screen, and 1 second later Flutter crashes with these exceptions:
**Failed assertion: line 1110 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true.
#0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:42:39)
#1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:38:5)
#2 State.initState (package:flutter/src/widgets/framework.dart:1110:12)
#3 _HomeScreenState.initState.<anonymous closure>.<anonymous closure> (package:schoolEachother1_0/screens/home_screen.dart:25:15)
#4 State.setState (package:flutter/src/widgets/framework.dart:1233:30)
#5 _HomeScreenState.initState.<anonymous closure> (package:schoolEachother1_0/screens/home_screen.dart:23:7)
#6 _rootRunUnary (dart:async/zone.dart:1192:38)
#7 _CustomZone.runUnary (dart:async/zone.dart:1085:19)
#8 _FutureListener.handleValue (dart:async/future_impl.dart:141:18)*
#9 Future._propagateToListeners.handleValueCallback (dart:async/futu<…>
*** First throw call stack:
(
0 CoreFoundation 0x00007fff23e3cf0e __exceptionPreprocess + 350
1 libobjc.A.dylib 0x00007fff50ba89b2 objc_exception_throw + 48
2 CoreFoundation 0x00007fff23e3cc88 +[NSException raise:format:arguments:] + 88
3 Foundation 0x00007fff258b8c9b -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 166
4 Runner 0x00000001031ad6d7 _ZN8firebase9firestore4util16ObjcThrowHandlerENS1_13ExceptionTypeEPKcS4_iRKNSt3__112basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEE + 343
5 Runner 0x00000001031acf25 _ZN8firebase9firestore4util5ThrowENS1_13ExceptionTypeEPKcS4_iRKNSt3__<…>*
Anyone who is able to tell me what I'm doing wrong?
Thanks in advance
Upvotes: 0
Views: 660
Reputation: 679
super.initState()
must be called independently from the rest of the code in your initState()
method.
@override
void initState() {
FirebaseAuth.instance.currentUser().then((user) {
setState(() {
uid = user.uid;
});
});
super.initState();
}
Upvotes: 1
Reputation: 2007
Please remove super.initstate() from the setstate that would solve it : )
Upvotes: 0