【发布时间】:2020-10-20 13:25:59
【问题描述】:
如何在 Firebase 中检索电话身份验证期间使用的电话号码并使用颤振显示它,我尝试了以下方法,但它不适用于我:
FirebaseAuth.instance.currentUser().then((user) {
_userId = user.uid;
_phone = user.phoneNumber;
});
这是我的完整代码
class HomePageState extends State<HomeScreen>{
String _userId,_phone;
@override
Widget build(BuildContext context) {
FirebaseAuth.instance.currentUser().then((user) {
_userId = user.uid;
_phone = user.phoneNumber;
});
var myGridView = new GridView.builder(
itemCount: services.length,
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
// childAspectRatio: (itemWidth / itemHeight),
),
itemBuilder: (BuildContext context, int index) {
return FlatButton(
child: Padding(
padding: const EdgeInsets.all(0.0),
// child:new Card(
//elevation: 5.0,
child: new Container(
alignment: Alignment.centerLeft,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
new Text(_userId),
],
),
),
),
),
onPressed: () {
String catgry = services[index];
if (catgry == "coming soon") {
showDialog(
barrierDismissible: false,
context: context,
child: new CupertinoAlertDialog(
title: new Column(
children: <Widget>[
new Text("This feature is coming soon"),
new Icon(
Icons.favorite,
color: Colors.red,
),
],
),
// content: new Text( services[index]),
actions: <Widget>[
new FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: new Text("OK"))
],
));
} else {
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => Details(catgry,phone1)));
}
},
);
},
);
return new Scaffold(
appBar: new AppBar(
backgroundColor: Colors.black,
title: Text("Appbar", style: TextStyle(color: Colors.white),),
),),
body: myGridView,
bottomNavigationBar: CustomBottomBar(),
);
}
}
【问题讨论】:
-
“它不工作”是什么意思。更多细节会有所帮助
-
当我使用它时,它给了我这个错误“引发了另一个异常:必须向文本小部件提供非空字符串。”
-
发布完整代码,包括您的
Text小部件的代码 -
哦,我发了,请检查
标签: firebase flutter firebase-authentication flutter-layout flutter-dependencies