【发布时间】:2021-03-29 13:34:18
【问题描述】:
我有这个简单的代码,其中包含一个 TextField 和一个 Edit 按钮。 TextField 最初有提示文本。当用户单击“编辑”按钮时,我想启用文本字段并打开键盘以编辑该值。
Row(
children: [
Container(
width: MediaQuery.of(context).size.width - 100,
margin: const EdgeInsets.symmetric(horizontal: 16),
child: TextFormField(
focusNode: myFocusNode,
key: Key("editusernamekey"),
decoration: InputDecoration(
hintText: "Username",
hintStyle: TextStyle(color: Colors.white),
),
enabled: editprovider.isEnabled,
),
),
IconButton(
icon: Icon(Icons.edit, color: Colors.white),
onPressed: () {
print("onpressed get called this time");
myFocusNode.requestFocus();
editprovider.isEnabled = true;
},
),
],
“editProvider”是在另一个类中声明的变量,其代码如下:
class UpdateDataProvider with ChangeNotifier {
bool _isEnabled = false;
bool get isEnabled => _isEnabled;
set isEnabled(bool value) {
this._isEnabled = value;
notifyListeners();
}
}
问题是它正在工作,但我需要在按钮上点击两次才能将注意力集中在文本字段上。 这是我的用户界面:
我还想知道如何在没有文档 ID 的情况下在数据库上运行更新查询。 假设我必须做一个查询,比如 update usersTable set name = "Abc" where rollno = 12;这是 sql 表单查询。 如何在颤振中做到这一点。 谢谢你的帮助..
【问题讨论】:
标签: flutter dart google-cloud-firestore