skip to Main Content

I am displaying data in my application from Firebase Firestore, but when displaying texts, they do not keep the same formatting. For example, if there is a blank line between the text, it is deleted while displaying it in the application. I only want to keep the empty lines while displaying them in the application.

i use flutter.

I manually enter the data into Firestore and then display it in the application as follows:

model file:

class Post {
  final String title;
  final String image;
  final String des;

  const Post({
    required this.title,
    required this.image,
    required this.des,
  });

  Post.fromJson(Map<String, Object?> json)
      : this(
          title: json['title']! as String,
          image: json['image']! as String,
          des: json['des']! as String,
        );
  Map<String, Object?> toJson() => {
        'title': title,
        'image': image,
        'des': des,
      };
}


The second file: ( I display it here through ListView.Builder ):

 final queryPost =
      FirebaseFirestore.instance.collection('thedata').withConverter<Post>(
            fromFirestore: (snapshot, _) => Post.fromJson(snapshot.data()!),
            toFirestore: (user, _) => user.toJson(),
          );

2

Answers


  1. Your test should contain n for empty lines when you set your data:

    Example Example Example Example Example Example n Example2 Example2

    now where you get and parse it inside your flutter app, it will be same as I did wrote, but when when you try print() with it, it will be two lines.

    Example Example Example Example Example Example

    Example2 Example2

    Login or Signup to reply.
  2. Then you can go for Mongo DB Cloud Database which can store formatted text and returns formatted text as well

    Mongo Db Data Api could work almost similar to Cloud Firestore by simply converting an existing database/collection as an api end point

    https://www.mongodb.com/docs/atlas/api/data-api/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search