dart_pdf
dart_pdf copied to clipboard
RangeError(index): Index out of range: no indices are valid:0
I try to add new page as the 1st page in the document (lets say some front page or summary page or table of contents etc) but i will be able to know the summary data for this first page only after the other pages are completed.
for ex:
final pdf = Document();
pdf.addPage(
Multipage(
build: (context) {
//* here, lets assume i generate 5 pages using some data list and then i also create each page summary etc when i process these 5
//* pages and assume this summary data is store in summaryDataList variable.
}
),
);
//* so these 5 pages are generated successfully. Now, i am trying to add a new page which must be the first page (can continue to
//* second page page based on the data length). So i tired adding another page
pdf.addPage(
index:1,
//* if i remove this index parameter, then its not showing the error but my page is added as a last page but i want to add as first page.
MultiPage(
build: (context){
//* here i am tying to render the summaryDataList and in the same time i am trying to make this as a first page. So, inorder to do
//*this, i tried adding index:1. if i use this index parameter, i get the "RangeError(index): Index out of range: no indices are valid:0"
//*error. am i missing something here? can we add a new page into the existing document instance with the spacfic page number?
//*I also tried to do the same after pdf.Save() but it throws error saying document already saved
}
)
);
pdf.save()
Even i tried removing the summaryDataList variable usage in this new page and tried with some static data but still same error. so i assume the issue not because of the data being determined and its because of the page is being added as a new page to specific index it seems.
Can you please let me know how to add a new page to the specific page number?
Appreciate your response.