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,
),
),
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)
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 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.