我使用showModalBottomSheet来获取OTP代码,如果用户输入错误代码,我希望显示snackBar。因此,我使用了此方法,
showModalBottomSheet(
isScrollControlled: true,
isDismissible: false,
context: context,
builder: (context) {
return SafeArea(
child: Stack(
alignment: Alignment.topCenter,
clipBehavior: Clip.none,
children: [
Column(
children: [
Container(
padding: const EdgeInsets.symmetric(
horizontal: 30, vertical: 0),
child: Column(children: [
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 50),
child: TextField(
controller: codeController,
keyboardType: TextInputType.number,
),
),
const SizedBox(
height: 5,
),
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 50),
child: CustomButton(
onTap: () async {
if (codeController.text.length == 6) {
try {
PhoneAuthCredential credential =
PhoneAuthProvider.credential(
verificationId: verificationId,
smsCode:
codeController.text.trim());
await _auth
.signInWithCredential(credential);
Navigator.of(context)
.pushNamedAndRemoveUntil(
'/home',
(Route<dynamic> route) =>
false);
} catch (e) {
// ----------------------------------------------
//this snackbar
showSnackBar(
context,
"Invalid verification code",
"Please enter correct verification code");
}
}
},
text: "Continue",
height: 50),
)
]),
)
],
)
],
),
);
});
snackBar显示在showModalBottomSheet下面,所以我想显示snackBar上面的showModalBottomSheet而不隐藏showModalBottomSheet.
1条答案
按热度按时间6qftjkof1#
您可以使用另一个
Scaffold
从showModalBottomSheet
获取新的ScaffoldMessenger
,而不是从顶层获取。