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