0

this is what shows after login and its working. I need to display the code below whenever a user is not logged in.

 Text(
            'Hello,\n ${loggedInUser.firstName}',
            style: const TextStyle(
              color: cyan,
              fontSize: 20,
            ),
          ),

i want to show this after logout

 Text(
            'Hello,\n please login',
            style: const TextStyle(
              color: cyan,
              fontSize: 20,
            ),
          ),
James Z
  • 12,209
  • 10
  • 24
  • 44

2 Answers2

0

I think that you can use an ternary operator, something like this

return loggedInUser is true
       ? text('Hello,\n ${loggedInUser.firstName}')
       : text('Hello,\n Please Login');

In loggedInUser you need to detect is the state of the user is logged or not.

(With a ternary operator you are basically doing an if else operator)

lasd
  • 26
  • 4
0

If when the user is logged out, the loggedInUser or loggedInUser.firstName is null, just check it and display the text based on the outcome:

Text("Hello,\n" + loggedInUser.firstName ?? "Please Login",
                style: const TextStyle(color: cyan, fontSize: 20))

The ?? double question mark operator means "if null".

See more information about here.

Dani3le_
  • 1,257
  • 1
  • 13
  • 22