Firebase 单击后如何在按钮下显示文本?
我想显示一个文本(“请检查您的电子邮件”)下的按钮被用户点击后,并使文本字段在颤振空。我已经尝试使用后,电子邮件被发送到用户,但它没有显示任何东西,然后我添加了设置状态,但仍然不工作。请查找以下代码:Firebase 单击后如何在按钮下显示文本?,firebase,flutter,dart,widget,Firebase,Flutter,Dart,Widget,我想显示一个文本(“请检查您的电子邮件”)下的按钮被用户点击后,并使文本字段在颤振空。我已经尝试使用后,电子邮件被发送到用户,但它没有显示任何东西,然后我添加了设置状态,但仍然不工作。请查找以下代码: Theme( data: ThemeData(hintColor: Colors.red), child: Padding( padding: EdgeInsets.only(top:
Theme(
data: ThemeData(hintColor: Colors.red),
child: Padding(
padding: EdgeInsets.only(top: 50),
child: TextFormField(
validator: (val) =>
val.isEmpty ? 'Enter your email' : null,
onChanged: (val) {
setState(() => email = val);
},
cursorColor: Colors.purple,
keyboardType: TextInputType.emailAddress,
textInputAction: TextInputAction.done,
style: TextStyle(color: Colors.black),
decoration: InputDecoration(
hintText: "Enter your email",
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Colors.black38,
),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.purple),
// when the TextFormField in focused
),
hintStyle:
TextStyle(fontSize: 12.0, color: Colors.black38),
),
),
),
),
SizedBox(
height: 30,
),
InkWell(
child: Container(
width: 160,
height: 60,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Color(0xffba68c8),
Color(0xFF9c27b0),
],
),
borderRadius: BorderRadius.circular(6.0),
boxShadow: [
BoxShadow(
color: Color(0xFF6078ea).withOpacity(0.3),
offset: Offset(0.0, 8.0),
blurRadius: 8.0,
)
],
),
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: () async {
if (_formKey.currentState.validate()) {
FirebaseAuth.instance
.sendPasswordResetEmail(email: email)
.then((_) {
setState(() {
Center(child: Text('Check your email'));
});
});
}
},
child: Center(
child: Text(
'SEND EMAIL',
style: TextStyle(
color: Colors.white,
fontFamily: 'Anton',
fontSize: 18.0,
letterSpacing: 1.0,
),
),
),
),
),
),
)
在setState()中使用小部件对您没有帮助,因为如果您观察代码,就会发现您只是在setState()中初始化小部件 要向用户显示消息,可以使用setState()中的SnackBar snackbar示例:
Scaffold.of(context).showSnackBar(SnackBar(
content: Text("Your message text"),
));
注意:为snackbar提供一个单独的方法并从setState()调用它总是好的