使用Flutter在Firestore中保存多行文本

问题描述 投票:0回答:1

我正在为我的应用制作一个便笺保持页面,该页面能够编辑音符标题和音符本身。

使用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 string)

在制作文本编辑应用程序或保存用户编写的长文本时,这一点尤为重要。

解决这个问题的任何想法?

database firebase flutter google-cloud-firestore flutter-dependencies
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.