【发布时间】:2019-06-27 02:36:14
【问题描述】:
我正在为我的应用制作一个笔记保存页面,该页面能够编辑笔记标题和笔记本身。
在使用 Flutter 和 Firestore 时,我遇到了这个问题:
我找不到任何方法来创建像 TextField 这样支持多行文本的东西,而且我不知道如何将这些数据存储在 Firestore 中。
编辑备注页面代码,目前只能从 Firestore 读取:
class EditNotePage extends StatefulWidget {
final DocumentSnapshot document;
EditNotePage({
Key key,
this.document
}) : super(key: key);
@override
_EditNotePageState createState() => _EditNotePageState(document);
}
class _EditNotePageState extends State<EditNotePage> {
final DocumentSnapshot document;
_EditNotePageState(this.document);
@override
Widget build(BuildContext context) {
var textFieldTitleController = new TextEditingController(
text: document['title']
);
var textFieldNoteController = new TextEditingController(
text: document['note']
);
return Scaffold(
appBar: AppBar(
title: Text('Edit note'),
),
body: Column(
children: <Widget>[
TextField(
controller: textFieldTitleController,
decoration: InputDecoration(
labelText: 'Title'
),
),
TextField(
controller: textFieldNoteController,
decoration: InputDecoration(
labelText: 'Note'
),
),
],
),
);
}
}
Firestore 结构:
users > "userUID" > notes > "note" > title (as string) 和 note (as 字符串)
这在制作文本编辑应用程序或保存用户编写的长文本时尤其重要。
有解决这个问题的想法吗?
【问题讨论】:
标签: database firebase flutter google-cloud-firestore flutter-dependencies