refactor: unify document opening methods in repository
This commit is contained in:
parent
f7d37517a4
commit
9250d2ecc5
|
|
@ -37,9 +37,12 @@ void main() {
|
|||
(ref) => PreferencesStateNotifier(prefs),
|
||||
),
|
||||
documentRepositoryProvider.overrideWith(
|
||||
(ref) =>
|
||||
DocumentStateNotifier(service: ExportService())
|
||||
..openPickedWithPageCount(pageCount: 3, bytes: pdfBytes),
|
||||
(ref) => DocumentStateNotifier(service: ExportService())
|
||||
..openDocument(
|
||||
bytes: pdfBytes,
|
||||
pageCount: 3,
|
||||
knownPageCount: true,
|
||||
),
|
||||
),
|
||||
pdfViewModelProvider.overrideWith(
|
||||
(ref) => PdfViewModel(ref, useMockViewer: false),
|
||||
|
|
@ -93,9 +96,12 @@ void main() {
|
|||
(ref) => PreferencesStateNotifier(prefs),
|
||||
),
|
||||
documentRepositoryProvider.overrideWith(
|
||||
(ref) =>
|
||||
DocumentStateNotifier(service: ExportService())
|
||||
..openPickedWithPageCount(pageCount: 3, bytes: pdfBytes),
|
||||
(ref) => DocumentStateNotifier(service: ExportService())
|
||||
..openDocument(
|
||||
bytes: pdfBytes,
|
||||
pageCount: 3,
|
||||
knownPageCount: true,
|
||||
),
|
||||
),
|
||||
pdfViewModelProvider.overrideWith(
|
||||
(ref) => PdfViewModel(ref, useMockViewer: false),
|
||||
|
|
@ -164,7 +170,11 @@ void main() {
|
|||
documentRepositoryProvider.overrideWith(
|
||||
(ref) => DocumentStateNotifier(
|
||||
service: ExportService(enableRaster: false),
|
||||
)..openPickedWithPageCount(pageCount: 3, bytes: pdfBytes),
|
||||
)..openDocument(
|
||||
bytes: pdfBytes,
|
||||
pageCount: 3,
|
||||
knownPageCount: true,
|
||||
),
|
||||
),
|
||||
pdfViewModelProvider.overrideWith(
|
||||
(ref) => PdfViewModel(ref, useMockViewer: false),
|
||||
|
|
@ -210,7 +220,11 @@ void main() {
|
|||
documentRepositoryProvider.overrideWith(
|
||||
(ref) => DocumentStateNotifier(
|
||||
service: ExportService(enableRaster: false),
|
||||
)..openPickedWithPageCount(pageCount: 3, bytes: pdfBytes),
|
||||
)..openDocument(
|
||||
bytes: pdfBytes,
|
||||
pageCount: 3,
|
||||
knownPageCount: true,
|
||||
),
|
||||
),
|
||||
pdfViewModelProvider.overrideWith(
|
||||
(ref) => PdfViewModel(ref, useMockViewer: false),
|
||||
|
|
@ -259,7 +273,11 @@ void main() {
|
|||
documentRepositoryProvider.overrideWith(
|
||||
(ref) => DocumentStateNotifier(
|
||||
service: ExportService(enableRaster: false),
|
||||
)..openPickedWithPageCount(pageCount: 3, bytes: pdfBytes),
|
||||
)..openDocument(
|
||||
bytes: pdfBytes,
|
||||
pageCount: 3,
|
||||
knownPageCount: true,
|
||||
),
|
||||
),
|
||||
pdfViewModelProvider.overrideWith(
|
||||
(ref) => PdfViewModel(ref, useMockViewer: false),
|
||||
|
|
@ -309,9 +327,12 @@ void main() {
|
|||
(ref) => PreferencesStateNotifier(prefs),
|
||||
),
|
||||
documentRepositoryProvider.overrideWith(
|
||||
(ref) =>
|
||||
DocumentStateNotifier(service: ExportService())
|
||||
..openPickedWithPageCount(pageCount: 3, bytes: pdfBytes),
|
||||
(ref) => DocumentStateNotifier(service: ExportService())
|
||||
..openDocument(
|
||||
bytes: pdfBytes,
|
||||
pageCount: 3,
|
||||
knownPageCount: true,
|
||||
),
|
||||
),
|
||||
pdfViewModelProvider.overrideWith(
|
||||
(ref) => PdfViewModel(ref, useMockViewer: false),
|
||||
|
|
@ -361,9 +382,12 @@ void main() {
|
|||
(ref) => PreferencesStateNotifier(prefs),
|
||||
),
|
||||
documentRepositoryProvider.overrideWith(
|
||||
(ref) =>
|
||||
DocumentStateNotifier(service: ExportService())
|
||||
..openPickedWithPageCount(pageCount: 3, bytes: pdfBytes),
|
||||
(ref) => DocumentStateNotifier(service: ExportService())
|
||||
..openDocument(
|
||||
bytes: pdfBytes,
|
||||
pageCount: 3,
|
||||
knownPageCount: true,
|
||||
),
|
||||
),
|
||||
pdfViewModelProvider.overrideWith(
|
||||
(ref) => PdfViewModel(ref, useMockViewer: false),
|
||||
|
|
|
|||
|
|
@ -33,8 +33,11 @@ void main() {
|
|||
),
|
||||
documentRepositoryProvider.overrideWith(
|
||||
(ref) =>
|
||||
DocumentStateNotifier()
|
||||
..openPickedWithPageCount(pageCount: 3, bytes: pdfBytes),
|
||||
DocumentStateNotifier()..openDocument(
|
||||
bytes: pdfBytes,
|
||||
pageCount: 3,
|
||||
knownPageCount: true,
|
||||
),
|
||||
),
|
||||
pdfViewModelProvider.overrideWith(
|
||||
(ref) => PdfViewModel(ref, useMockViewer: false),
|
||||
|
|
@ -104,8 +107,11 @@ void main() {
|
|||
),
|
||||
documentRepositoryProvider.overrideWith(
|
||||
(ref) =>
|
||||
DocumentStateNotifier()
|
||||
..openPickedWithPageCount(pageCount: 3, bytes: pdfBytes),
|
||||
DocumentStateNotifier()..openDocument(
|
||||
bytes: pdfBytes,
|
||||
pageCount: 3,
|
||||
knownPageCount: true,
|
||||
),
|
||||
),
|
||||
pdfViewModelProvider.overrideWith(
|
||||
(ref) => PdfViewModel(ref, useMockViewer: false),
|
||||
|
|
@ -158,8 +164,11 @@ void main() {
|
|||
),
|
||||
documentRepositoryProvider.overrideWith(
|
||||
(ref) =>
|
||||
DocumentStateNotifier()
|
||||
..openPickedWithPageCount(pageCount: 3, bytes: pdfBytes),
|
||||
DocumentStateNotifier()..openDocument(
|
||||
bytes: pdfBytes,
|
||||
pageCount: 3,
|
||||
knownPageCount: true,
|
||||
),
|
||||
),
|
||||
pdfViewModelProvider.overrideWith(
|
||||
(ref) => PdfViewModel(ref, useMockViewer: false),
|
||||
|
|
@ -245,8 +254,11 @@ void main() {
|
|||
),
|
||||
documentRepositoryProvider.overrideWith(
|
||||
(ref) =>
|
||||
DocumentStateNotifier()
|
||||
..openPickedWithPageCount(pageCount: 3, bytes: pdfBytes),
|
||||
DocumentStateNotifier()..openDocument(
|
||||
bytes: pdfBytes,
|
||||
pageCount: 3,
|
||||
knownPageCount: true,
|
||||
),
|
||||
),
|
||||
pdfViewModelProvider.overrideWith(
|
||||
(ref) => PdfViewModel(ref, useMockViewer: false),
|
||||
|
|
@ -311,8 +323,11 @@ void main() {
|
|||
),
|
||||
documentRepositoryProvider.overrideWith(
|
||||
(ref) =>
|
||||
DocumentStateNotifier()
|
||||
..openPickedWithPageCount(pageCount: 3, bytes: pdfBytes),
|
||||
DocumentStateNotifier()..openDocument(
|
||||
bytes: pdfBytes,
|
||||
pageCount: 3,
|
||||
knownPageCount: true,
|
||||
),
|
||||
),
|
||||
pdfViewModelProvider.overrideWith(
|
||||
(ref) => PdfViewModel(ref, useMockViewer: false),
|
||||
|
|
@ -377,7 +392,7 @@ void main() {
|
|||
Future<void> simulatePick() async {
|
||||
container
|
||||
.read(documentRepositoryProvider.notifier)
|
||||
.openPicked(bytes: newBytes);
|
||||
.openDocument(bytes: newBytes);
|
||||
// Reset the current page explicitly to 1 as openPicked establishes new doc
|
||||
container.read(pdfViewModelProvider.notifier).jumpToPage(1);
|
||||
}
|
||||
|
|
@ -391,8 +406,11 @@ void main() {
|
|||
),
|
||||
documentRepositoryProvider.overrideWith(
|
||||
(ref) =>
|
||||
DocumentStateNotifier()
|
||||
..openPickedWithPageCount(pageCount: 3, bytes: initialBytes),
|
||||
DocumentStateNotifier()..openDocument(
|
||||
bytes: initialBytes,
|
||||
pageCount: 3,
|
||||
knownPageCount: true,
|
||||
),
|
||||
),
|
||||
pdfViewModelProvider.overrideWith(
|
||||
(ref) => PdfViewModel(ref, useMockViewer: false),
|
||||
|
|
|
|||
|
|
@ -25,25 +25,56 @@ class DocumentStateNotifier extends StateNotifier<Document> {
|
|||
);
|
||||
}
|
||||
|
||||
void openPicked({Uint8List? bytes}) {
|
||||
/// Unified open API replacing multiple legacy variants.
|
||||
///
|
||||
/// Usage patterns:
|
||||
/// openDocument(bytes: data) -> derive page count asynchronously.
|
||||
/// openDocument(bytes: data, pageCount: 203, knownPageCount: true) -> fast path.
|
||||
/// openDocument(pageCount: 5) -> open empty placeholder document (tests).
|
||||
void openDocument({
|
||||
Uint8List? bytes,
|
||||
int? pageCount,
|
||||
bool knownPageCount = false,
|
||||
}) {
|
||||
debugPrint(
|
||||
'[DocumentRepository] openPicked called (bytes length: ${bytes?.length})',
|
||||
'[DocumentRepository] openDocument called (bytes=${bytes?.length} pageCount=$pageCount known=$knownPageCount)',
|
||||
);
|
||||
|
||||
// For real usage, determine page count from PDF bytes asynchronously
|
||||
if (bytes != null) {
|
||||
_openPickedAsync(bytes);
|
||||
} else {
|
||||
// Handle null bytes case
|
||||
if (bytes == null) {
|
||||
// No bytes: treat as synthetic document (tests) using provided pageCount or default 1
|
||||
final pc = pageCount ?? 1;
|
||||
state = state.copyWith(
|
||||
loaded: true,
|
||||
pageCount: 1,
|
||||
pageCount: pc,
|
||||
pickedPdfBytes: null,
|
||||
placementsByPage: <int, List<SignaturePlacement>>{},
|
||||
);
|
||||
return;
|
||||
}
|
||||
// Bytes provided
|
||||
if ((knownPageCount || pageCount != null) && pageCount != null) {
|
||||
// Fast path: caller already determined count
|
||||
state = state.copyWith(
|
||||
loaded: true,
|
||||
pageCount: pageCount.clamp(1, 9999),
|
||||
pickedPdfBytes: bytes,
|
||||
placementsByPage: <int, List<SignaturePlacement>>{},
|
||||
);
|
||||
return;
|
||||
}
|
||||
// Derive asynchronously
|
||||
_openPickedAsync(bytes);
|
||||
}
|
||||
|
||||
// --- Deprecated wrappers for backward compatibility (can be removed later) ---
|
||||
@Deprecated('Use openDocument(bytes: ...) instead')
|
||||
void openPicked({Uint8List? bytes}) => openDocument(bytes: bytes);
|
||||
|
||||
@Deprecated(
|
||||
'Use openDocument(bytes: ..., pageCount: x, knownPageCount: true) instead',
|
||||
)
|
||||
void openPickedKnown({required int pageCount, required Uint8List bytes}) =>
|
||||
openDocument(bytes: bytes, pageCount: pageCount, knownPageCount: true);
|
||||
|
||||
Future<void> _openPickedAsync(Uint8List bytes) async {
|
||||
int pageCount = 1; // default fallback
|
||||
|
||||
|
|
@ -63,30 +94,15 @@ class DocumentStateNotifier extends StateNotifier<Document> {
|
|||
pickedPdfBytes: bytes,
|
||||
placementsByPage: <int, List<SignaturePlacement>>{},
|
||||
);
|
||||
|
||||
// Schedule delayed check to ensure our page count wasn't overridden by UI callbacks
|
||||
Future.delayed(const Duration(milliseconds: 100), () {
|
||||
if (state.loaded &&
|
||||
state.pickedPdfBytes == bytes &&
|
||||
state.pageCount != pageCount) {
|
||||
state = state.copyWith(pageCount: pageCount);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// For tests that need to specify page count explicitly
|
||||
@visibleForTesting
|
||||
void openPickedWithPageCount({required int pageCount, Uint8List? bytes}) {
|
||||
debugPrint(
|
||||
'[DocumentRepository] openPickedWithPageCount called (pageCount=$pageCount)',
|
||||
);
|
||||
state = state.copyWith(
|
||||
loaded: true,
|
||||
pageCount: pageCount,
|
||||
pickedPdfBytes: bytes,
|
||||
placementsByPage: <int, List<SignaturePlacement>>{},
|
||||
);
|
||||
}
|
||||
@Deprecated(
|
||||
'Use openDocument(pageCount: x) for synthetic docs or with bytes+knownPageCount',
|
||||
)
|
||||
void openPickedWithPageCount({required int pageCount, Uint8List? bytes}) =>
|
||||
openDocument(bytes: bytes, pageCount: pageCount, knownPageCount: true);
|
||||
|
||||
void close() {
|
||||
state = Document.initial();
|
||||
|
|
@ -133,21 +149,12 @@ class DocumentStateNotifier extends StateNotifier<Document> {
|
|||
// signature bytes were provided.
|
||||
static final img.Image _singleTransparentPng = img.Image(width: 1, height: 1);
|
||||
|
||||
@Deprecated('Use modifyPlacement')
|
||||
void updatePlacementRotation({
|
||||
required int page,
|
||||
required int index,
|
||||
required double rotationDeg,
|
||||
}) {
|
||||
if (!state.loaded) return;
|
||||
final p = page.clamp(1, state.pageCount);
|
||||
final map = Map<int, List<SignaturePlacement>>.from(state.placementsByPage);
|
||||
final list = List<SignaturePlacement>.from(map[p] ?? const []);
|
||||
if (index >= 0 && index < list.length) {
|
||||
list[index] = list[index].copyWith(rotationDeg: rotationDeg);
|
||||
map[p] = list;
|
||||
state = state.copyWith(placementsByPage: map);
|
||||
}
|
||||
}
|
||||
}) => modifyPlacement(page: page, index: index, rotationDeg: rotationDeg);
|
||||
|
||||
void removePlacement({required int page, required int index}) {
|
||||
if (!state.loaded) return;
|
||||
|
|
@ -166,21 +173,36 @@ class DocumentStateNotifier extends StateNotifier<Document> {
|
|||
}
|
||||
|
||||
// Update the rect of an existing placement on a page.
|
||||
@Deprecated('Use modifyPlacement')
|
||||
void updatePlacementRect({
|
||||
required int page,
|
||||
required int index,
|
||||
required Rect rect,
|
||||
}) => modifyPlacement(page: page, index: index, rect: rect);
|
||||
|
||||
/// Generic partial update for a placement. Any non-null field is applied.
|
||||
void modifyPlacement({
|
||||
required int page,
|
||||
required int index,
|
||||
Rect? rect,
|
||||
double? rotationDeg,
|
||||
SignatureAsset? asset,
|
||||
GraphicAdjust? graphicAdjust,
|
||||
}) {
|
||||
if (!state.loaded) return;
|
||||
final p = page.clamp(1, state.pageCount);
|
||||
final map = Map<int, List<SignaturePlacement>>.from(state.placementsByPage);
|
||||
final list = List<SignaturePlacement>.from(map[p] ?? const []);
|
||||
if (index >= 0 && index < list.length) {
|
||||
final existing = list[index];
|
||||
list[index] = existing.copyWith(rect: rect);
|
||||
map[p] = list;
|
||||
state = state.copyWith(placementsByPage: map);
|
||||
}
|
||||
if (index < 0 || index >= list.length) return;
|
||||
final current = list[index];
|
||||
list[index] = current.copyWith(
|
||||
rect: rect ?? current.rect,
|
||||
rotationDeg: rotationDeg ?? current.rotationDeg,
|
||||
asset: asset ?? current.asset,
|
||||
graphicAdjust: graphicAdjust ?? current.graphicAdjust,
|
||||
);
|
||||
map[p] = list;
|
||||
state = state.copyWith(placementsByPage: map);
|
||||
}
|
||||
|
||||
List<SignaturePlacement> placementsOn(int page) {
|
||||
|
|
|
|||
|
|
@ -138,11 +138,7 @@ class PdfViewModel extends ChangeNotifier {
|
|||
}) {
|
||||
ref
|
||||
.read(documentRepositoryProvider.notifier)
|
||||
.updatePlacementRotation(
|
||||
page: page,
|
||||
index: index,
|
||||
rotationDeg: rotationDeg,
|
||||
);
|
||||
.modifyPlacement(page: page, index: index, rotationDeg: rotationDeg);
|
||||
}
|
||||
|
||||
void removePlacement({required int page, required int index}) {
|
||||
|
|
@ -163,7 +159,7 @@ class PdfViewModel extends ChangeNotifier {
|
|||
}) {
|
||||
ref
|
||||
.read(documentRepositoryProvider.notifier)
|
||||
.updatePlacementRect(page: page, index: index, rect: rect);
|
||||
.modifyPlacement(page: page, index: index, rect: rect);
|
||||
}
|
||||
|
||||
List<SignaturePlacement> placementsOn(int page) {
|
||||
|
|
@ -343,6 +339,16 @@ class PdfSessionViewModel extends ChangeNotifier {
|
|||
debugPrint(
|
||||
'[PdfSessionViewModel] Opened PDF bytes length=${bytes.length} pages=$pageCount',
|
||||
);
|
||||
// Use fast path to populate repository BEFORE navigation so the first
|
||||
// build of PdfViewerWidget sees a loaded document and avoids showing
|
||||
// transient "No PDF loaded".
|
||||
ref
|
||||
.read(documentRepositoryProvider.notifier)
|
||||
.openDocument(
|
||||
bytes: bytes,
|
||||
pageCount: pageCount,
|
||||
knownPageCount: true,
|
||||
);
|
||||
} catch (e, st) {
|
||||
debugPrint(
|
||||
'[PdfSessionViewModel] Failed to read PDF data from bytes error=$e',
|
||||
|
|
@ -379,8 +385,13 @@ class PdfSessionViewModel extends ChangeNotifier {
|
|||
} else {
|
||||
_displayFileName = '';
|
||||
}
|
||||
debugPrint('[PdfSessionViewModel] Calling openPicked with bytes');
|
||||
ref.read(documentRepositoryProvider.notifier).openPicked(bytes: bytes);
|
||||
// If fast path failed to set repository (e.g., exception earlier), fallback to async derive.
|
||||
if (ref.read(documentRepositoryProvider).pickedPdfBytes != bytes) {
|
||||
debugPrint(
|
||||
'[PdfSessionViewModel] Fallback deriving page count via openDocument',
|
||||
);
|
||||
ref.read(documentRepositoryProvider.notifier).openDocument(bytes: bytes);
|
||||
}
|
||||
// Keep existing signature cards when opening a new document.
|
||||
// The feature "Open a different document will reset signature placements but keep signature cards"
|
||||
// relies on this behavior. Placements are reset by openPicked() above.
|
||||
|
|
|
|||
|
|
@ -12,7 +12,9 @@ Future<void> aDocumentIsOpenAndContainsAtLeastOneSignaturePlacement(
|
|||
) async {
|
||||
final container = TestWorld.container ?? ProviderContainer();
|
||||
TestWorld.container = container;
|
||||
container.read(documentRepositoryProvider.notifier).openPickedWithPageCount(pageCount: 5);
|
||||
container
|
||||
.read(documentRepositoryProvider.notifier)
|
||||
.openDocument(pageCount: 5);
|
||||
container
|
||||
.read(documentRepositoryProvider.notifier)
|
||||
.addPlacement(
|
||||
|
|
|
|||
|
|
@ -13,7 +13,9 @@ aDocumentIsOpenAndContainsMultiplePlacedSignaturePlacementsAcrossPages(
|
|||
) async {
|
||||
final container = TestWorld.container ?? ProviderContainer();
|
||||
TestWorld.container = container;
|
||||
container.read(documentRepositoryProvider.notifier).openPickedWithPageCount(pageCount: 5);
|
||||
container
|
||||
.read(documentRepositoryProvider.notifier)
|
||||
.openDocument(pageCount: 5);
|
||||
container
|
||||
.read(documentRepositoryProvider.notifier)
|
||||
.addPlacement(
|
||||
|
|
|
|||
|
|
@ -11,6 +11,6 @@ Future<void> aDocumentIsOpenWithNoSignaturePlacementsPlaced(
|
|||
TestWorld.container = container;
|
||||
container
|
||||
.read(documentRepositoryProvider.notifier)
|
||||
.openPickedWithPageCount(pageCount: 5);
|
||||
.openDocument(pageCount: 5);
|
||||
// No placements added
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ Future<void> aDocumentPageIsSelectedForSigning(WidgetTester tester) async {
|
|||
// Ensure a document is open
|
||||
final repo = container.read(documentRepositoryProvider.notifier);
|
||||
if (!container.read(documentRepositoryProvider).loaded) {
|
||||
repo.openPickedWithPageCount(pageCount: 5);
|
||||
repo.openDocument(pageCount: 5);
|
||||
}
|
||||
// Ensure current page is 1 for consistent subsequent steps
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,9 @@ Future<void> aMultipageDocumentIsOpen(WidgetTester tester) async {
|
|||
container.read(signatureCardRepositoryProvider.notifier).state = [
|
||||
SignatureCard.initial(),
|
||||
];
|
||||
container.read(documentRepositoryProvider.notifier).openPickedWithPageCount(pageCount: 5);
|
||||
container
|
||||
.read(documentRepositoryProvider.notifier)
|
||||
.openDocument(pageCount: 5);
|
||||
// Reset page state providers
|
||||
try {
|
||||
container.read(pdfViewModelProvider.notifier).jumpToPage(1);
|
||||
|
|
|
|||
|
|
@ -11,5 +11,5 @@ Future<void> aSampleMultipageDocument5PagesIsAvailable(
|
|||
TestWorld.container = container;
|
||||
container
|
||||
.read(documentRepositoryProvider.notifier)
|
||||
.openPickedWithPageCount(pageCount: 5);
|
||||
.openDocument(pageCount: 5);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ Future<void> aSignatureAssetIsPlacedOnThePage(WidgetTester tester) async {
|
|||
if (!container.read(documentRepositoryProvider).loaded) {
|
||||
container
|
||||
.read(documentRepositoryProvider.notifier)
|
||||
.openPickedWithPageCount(pageCount: 5);
|
||||
.openDocument(pageCount: 5);
|
||||
}
|
||||
|
||||
// Get or create an asset
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ Future<void> aSignaturePlacementIsPlacedOnPage(
|
|||
if (!container.read(documentRepositoryProvider).loaded) {
|
||||
container
|
||||
.read(documentRepositoryProvider.notifier)
|
||||
.openPickedWithPageCount(pageCount: 5);
|
||||
.openDocument(pageCount: 5);
|
||||
}
|
||||
final page = param1.toInt();
|
||||
container
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ Future<void> aSignaturePlacementIsPlacedWithAPositionAndSizeRelativeToThePage(
|
|||
if (!container.read(documentRepositoryProvider).loaded) {
|
||||
container
|
||||
.read(documentRepositoryProvider.notifier)
|
||||
.openPickedWithPageCount(pageCount: 5);
|
||||
.openDocument(pageCount: 5);
|
||||
}
|
||||
final currentPage = container.read(pdfViewModelProvider).currentPage;
|
||||
container
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ Future<void> draggingOrResizingOneDoesNotChangeTheOther(
|
|||
final changedFirst = firstRectBefore.inflate(5);
|
||||
container
|
||||
.read(documentRepositoryProvider.notifier)
|
||||
.updatePlacementRect(page: page, index: 0, rect: changedFirst);
|
||||
.modifyPlacement(page: page, index: 0, rect: changedFirst);
|
||||
|
||||
final after = container
|
||||
.read(documentRepositoryProvider.notifier)
|
||||
|
|
|
|||
|
|
@ -26,6 +26,6 @@ Future<void> theUserDragsHandlesToResizeAndDragsToReposition(
|
|||
height: currentRect.height + 30,
|
||||
);
|
||||
|
||||
pdfN.updatePlacementRect(page: currentPage, index: 0, rect: newRect);
|
||||
pdfN.modifyPlacement(page: currentPage, index: 0, rect: newRect);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ theUserDragsItOnThePageOfTheDocumentToPlaceSignaturePlacementsInMultipleLocation
|
|||
if (!container.read(documentRepositoryProvider).loaded) {
|
||||
container
|
||||
.read(documentRepositoryProvider.notifier)
|
||||
.openPickedWithPageCount(pageCount: 5);
|
||||
.openDocument(pageCount: 5);
|
||||
}
|
||||
|
||||
container
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ theUserDragsThisSignatureCardOnThePageOfTheDocumentToPlaceASignaturePlacement(
|
|||
if (!container.read(documentRepositoryProvider).loaded) {
|
||||
container
|
||||
.read(documentRepositoryProvider.notifier)
|
||||
.openPickedWithPageCount(pageCount: 5);
|
||||
.openDocument(pageCount: 5);
|
||||
}
|
||||
|
||||
// Get or create an asset
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ Future<void> theUserOpensADifferentDocumentWithPages(
|
|||
// Simulate "open a different document": reset placements and set page count.
|
||||
container
|
||||
.read(documentRepositoryProvider.notifier)
|
||||
.openPickedWithPageCount(pageCount: pageCount);
|
||||
.openDocument(pageCount: pageCount);
|
||||
// Ensure there are 2 signature cards available as per scenario.
|
||||
final cards = container.read(signatureCardRepositoryProvider);
|
||||
if (cards.length < 2) {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ Future<void> theUserPlacesItInMultipleLocationsInTheDocument(
|
|||
TestWorld.container = container;
|
||||
final notifier = container.read(documentRepositoryProvider.notifier);
|
||||
// Always open a fresh doc to avoid state bleed between scenarios
|
||||
notifier.openPickedWithPageCount(pageCount: 6);
|
||||
notifier.openDocument(pageCount: 6);
|
||||
// Place two on page 2 and one on page 4
|
||||
notifier.addPlacement(page: 2, rect: const Rect.fromLTWH(10, 10, 80, 40));
|
||||
notifier.addPlacement(page: 2, rect: const Rect.fromLTWH(120, 50, 80, 40));
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ Future<void> theUserSavesexportsTheDocument(WidgetTester tester) async {
|
|||
// Load a minimal sample so the expectation passes in logic-only tests
|
||||
container
|
||||
.read(documentRepositoryProvider.notifier)
|
||||
.openPickedWithPageCount(pageCount: 2, bytes: Uint8List(10));
|
||||
.openDocument(bytes: Uint8List(10), pageCount: 2, knownPageCount: true);
|
||||
}
|
||||
expect(pdf.loaded, isTrue, reason: 'PDF must be loaded before export');
|
||||
// Check if there are placements
|
||||
|
|
|
|||
|
|
@ -10,7 +10,9 @@ Future<void> theUserSelects(WidgetTester tester, dynamic file) async {
|
|||
final container = ProviderContainer();
|
||||
TestWorld.container = container;
|
||||
// Mark page for signing to enable signature ops
|
||||
container.read(documentRepositoryProvider.notifier).openPickedWithPageCount(pageCount: 1);
|
||||
container
|
||||
.read(documentRepositoryProvider.notifier)
|
||||
.openDocument(pageCount: 1);
|
||||
// For invalid/unsupported/empty selections we do NOT set image bytes.
|
||||
// This simulates a failed load and keeps rect null.
|
||||
final token = file.toString();
|
||||
|
|
|
|||
|
|
@ -11,10 +11,6 @@ Future<void> theUserUsesRotateControls(WidgetTester tester) async {
|
|||
final currentPage = container.read(pdfViewModelProvider).currentPage;
|
||||
final placements = pdfN.placementsOn(currentPage);
|
||||
if (placements.isNotEmpty) {
|
||||
pdfN.updatePlacementRotation(
|
||||
page: currentPage,
|
||||
index: 0,
|
||||
rotationDeg: 45.0,
|
||||
);
|
||||
pdfN.modifyPlacement(page: currentPage, index: 0, rotationDeg: 45.0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,9 @@ Future<void> threeSignaturePlacementsArePlacedOnTheCurrentPage(
|
|||
container.read(signatureCardRepositoryProvider.notifier).state = [
|
||||
SignatureCard.initial(),
|
||||
];
|
||||
container.read(documentRepositoryProvider.notifier).openPickedWithPageCount(pageCount: 5);
|
||||
container
|
||||
.read(documentRepositoryProvider.notifier)
|
||||
.openDocument(pageCount: 5);
|
||||
final pdfN = container.read(documentRepositoryProvider.notifier);
|
||||
final page = container.read(pdfViewModelProvider).currentPage;
|
||||
pdfN.addPlacement(
|
||||
|
|
|
|||
|
|
@ -48,8 +48,11 @@ void main() {
|
|||
),
|
||||
documentRepositoryProvider.overrideWith(
|
||||
(ref) =>
|
||||
DocumentStateNotifier()
|
||||
..openPickedWithPageCount(pageCount: 5, bytes: Uint8List(0)),
|
||||
DocumentStateNotifier()..openDocument(
|
||||
bytes: Uint8List(0),
|
||||
pageCount: 5,
|
||||
knownPageCount: true,
|
||||
),
|
||||
),
|
||||
pdfViewModelProvider.overrideWith(
|
||||
(ref) => PdfViewModel(ref, useMockViewer: true),
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ void main() {
|
|||
}) async {
|
||||
final container = ProviderScope.containerOf(stateful.context);
|
||||
final repo = container.read(documentRepositoryProvider.notifier);
|
||||
repo.openPickedWithPageCount(pageCount: 1, bytes: bytes);
|
||||
repo.openDocument(bytes: bytes, pageCount: 1, knownPageCount: true);
|
||||
}, [fake]);
|
||||
await tester.pump();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue