flutter - showBottomSheet 看不到 currentState
问题描述
我正在尝试添加 showBottomSheet 并在其中尝试调用 currentState 以更改密码,但出现错误:
E/flutter(3094):[错误:flutter/lib/ui/ui_dart_state.cc(186)]未处理的异常:NoSuchMethodError:getter'currentState'被调用为null。E/flutter(3094):接收者:null E/flutter(3094):尝试调用:currentState
class SecurityCard extends StatefulWidget {
final UserModel currentUser;
SecurityCard({this.currentUser});
@override
_SecurityCardState createState() => _SecurityCardState();
}
class _SecurityCardState extends State<SecurityCard> {
var _passwordController = TextEditingController();
var _newPasswordController = TextEditingController();
var _repeatPasswordController = TextEditingController();
var userController = locator.get<UserController>();
bool checkCurrentPasswordValid = true;
var _formKeyNewPassword;
@override
void dispose() {
_passwordController.dispose();
_newPasswordController.dispose();
_repeatPasswordController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Container(
child: Column(
children: [
ListTile(
title: Text('Сменить пароль'),
leading: Icon(Icons.https),
onTap: () {
Scaffold.of(context).showBottomSheet<void>((BuildContext context) {
return Container(
padding: EdgeInsets.symmetric(vertical: getProportionateScreenWidth(5)),
horizontal: getProportionateScreenWidth(5)),
decoration: BoxDecoration(
gradient: LinearGradient(begin: Alignment.topLeft, end: Alignment.bottomRight, colors: [Color.fromRGBO(248, 219, 221, 1.0), Colors.orange[100]]),
),
height: 350.0,
child: Form(
key: _formKeyNewPassword,
child: Column(
children: [
TextFormField(
decoration: InputDecoration(hintText: 'Пароль', errorText: checkCurrentPasswordValid ? null : 'Неверный пароль'),
controller: _passwordController,
),
TextFormField(
decoration: InputDecoration(hintText: 'Новый пароль'),
// obscureText: true,
controller: _newPasswordController,
),
TextFormField(
decoration: InputDecoration(hintText: 'Повторите новый пароль'),
// obscureText: true,
controller: _repeatPasswordController,
validator: (value) {
return _newPasswordController.text == value ? null : 'Пароли не совпадают';
},
),
ElevatedButton(
onPressed: () async {
checkCurrentPasswordValid = await userController.validateCurrentPassword(_passwordController.text);
if (_formKeyNewPassword.currentState.validate() && checkCurrentPasswordValid) {
userController.updateUserPassword(_newPasswordController.text);
setState(() {});
}
},
child: Text("Сохранить"),
)
],
),
),
);
});
},
),
],
),
);
}
}
解决方案
推荐阅读
- mariadb - 在 MariaDB 中使用 ROW_NUMBER() 函数的问题
- php - 从 PHP 执行读取用户输入的 shell 脚本
- mysql - 使用存储过程向 MYSQL 数据库添加自动日期字段
- python - 如何根据列的不同值统一下采样数据帧行?
- java - 带有itext的pdf生成中的卡纳达语字体问题
- php - GenericHeader.php 第 54 行中允许的内存大小为 805306368 字节(试图分配 20480 字节)。 Magento2.3
- java - 需要分块下载大文件
- ionic-framework - 如何在离子相机中以 1:1 的分辨率绘制 4*4 网格?
- android - 当我使用 Onclick 时,在 recyclerview 中更改所选项目的背景颜色不起作用
- .net - 如何在 sitecore 中执行 javascript 渲染