Issue
I tried to use the google auth login code as it is during the splash screen on this site, but I still get a late error
class SplashScreen extends StatefulWidget {
@override
_SplashScreenState createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
final FirebaseAuth _auth = FirebaseAuth.instance;
late User _user;
@override
void initState() {
super.initState();
initializeUser();
_initUser();
}
Future initializeUser() async {
await Firebase.initializeApp();
final User? firebaseUser = await FirebaseAuth.instance.currentUser;
await firebaseUser!.reload();
_user = (await _auth.currentUser)!;
// get User authentication status here
}
_initUser() async {
if (_auth.currentUser != null) {
Timer(
Duration(seconds: 2),
() => Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(
builder: (context) =>
MainScreen(_user)),
(Route<dynamic> route) => false),
);
} else {
Timer(Duration(seconds: 1),
() => Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(
builder: (context) =>
MyHomePage()),
(Route<dynamic> route) => false),
);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Text("Splash Screen"),
),
);
}
}
The contents of MyHomePage() or MainScreen(_user) also typed the site code as it is, but the error is still there. Before gradle upgrade, this code worked normally, but after jdk version up and gradle upgrade, the damn late error does not stop.
This is the error
Performing hot restart...
Syncing files to device sdk gphone x86...
Restarted application in 1,320ms.
W/DynamiteModule( 6646): Local module descriptor class for com.google.android.gms.providerinstaller.dynamite not found.
I/DynamiteModule( 6646): Considering local module com.google.android.gms.providerinstaller.dynamite:0 and remote module com.google.android.gms.providerinstaller.dynamite:0
W/ProviderInstaller( 6646): Failed to load providerinstaller module: No acceptable module com.google.android.gms.providerinstaller.dynamite found. Local version is 0 and remote version is 0.
I/om.gwon.goodma( 6646): The ClassLoaderContext is a special shared library.
I/om.gwon.goodma( 6646): The ClassLoaderContext is a special shared library.
I/TetheringManager( 6646): registerTetheringEventCallback:com.gwon.goodman
V/NativeCrypto( 6646): Registering com/google/android/gms/org/conscrypt/NativeCrypto's 294 native methods...
W/om.gwon.goodma( 6646): Accessing hidden method Ljava/security/spec/ECParameterSpec;->getCurveName()Ljava/lang/String; (greylist, reflection, allowed)
I/ProviderInstaller( 6646): Installed default security provider GmsCore_OpenSSL
I/FirebaseAuth( 6646): [FirebaseAuth:] Preparing to create service connection to fallback implementation
W/System ( 6646): Ignoring header X-Firebase-Locale because its value was null.
W/om.gwon.goodma( 6646): Accessing hidden field Ljava/net/Socket;->impl:Ljava/net/SocketImpl; (greylist, reflection, allowed)
W/om.gwon.goodma( 6646): Accessing hidden method Ldalvik/system/CloseGuard;->get()Ldalvik/system/CloseGuard; (greylist,core-platform-api, linking, allowed)
W/om.gwon.goodma( 6646): Accessing hidden method Ldalvik/system/CloseGuard;->open(Ljava/lang/String;)V (greylist,core-platform-api, linking, allowed)
W/om.gwon.goodma( 6646): Accessing hidden method Ljava/security/spec/ECParameterSpec;->setCurveName(Ljava/lang/String;)V (greylist, reflection, allowed)
W/om.gwon.goodma( 6646): Accessing hidden method Ldalvik/system/BlockGuard;->getThreadPolicy()Ldalvik/system/BlockGuard$Policy; (greylist,core-platform-api, linking, allowed)
W/om.gwon.goodma( 6646): Accessing hidden method Ldalvik/system/BlockGuard$Policy;->onNetwork()V (greylist, linking, allowed)
======== Exception caught by widgets library =======================================================
The following LateError was thrown building MainScreen(dirty, dependencies: [_InheritedProviderScope<Pro?>], state: _MainScreenState#c8d34):
LateInitializationError: Field '_instance@21075166' has not been initialized.
The relevant error-causing widget was:
MainScreen MainScreen:file:///F:/flutter%20project/good_man/lib/main.dart:81:25
The code on that site is the code from November 2020, but in the meantime, there was a change in the rules of Timer and google auth... The error is maintained even if you write the same code that uses Future and checks for null using ![enter image description here][1]
This is not a duplicate of the last late question post. After seeing the advice in that article, I wrote down the same code of the blog where I first wrote this code, but I am still embarrassed that the Late error is maintained.
Solution
Even though you are initializing these variables inside the initUser(), but you will get this error if you are using the variables inside the build() method since initUser() is asynchronous meaning it will take time to get the data from the collection. To solve this you can do:
@override
void initState() {
super.initState();
_initUser().whenComplete((){
setState(() {});
});
}
This will rebuild the widget tree with the new values.
Answered By - Raja Ehtisham
Answer Checked By - Senaida (JavaFixing Volunteer)