I am working on an app in Flutter that presents stories and articles to users.
Currently, I am building the stories in a RichText widget to add special stylings and interactivity to various substrings of the text, and the data that is being input to building the list of TextSpan or WidgetSpan that I am filling the RichText with comes from a List of a custom class which holds the actual substring along with information for styling it.
For simplicity let's say each child of this List is:
CustomSpanClass(string: "substring that may include ,!'\" punctuation", weight: FontWeight.bold, ...etc)
Currently the entire RichText is being held in a container that is scrollable so the user can scroll through the story on the same page. I want to give users the option to have a swiping reading experience though, and here lies my biggest obstacle: the data being fed in is just one large list of substrings, so I have no idea at which point the text would overflow the screen.
Does anyone know how to capture which TextSpan/WidgetSpan would first overflow the constraints of its container which is bound by the screen's width and height? I have done a lot of reading and think maybe I need to utilize/access the RenderObject but I'm really at a loss here.
This is going to be a bit of an over-simplification but, in other words, if I have a RichText:
Text.rich(
children: [
CustomSpan(string: "Flutter is pretty awesome,"),
CustomSpan(string: "and I love that it uses"),
CustomSpan(string: "widgets", weight: FontWeight.bold, color: Colors.blue),
CustomSpan(string: "and has hot reload capability."),
CustomSpan(string: "This span won't fit on the same screen for an iPhone 8 plus",),
CustomSpan(string: "And this span won't fully fit on the same screen for an iPhone 11 Pro."),
],
)
Does anyone have any idea how I could get the index of the first child of the Text.rich() spans that overflows a page, and proceed to build a second screen from there?