Home > database >  Flutter : Unable to navigate to next screen getting consider canceling any active work during "
Flutter : Unable to navigate to next screen getting consider canceling any active work during "

Time:11-27

when i am trying to navigate screen i am getting this error

E/flutter (11689): Consider canceling any active work during "dispose" or using the "mounted" getter to determine if the State is still active. E/flutter (11689): #0 State.context. package:flutter/…/widgets/framework.dart:909 E/flutter (11689): #1
State.context package:flutter/…/widgets/framework.dart:915 E/flutter (11689): #2 _SplashScreenState._checkIfIsLogged. package:losedafat/screens/splash_screen.dart:81

please check below code and images

Future<void> _checkIfIsLogged() async {
final accessToken = await FacebookAuth.instance.accessToken;


if (accessToken != null) {
  //print("is Logged:::: ${(accessToken.toJson())}");

  Services.fbtoken = accessToken.toJson()['token'];
  //print(Services.fbtoken);

  // now you can call to  FacebookAuth.instance.getUserData();
  var data = await FacebookAuth.instance.getUserData(fields: "picture");
  Services.photo = data['picture']['data']['url'];

  /// this function will build json data in `package:losedafat/handlers/user_account_check.dart`
  FacebookAccountCheck(context).buildFBJson();

  Timer(
    const Duration(seconds: 3),
    () => Navigator.pushReplacement(
      context,
      MaterialPageRoute(
        builder: (context) => const nScreen(),
      ),
    ),
  );
 }
}

Error Image enter image description here

CodePudding user response:

on line 81 write if(mounted){ //your code }

CodePudding user response:

i suspect the issue is with the widget being already disposed, look at the line before this

flutter (11689): Consider canceling

in your log, it says the widget was already unmounted and you're trying to access the context, also consider using this instead of timer (which i also suspect is causing an issue)

await Future.delayed(Duration(seconds:3)) 

then navigating

  • Related