jeudi 6 mai 2021

how can i routeing with statement in Flutter

I have login page. After i login, i want to check is the user has telephone number. If user has phone number, then he need to go homepage, but if he has not phone number, then he need to go telephone number page which provide saving his phone number with an input. I work with firestore and cubits. Can you help me please ?

Extra information: When user logins the app, firestore create this user informations in firebase.

'email' : userEmail@example.com
'password' : userPassword
phoneNumber : ""

( I try to put 'if' statement above of the Navigator homepage, but it does not work or i couldn't do it. )

here my landing page for user:

class LandingPage extends StatefulWidget {
  static const String id = 'landing_page';
  @override
  _LandingPageState createState() => _LandingPageState();
}

class _LandingPageState extends State<LandingPage> {
  @override
  void didChangeDependencies() {
    bool isUserStateChecked =
        BlocProvider.of<AuthCubit>(context).state.isUserChecked;
    bool isUserSignedIn =
        BlocProvider.of<AuthCubit>(context).state.isUserSignedIn;

    if (isUserStateChecked && isUserSignedIn) {
      Navigator.of(context).push(MaterialPageRoute(
        builder: (_) => HomePage(),
      ));
    } else if (isUserStateChecked && !isUserSignedIn) {
      Navigator.of(context).push(MaterialPageRoute(
        builder: (_) => SignInPage(),
      ));
    }
    super.didChangeDependencies();
  }

  @override
  Widget build(BuildContext context) {
    return BlocListener<AuthCubit, AuthState>(
      listenWhen: (AuthState previous, AuthState current) =>
          previous.isUserChecked != current.isUserChecked &&
          current.isUserChecked,
      listener: (context, state) {
        if (state.isUserSignedIn) {
          Navigator.of(context).push(MaterialPageRoute(
            builder: (_) => HomePage(),
          ));
        } else if (!state.isUserSignedIn) {
          Navigator.of(context).push(MaterialPageRoute(
            builder: (_) => SignInPage(),
          ));
        }
      },
      child: CircularProgressIndicator(),
    );
  }
}

Aucun commentaire:

Enregistrer un commentaire