roughike/flutter_facebook_login

Navigating away from login screen

Closed this issue · 4 comments

Hi Liro, Thanks for this awesome plug in! I'm having an issue where when I navigate to the next screen the previous screen still exists partially. Not sure if you've had this issue either and if it's related to the plug in or if it's just a flutter issue?

Hi!

Is the issue present on Android or iOS? Could you provide a code sample on how to reproduce the issue?

Thanks for responding! The issue I'm having is on Android. Absolutely! I'll paste it in below. The 1st class is the class I' m navigating from. Home class is the one I'm navigating to

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp( ),
      home: new LoginPage(),
      routes: <String, WidgetBuilder>{
        "/sure": (_) => new LoginPage(),
        MyHomePage.HomePageRouteName: (BuildContext context) => new Home(),
      },
    );
  }
}

class LoginPage extends StatefulWidget {
  @override
  State createState() => new _LoginPageState();
}

class FacebookLogger {
  BuildContext context;

  FacebookLogger(this.context);

  _HandleFacebookLogin() async {
    FacebookLogin facebookLogin = new FacebookLogin();
    facebookLogin.loginBehavior = FacebookLoginBehavior.nativeWithFallback;
    FacebookLoginResult facebookLoginResult = await facebookLogin
        .logInWithReadPermissions(["email"]);
    statusChecker(facebookLoginResult);
  }

  void statusChecker(FacebookLoginResult facebookLoginResult) {
    if (facebookLoginResult.status == FacebookLoginStatus.loggedIn) {
      Navigator.of(context).pop(context);
      Navigator.pushReplacementNamed(context, MyHomePage.HomePageRouteName);

    }
  }

}

class _LoginPageState extends State<LoginPage> {

  @override
  Widget build(BuildContext context) {

    return new Scaffold(body: new Center(
        child: new Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
          new Text("Login"),
          new IconButton(icon: new Icon(Icons.favorite),
            onPressed: () {
              new FacebookLogger(context)._HandleFacebookLogin();
            },
          ),
        ],)
    )
    );
  }
}


//In a new Dart file
class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    routes: <String, WidgetBuilder>{
      MyHomePage.HomePageRouteName: (BuildContext context) => new Home(),
    };
    return new MyHomePage();
  }
}

class MyHomePage extends StatefulWidget {

  static String HomePageRouteName = '/homepage';

  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  @override
  Widget build(BuildContext context) {
    Row toolbar = new Row(

        children: <Widget>[
          new Expanded(child: new Text('')),
          new IconButton(icon: binImage,
              onPressed: () {
                _onItemPressed("gotosettings");
              }),

        ]
    );
}

Oh, I see. I've encountered this bug before. The Facebook dialog seems to linger a little bit even though you get the result back just fine.

If you're in a hurry, as a temporary fix, you can do something like this:

void statusChecker(FacebookLoginResult facebookLoginResult) {
    if (facebookLoginResult.status == FacebookLoginStatus.loggedIn) {
        new Timer(
            const Duration(milliseconds: 500),
            () {
                Navigator.of(context).pop(context);
                Navigator.pushReplacementNamed(context, MyHomePage.HomePageRouteName);
            },
        );
    }
}

I'll look into a proper fix in the library when I have the time.

Thanks for that work around! Definitely a good temporary fix.