Home > Software engineering >  Flutter divide a long text with images
Flutter divide a long text with images

Time:07-13

i am creating a news App which i the content of the news is more than 2000 words, my problem is, i want to divide the content and put images in between them. something like this

Note:

Both the images and text are coming from firebase...

i want to able to do irrespective the length of the words

here

CodePudding user response:

You can use RichText widget for this types of complex UI.

RichText( 
   text: TextSpan( 
      children: [ 
        TextSpan( text: "Some Text...", ), 
        WidgetSpan( child: 
          Image.network(src), 
        ), 
        TextSpan( text: "Some Text...", ), 
      ], 
   ), 
),

CodePudding user response:

To cut a big sentence you can use the split method and create a list and save it as 2 different strings like

List<String> stringList = verylongSentence.split(" ");

  int start = 0;
  int end = 20;//get first 20 words

  /// sublist of stringList
  final joinedWords = stringList.sublist(start, end);
  /// join the list with space
  String _content1 = joinedWords.join(" ");
  String _content2 = stringList.sublist(end).join(" ");
  • Related