Show new line in Firebase Firestore

164

The Firebase console hides newlines from field values when it displays them.

The data itself is not modified though, so you'll typically want to check the display of newlines in your own application rather than in the Firebase console.

Share:
164
SK7
Author by

SK7

Updated on December 21, 2022

Comments

  • SK7
    SK7 over 1 year

    I can't figure out how to get this poem to appear on new lines in Firestore. How would I do this?

            "Broken bottles and charred pieces of glass,\n"
            "Wadded up newspapers tossed on the grass,\n"
            "Pouring of concrete and tearing out trees.\n"
            "This is the environment that surrounds me?\n\n"
            "Poisons and insecticides sprayed on our food,\n"
            "Oceans filling with thick oil crude.\n"
            "All sea life destined to a slow, awful doom.\n"
            "These are the things we are to consume?\n\n"
            "Mills pumping out iron, expelling yellow fumes,\n"
            "Airlines emitting caustic gases from fuels,\n"
            "Weapons of destruction tested at desolate sites.\n"
            "And this is the air that's to sustain life?\n\n"
            "There has to be something that someone can do,\n"
            "Like raise the awareness to those around you\n"
            "That if we don't heed the problem at hand\n"
            "It's your life that's at stake, the destruction of man.\n\n";
    
    return StreamBuilder(
                  stream: Firestore.instance
                  .collection('poems')
                  .snapshots(),
    
    Padding(
                  padding: const EdgeInsets.all(16),
                  child: Text(
                    document['body'] == null ? '' : document['body'],
    
    • Frank van Puffelen
      Frank van Puffelen about 4 years
      Are you asking about how to get the Firebase console to display newlines? Because you can't. The Firebase console strips newlines from its display (the data is not modified).
    • SK7
      SK7 about 4 years
      @FrankvanPuffelen Thanks Frank. I thought that may be the case. Is there a way around it?
    • Frank van Puffelen
      Frank van Puffelen about 4 years
      The solution is to display the data in your application code, and ensure the newline symbols are handled the way you want them to be handled there.