Luca_54
Luca_54

Reputation: 539

Create a text file with Textfield data and upload to firebase storage in Flutter

I have a Textfield in my Flutter app and I want to put the data of the field in a file and upload it into my Firebase storage on submit. I want to do this because the content is like a post on Twitter where you can write up to 400 characters in text and it would be better if it is in a seperated file.

Is that possible? I couldn't find any tutorial for this. Is there a better option than that?

Upvotes: 0

Views: 1699

Answers (1)

jpheine
jpheine

Reputation: 226

Yes it is possible, if I understand your question correct. It is possible to store each post as an own document. For example you can create a button and then you can upload your "post" to your firestore database. In your case it could look like this:

floatingActionButton: FloatingActionButton(
    child: Icon(Icons.send),
    onPressed: () {
      FirebaseFirestore.instance.collection("posts").add(
        {
          "user": "user_xy",
          "text": "post_text"
        },
      );
    },
  )

You have to change the collection name to the name of your collection and the attributes to the attributes you require. The attribute text would store the message of your post. If you do it as shown above, each post get's stored as an own document.

Upvotes: 1

Related Questions