Home > Back-end >  My flutter project splashscreen is freezing when I run the project maybe due to firebase error in th
My flutter project splashscreen is freezing when I run the project maybe due to firebase error in th

Time:11-21

Hello Guy's I am working on a flutter project. I had created I splash screen where first we check that is there any credentials exist. If yes then we try to login if some error occur we move to login else if no error we move to homescreen and If there is no credentials then we move to login.

The problem I am facing is my app freezes at the splash screen I can only see the UI.

Here is my code for getDataAndCheck function:

void getDataAndCheck() async {
    bool emailPresent = await sharedPreference().checkValuePresent('email');
    bool passwordPresent =
        await sharedPreference().checkValuePresent('password');
    email = (await sharedPreference().getCred('email')) ?? '';
    password = (await sharedPreference().getCred('password')) ?? '';
    Timer(const Duration(seconds: 3), () {
      print('Email: $email\nPassword: $password');
      if (emailPresent == true && passwordPresent == true) {
        print('inside if');
        firebaseAuth
            .signInWithEmailAndPassword(email: email, password: password)
            .catchError((errMsg) {
          print('inside catch error');
          if (errMsg.code == null) {
            print('When Null');
            Navigator.pushAndRemoveUntil(
              context,
              PageRouteBuilder(
                transitionDuration: const Duration(seconds: 1),
                transitionsBuilder: (context, animation, animationTime, child) {
                  animation = CurvedAnimation(
                      parent: animation, curve: Curves.fastLinearToSlowEaseIn);
                  return ScaleTransition(
                    scale: animation,
                    alignment: Alignment.center,
                    child: child,
                  );
                },
                pageBuilder: (context, animation, animationTime) {
                  return const HomeScreen();
                },
              ),
              (route) => false,
            );
          } else {
            print('When Not Null');
            sharedPreference().reset();
            Navigator.pushReplacement(
              context,
              PageRouteBuilder(
                transitionDuration: const Duration(seconds: 1),
                transitionsBuilder: (context, animation, animationTime, child) {
                  animation = CurvedAnimation(
                      parent: animation, curve: Curves.fastLinearToSlowEaseIn);
                  return ScaleTransition(
                    scale: animation,
                    alignment: Alignment.center,
                    child: child,
                  );
                },
                pageBuilder: (context, animation, animationTime) {
                  return const LoginOrSignUp();
                },
              ),
            );
          }
        });
      } else {
        print('When email and password in not present');
        sharedPreference().reset();
        Navigator.pushReplacement(
          context,
          PageRouteBuilder(
            transitionDuration: const Duration(seconds: 1),
            transitionsBuilder: (context, animation, animationTime, child) {
              animation = CurvedAnimation(
                  parent: animation, curve: Curves.fastLinearToSlowEaseIn);
              return ScaleTransition(
                scale: animation,
                alignment: Alignment.center,
                child: child,
              );
            },
            pageBuilder: (context, animation, animationTime) {
              return const LoginOrSignUp();
            },
          ),
        );
      }
    });
  }

Later I called that function into initState:

@override
  void initState() {
    super.initState();
    getDataAndCheck();
  }

The error state that:

Performing hot restart...
Syncing files to device sdk gphone64 x86 64...
Restarted application in 3,201ms.
W/DynamiteModule(15758): Local module descriptor class for com.google.android.gms.providerinstaller.dynamite not found.
I/DynamiteModule(15758): Considering local module com.google.android.gms.providerinstaller.dynamite:0 and remote module com.google.android.gms.providerinstaller.dynamite:0
W/ProviderInstaller(15758): Failed to load providerinstaller module: No acceptable module com.google.android.gms.providerinstaller.dynamite found. Local version is 0 and remote version is 0.
W/ConnectivityManager.CallbackHandler(15758): callback not found for CALLBACK_AVAILABLE message
D/EGL_emulation(15758): app_time_stats: avg=58800.26ms min=766.16ms max=116834.36ms count=2
D/EGL_emulation(15758): app_time_stats: avg=1744.28ms min=1744.28ms max=1744.28ms count=1
I/flutter (15758): Email: [email protected]
I/flutter (15758): Password: 123456
I/flutter (15758): inside if
W/System  (15758): Ignoring header X-Firebase-Locale because its value was null.
W/System  (15758): Ignoring header X-Firebase-Locale because its value was null.
D/FirebaseAuth(15758): Notifying id token listeners about user ( NcSwfsdw7fc6ZFXH0ylSRMNonW63 ).
D/EGL_emulation(15758): app_time_stats: avg=3078.58ms min=3078.58ms max=3078.58ms count=1

CodePudding user response:

You have put the redirection logic in the cathError block, but what if there's no error? It will not run.

Instead, try

firebaseAuth.signInWithEmailAndPassword(email: email, password: password).then((){
    
    // put your logic here for successful sign in

    }).cathError((error){

// you can handle errors here

})
  • Related