Firebase 设置状态以允许更改立即出现在界面上以进行颤振
我正在努力更新我在firebase中的用户名,我希望更改立即显示在界面上。如何设置此项的状态?这是迄今为止我为“更新”按钮编写的代码。谢谢Firebase 设置状态以允许更改立即出现在界面上以进行颤振,firebase,flutter,settings,setstate,Firebase,Flutter,Settings,Setstate,我正在努力更新我在firebase中的用户名,我希望更改立即显示在界面上。如何设置此项的状态?这是迄今为止我为“更新”按钮编写的代码。谢谢 RaisedButton( onPressed: () async { //change username FirebaseUser user = await Provider.of(context).auth.getCurrentUser(); UserU
RaisedButton(
onPressed: () async { //change username
FirebaseUser user = await Provider.of(context).auth.getCurrentUser();
UserUpdateInfo updateInfo = UserUpdateInfo();
updateInfo.displayName = _newUsernameController.text;
user.updateProfile(updateInfo);
print('USERNAME IS: ${user.displayName}');
setState(() {
//user.displayName = _newUsernameController;
});
Navigator.pop(context);
},
color: Colors.indigo,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50)),
child: Padding(
padding: EdgeInsets.only(top: 10, bottom: 10, left: 20, right: 20),
child: Text("Save", style: TextStyle(color: Colors.white,
fontWeight: FontWeight.bold, fontSize: 15),
),
),
)
您可以将
user.displayName
分配给setState
中的变量,并显示该变量
String用户名='Old Name';
...
子:列(
儿童:[
Text(用户名),//此处!
升起的按钮(
onPressed:()异步{//更改用户名
FirebaseUser user=wait Provider.of(context.auth.getCurrentUser();
UserUpdateInfo updateInfo=UserUpdateInfo();
updateInfo.displayName=\u newUsernameController.text;
user.updateProfile(updateInfo);
打印('用户名为:${user.displayName}');
设置状态(){
用户名=user.displayName;
});
//Navigator.pop(上下文);为什么???
},
颜色:颜色,靛蓝,
形状:圆形矩形边框(
边界半径:边界半径。圆形(50)),
孩子:填充(
填充:仅限边集(顶部:10,底部:10,左侧:20,右侧:20),
子项:文本(“保存”),样式:文本样式(颜色:Colors.white,
fontWeight:fontWeight.bold,fontSize:15),
),
),
),
],
),
< /代码> 如果您需要从多个小部件/视图访问数据,则应考虑搜索状态管理解决方案。
从Flatter文档中可以看到,这对于理解状态管理的基本原理非常有用
另外,user.updateProfile(updateInfo)
是一个。您可能需要等待它,然后再采取进一步的操作,如导航返回