Skip to content

Commit aace465

Browse files
committed
attempt to fix incorrect page number in table of contents when footer pushes section to the next page
1 parent 9f54667 commit aace465

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

pdf/lib/src/widgets/content.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,14 @@ class Header extends StatelessWidget {
121121
return container;
122122
}
123123

124-
return Outline(
124+
return DelayedWidget(build: (_) => Outline(
125125
name: text.hashCode.toString(),
126126
title: title!,
127127
child: container,
128128
level: level,
129129
color: outlineColor,
130130
style: outlineStyle,
131-
);
131+
));
132132
}
133133
}
134134

pdf/test/widget_toc_test.dart

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import 'dart:io';
1818
import 'dart:math';
1919

20+
import 'package:pdf/pdf.dart';
2021
import 'package:pdf/widgets.dart';
2122
import 'package:test/test.dart';
2223

@@ -79,6 +80,35 @@ void main() {
7980
);
8081
});
8182

83+
test('page number with footer', () {
84+
pdf.addPage(
85+
Page(
86+
build: (final context) {
87+
return Column(
88+
children: [TableOfContent()],
89+
);
90+
},
91+
),
92+
);
93+
pdf.addPage(
94+
MultiPage(
95+
footer: (final Context context) {
96+
return Container(
97+
margin: const EdgeInsets.only(top: 1.0 * PdfPageFormat.cm),
98+
child: Text(
99+
'Page ${context.pageNumber} of ${context.pagesCount}',
100+
),
101+
);
102+
},
103+
build: (final context) => [
104+
Header(text: 'a', level: 1),
105+
Text(LoremText().paragraph(600)),
106+
Header(text: 'b', level: 1),
107+
],
108+
),
109+
);
110+
});
111+
82112
tearDownAll(() async {
83113
final file = File('widgets-toc.pdf');
84114
await file.writeAsBytes(await pdf.save());

0 commit comments

Comments
 (0)