【问题标题】:Saving multiple lines of text in Firestore with Flutter使用 Flutter 在 Firestore 中保存多行文本
【发布时间】: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


    【解决方案1】:

    终于找到了解决方案,Flutter 的文本字段有一个 maxLines 参数,输入 null 或你想要的行数,它将无缝存储在 Firebase 中,没有任何格式问题。

    【讨论】:

      猜你喜欢
      • 2019-10-27
      • 1970-01-01
      • 1970-01-01
      • 2021-09-14
      • 2019-07-21
      • 1970-01-01
      • 2018-06-14
      • 2020-02-10
      • 2019-03-31
      相关资源
      最近更新 更多