-2

I'm having hard time creating logic for this. I jave a flutter app in which i want to show same screen for both admin and user but for admin i want to add CRUD facilities. How can i achieve this in flutter?

Asif Shaik
  • 45
  • 8

1 Answers1

0

I am assuming that you have some sort of a backend/database where you know what kind of user is logging in. If you can share that information with Flutter, you can use conditional rendering of widgets.

You can use the Ternary operator.

user.type == 'admin' ? CustomWidget() : null

You can refer to this stackoverflow post that shares a few other ways to conditionally render.

Rohit Rao
  • 29
  • 1
  • 4
  • actually for my app a normal user doesn't need to login, only admins do for crud operations, i wanna do this with out any backend as i gonna share the id and password to every admin manually , my problem is i want to show the same screen for normal user and admin but for admin with add and delete button so he can regulate what normal user sees @Rohit Rao – Asif Shaik Feb 04 '22 at 12:49
  • Okay so just set a global boolean variable called isAdmin or something to True after the admin has logged in and pass that to functions and have its default value be false for normal users – Rohit Rao Feb 04 '22 at 13:56
  • i tried it but i just dont know how to make bool isAdmin change itself to true after admin logs in @Rohit Rao – Asif Shaik Feb 06 '22 at 05:59
  • Just after you verify that the login was successful. – Rohit Rao Feb 07 '22 at 06:26