0

Trying to update BottomNavigationBarItems based on user successful signUp/signIn. Not an expert in flutter or AWS, but have tried using either of the following to update a bool flag to render _listA or _listB

  • Amplify.Auth.fetchAuthSession()
  • Amplify.Auth.getCurrentUser()

The problem I'm having is the BottomNavigationBar renders faster than the above functions and app needs to reload to show the correct bar items.

Is there a solution like the following?

bottomNavigationBar: StreamBuilder<SomeState>(
   stream: Amplify.Auth.SomeState,
   builder: (context, snapshot) {
     return BottomNavigationBar(
...

Any other alternative would be appreciated as well.

kenta_desu
  • 303
  • 1
  • 9

1 Answers1

-1

You can't directly use a StreamBuilder for this job, but you can use StreamsubScription for auth events:

final subscription = Amplify.Hub.listen(HubChannel.Auth,(AuthHubEvent event) {
  switch (event.type) {
    case AuthHubEventType.signedIn:
      safePrint('User is signed in.');
      break;
    case AuthHubEventType.signedOut:
      safePrint('User is signed out.');
      break;
    case AuthHubEventType.sessionExpired:
      safePrint('The session has expired.');
      break;
    case AuthHubEventType.userDeleted:
      safePrint('The user has been deleted.');
      break;
  }
});

You can read the documentation for more information: https://docs.amplify.aws/lib/auth/auth-events/q/platform/flutter/

  • Ravan Alaskarov, a link to a solution is welcome, but please ensure your answer is useful without it: [add context around the link](//meta.stackexchange.com/a/8259) so your fellow users will have some idea what it is and why it is there, then quote the most relevant part of the page you are linking to in case the target page is unavailable. [Answers that are little more than a link may be deleted.](/help/deleted-answers) – M-- Sep 02 '23 at 17:24
  • @M-- You're right. I've edited my reply. – Ravan Alaskarov Sep 02 '23 at 18:51