fix: reset max page count for new documents in DocumentStateNotifier
This commit is contained in:
parent
1394341935
commit
5fe31a6947
|
|
@ -313,11 +313,16 @@ void main() {
|
||||||
expect(pagesSidebar, findsOneWidget);
|
expect(pagesSidebar, findsOneWidget);
|
||||||
|
|
||||||
// Scroll to make page 3 thumbnail visible
|
// Scroll to make page 3 thumbnail visible
|
||||||
final page3Thumb = find.text('3');
|
final page3Thumb = find.descendant(
|
||||||
await tester.ensureVisible(page3Thumb);
|
of: pagesSidebar,
|
||||||
|
matching: find.text('3'),
|
||||||
|
);
|
||||||
|
// Scroll more aggressively to ensure page 3 is visible
|
||||||
|
await tester.drag(pagesSidebar, const Offset(0, -500));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
expect(page3Thumb, findsOneWidget);
|
expect(page3Thumb, findsOneWidget);
|
||||||
await tester.tap(page3Thumb);
|
await tester.tap(page3Thumb, warnIfMissed: false);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(container.read(pdfViewModelProvider).currentPage, 3);
|
expect(container.read(pdfViewModelProvider).currentPage, 3);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -81,21 +81,22 @@ void main() {
|
||||||
final loadedStart = DateTime.now();
|
final loadedStart = DateTime.now();
|
||||||
while (container.read(documentRepositoryProvider).pageCount == 0) {
|
while (container.read(documentRepositoryProvider).pageCount == 0) {
|
||||||
await tester.pump(const Duration(milliseconds: 40));
|
await tester.pump(const Duration(milliseconds: 40));
|
||||||
if (DateTime.now().difference(loadedStart) > const Duration(seconds: 8)) {
|
if (DateTime.now().difference(loadedStart) >
|
||||||
|
const Duration(seconds: 10)) {
|
||||||
fail('Document never loaded (pageCount still 0)');
|
fail('Document never loaded (pageCount still 0)');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait a bit more for controller to become ready after document loads
|
// Wait a bit more for controller to become ready after document loads
|
||||||
await tester.pump(const Duration(milliseconds: 200));
|
await tester.pump(const Duration(milliseconds: 300));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
final controller = container.read(pdfViewModelProvider).controller;
|
final controller = container.read(pdfViewModelProvider).controller;
|
||||||
// Wait until the underlying viewer controller reports ready.
|
// Wait until the underlying viewer controller reports ready.
|
||||||
final readyStart = DateTime.now();
|
final readyStart = DateTime.now();
|
||||||
while (!controller.isReady) {
|
while (controller != null && !controller.isReady) {
|
||||||
await tester.pump(const Duration(milliseconds: 40));
|
await tester.pump(const Duration(milliseconds: 50));
|
||||||
if (DateTime.now().difference(readyStart) > const Duration(seconds: 8)) {
|
if (DateTime.now().difference(readyStart) > const Duration(seconds: 15)) {
|
||||||
fail('PdfViewerController never became ready');
|
fail('PdfViewerController never became ready');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,8 +49,9 @@ class DocumentStateNotifier extends Notifier<Document> {
|
||||||
);
|
);
|
||||||
if (bytes == null) {
|
if (bytes == null) {
|
||||||
// No bytes: treat as synthetic document (tests) using provided pageCount or default 1
|
// No bytes: treat as synthetic document (tests) using provided pageCount or default 1
|
||||||
|
// Reset max page count for new document
|
||||||
final pc = pageCount ?? 1;
|
final pc = pageCount ?? 1;
|
||||||
_maxPageCount = math.max(_maxPageCount, pc).toInt();
|
_maxPageCount = pc;
|
||||||
state = state.copyWith(
|
state = state.copyWith(
|
||||||
loaded: true,
|
loaded: true,
|
||||||
pageCount: _maxPageCount,
|
pageCount: _maxPageCount,
|
||||||
|
|
@ -59,11 +60,11 @@ class DocumentStateNotifier extends Notifier<Document> {
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Bytes provided
|
// Bytes provided - reset max page count for new document
|
||||||
if ((knownPageCount || pageCount != null) && pageCount != null) {
|
if ((knownPageCount || pageCount != null) && pageCount != null) {
|
||||||
// Fast path: caller already determined count
|
// Fast path: caller already determined count
|
||||||
final pc = pageCount.clamp(1, 9999) as int;
|
final pc = pageCount.clamp(1, 9999);
|
||||||
_maxPageCount = math.max(_maxPageCount, pc).toInt();
|
_maxPageCount = pc;
|
||||||
state = state.copyWith(
|
state = state.copyWith(
|
||||||
loaded: true,
|
loaded: true,
|
||||||
pageCount: _maxPageCount,
|
pageCount: _maxPageCount,
|
||||||
|
|
@ -125,7 +126,7 @@ class DocumentStateNotifier extends Notifier<Document> {
|
||||||
debugPrint(
|
debugPrint(
|
||||||
'[DocumentRepository] setPageCount called: $count (current: ${state.pageCount})',
|
'[DocumentRepository] setPageCount called: $count (current: ${state.pageCount})',
|
||||||
);
|
);
|
||||||
final clamped = count.clamp(1, 9999) as int;
|
final clamped = count.clamp(1, 9999);
|
||||||
_maxPageCount = math.max(_maxPageCount, clamped).toInt();
|
_maxPageCount = math.max(_maxPageCount, clamped).toInt();
|
||||||
state = state.copyWith(pageCount: _maxPageCount);
|
state = state.copyWith(pageCount: _maxPageCount);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue