为未经授权的用户隐藏应用程序中的内容 - Flutter Firebase
所以我想显示一个特殊的按钮。仅当用户使用正确的权限登录时,该按钮才应起作用(或可见)。
我发现我可以用 flutter firestore 以某种方式做到这一点。我如何将其实现到我的代码中?如果您需要我的 firestore 数据库中的更多代码或信息(屏幕),请在评论中询问。 :)
//serverstatuspage
final serverstatuspage = Material(
elevation: 5,
borderRadius: BorderRadius.circular(30),
color: Colors.green,
child: MaterialButton(
padding: EdgeInsets.fromLTRB(20, 15, 20, 15),
minWidth: MediaQuery.of(context).size.width,
onPressed: () {
serverstatusbutton(context);
},
child: Text(
"Admin Dashboard",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20,
color: Colors.white,
fontWeight: FontWeight.bold),
)));
So i want to show a special button. The button should only work (or be seen) when the user is logged in with the right permissions.
I saw that i can somehow do this with flutter firestore. How can i implement this to my code? If you need more code or infos (screens) from my firestore database just ask in the comments. :)
//serverstatuspage
final serverstatuspage = Material(
elevation: 5,
borderRadius: BorderRadius.circular(30),
color: Colors.green,
child: MaterialButton(
padding: EdgeInsets.fromLTRB(20, 15, 20, 15),
minWidth: MediaQuery.of(context).size.width,
onPressed: () {
serverstatusbutton(context);
},
child: Text(
"Admin Dashboard",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20,
color: Colors.white,
fontWeight: FontWeight.bold),
)));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以根据您的权限在用户文档中添加新字段,然后在显示小部件之前或在按钮的 onPressed 时检查它们。
例如,在用户文档中添加一个新的布尔字段“isAdmin”,并为其指定 true 或 false。
现在,您获取此值并仅在 isAdmin 为 true 时使按钮起作用,如下所示:
首先获取字段值
现在在 onPressed() 中使用此方法
您可以检查此之前在此处讨论过的主题。如果您想了解有关此主题的更多说明,请参阅使用云的指南函数对于了解整个想法很有用,如果您想深入了解它,基于角色的登录架构可以帮助您实现这一点。
You can add new fields in your user documents according to your permissions and then check them before displaying the widget, or at onPressed of your button.
For example, add a new boolean field 'isAdmin' in the user documents and assign either true or false to it.
Now you get this value and make the button functional only if isAdmin is true, like this:
First get the field value
Now use this method at onPressed()
You can check this previously discussed topic here. If you want some more explanation on this topic, a guide using Cloud Functions can be useful to get the whole idea, and in case you want to go deep into it, the roled-based login architecture can help you with that.