Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

Navigating away from login screen #14

Closed
svalexander opened this issue Mar 29, 2018 · 4 comments
Closed

Navigating away from login screen #14

svalexander opened this issue Mar 29, 2018 · 4 comments

Comments

@svalexander
Copy link

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?

@roughike
Copy link
Owner

Hi!

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

@svalexander
Copy link
Author

svalexander commented Mar 29, 2018

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");
              }),

        ]
    );
}

@roughike
Copy link
Owner

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.

@svalexander
Copy link
Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants