feat: partially implement new ui widget
This commit is contained in:
parent
d9969e5ea5
commit
b0a3ff1f57
|
|
@ -0,0 +1,65 @@
|
||||||
|
import 'dart:typed_data';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import 'package:pdf_signature/data/repositories/document_repository.dart';
|
||||||
|
import 'package:pdf_signature/data/repositories/signature_card_repository.dart';
|
||||||
|
import 'package:pdf_signature/domain/models/model.dart';
|
||||||
|
import 'package:pdfrx/pdfrx.dart';
|
||||||
|
|
||||||
|
class PdfViewModel {
|
||||||
|
final Ref ref;
|
||||||
|
|
||||||
|
PdfViewModel(this.ref);
|
||||||
|
|
||||||
|
Document get document => ref.read(documentRepositoryProvider);
|
||||||
|
|
||||||
|
void jumpToPage(int page) {
|
||||||
|
ref.read(documentRepositoryProvider.notifier).jumpTo(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> openPdf({required String path, Uint8List? bytes}) async {
|
||||||
|
int pageCount = 1;
|
||||||
|
if (bytes != null) {
|
||||||
|
try {
|
||||||
|
final doc = await PdfDocument.openData(bytes);
|
||||||
|
pageCount = doc.pages.length;
|
||||||
|
} catch (_) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ref
|
||||||
|
.read(documentRepositoryProvider.notifier)
|
||||||
|
.openPicked(path: path, pageCount: pageCount, bytes: bytes);
|
||||||
|
ref.read(signatureCardProvider.notifier).clearAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Uint8List?> loadSignatureFromFile() async {
|
||||||
|
// This would need file picker, but since it's UI logic, perhaps keep in widget
|
||||||
|
// For now, return null
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
void confirmSignature() {
|
||||||
|
// Need to implement based on original logic
|
||||||
|
}
|
||||||
|
|
||||||
|
void onDragSignature(Offset delta) {
|
||||||
|
// Implement drag
|
||||||
|
}
|
||||||
|
|
||||||
|
void onResizeSignature(Offset delta) {
|
||||||
|
// Implement resize
|
||||||
|
}
|
||||||
|
|
||||||
|
void onSelectPlaced(int? index) {
|
||||||
|
// ref.read(documentRepositoryProvider.notifier).selectPlacement(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> saveSignedPdf() async {
|
||||||
|
// Implement save logic
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final pdfViewModelProvider = Provider<PdfViewModel>((ref) {
|
||||||
|
return PdfViewModel(ref);
|
||||||
|
});
|
||||||
|
|
@ -62,10 +62,9 @@ class _PdfSignatureHomePageState extends ConsumerState<PdfSignatureHomePage> {
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
bytes = null;
|
bytes = null;
|
||||||
}
|
}
|
||||||
ref
|
await ref
|
||||||
.read(documentRepositoryProvider.notifier)
|
.read(pdfViewModelProvider)
|
||||||
.openPicked(path: file.path, bytes: bytes);
|
.openPdf(path: file.path, bytes: bytes);
|
||||||
ref.read(signatureProvider.notifier).resetForNewPage();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
|
||||||
|
class PreferencesViewModel {
|
||||||
|
final Ref ref;
|
||||||
|
|
||||||
|
PreferencesViewModel(this.ref);
|
||||||
|
|
||||||
|
// Add methods as needed
|
||||||
|
}
|
||||||
|
|
||||||
|
final preferencesViewModelProvider = Provider<PreferencesViewModel>((ref) {
|
||||||
|
return PreferencesViewModel(ref);
|
||||||
|
});
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
|
||||||
|
class SignatureViewModel {
|
||||||
|
final Ref ref;
|
||||||
|
|
||||||
|
SignatureViewModel(this.ref);
|
||||||
|
|
||||||
|
// Add methods as needed
|
||||||
|
}
|
||||||
|
|
||||||
|
final signatureViewModelProvider = Provider<SignatureViewModel>((ref) {
|
||||||
|
return SignatureViewModel(ref);
|
||||||
|
});
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
import 'dart:typed_data';
|
||||||
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import 'package:pdf_signature/data/repositories/document_repository.dart';
|
||||||
|
import 'package:pdf_signature/data/repositories/signature_card_repository.dart';
|
||||||
|
import 'package:pdfrx/pdfrx.dart';
|
||||||
|
|
||||||
|
class WelcomeViewModel {
|
||||||
|
final Ref ref;
|
||||||
|
|
||||||
|
WelcomeViewModel(this.ref);
|
||||||
|
|
||||||
|
Future<void> openPdf({required String path, Uint8List? bytes}) async {
|
||||||
|
int pageCount = 1; // default
|
||||||
|
if (bytes != null) {
|
||||||
|
try {
|
||||||
|
final doc = await PdfDocument.openData(bytes);
|
||||||
|
pageCount = doc.pages.length;
|
||||||
|
} catch (_) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ref
|
||||||
|
.read(documentRepositoryProvider.notifier)
|
||||||
|
.openPicked(path: path, pageCount: pageCount, bytes: bytes);
|
||||||
|
ref.read(signatureCardProvider.notifier).clearAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final welcomeViewModelProvider = Provider<WelcomeViewModel>((ref) {
|
||||||
|
return WelcomeViewModel(ref);
|
||||||
|
});
|
||||||
|
|
@ -6,10 +6,7 @@ import 'package:flutter/foundation.dart' show kIsWeb;
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:pdf_signature/l10n/app_localizations.dart';
|
import 'package:pdf_signature/l10n/app_localizations.dart';
|
||||||
|
import 'package:pdf_signature/ui/features/welcome/view_model/welcome_view_model.dart';
|
||||||
import 'package:pdf_signature/data/repositories/signature_card_repository.dart';
|
|
||||||
import 'package:pdf_signature/data/repositories/document_repository.dart';
|
|
||||||
// Settings dialog is provided via global AppBar in MyApp
|
|
||||||
|
|
||||||
// Abstraction to make drop handling testable without constructing
|
// Abstraction to make drop handling testable without constructing
|
||||||
// platform-specific DropItem types in widget tests.
|
// platform-specific DropItem types in widget tests.
|
||||||
|
|
@ -50,10 +47,7 @@ Future<void> handleDroppedFiles(
|
||||||
bytes = null;
|
bytes = null;
|
||||||
}
|
}
|
||||||
final String path = pdf.path ?? pdf.name;
|
final String path = pdf.path ?? pdf.name;
|
||||||
read(
|
await read(welcomeViewModelProvider).openPdf(path: path, bytes: bytes);
|
||||||
documentRepositoryProvider.notifier,
|
|
||||||
).openPicked(path: path, bytes: bytes);
|
|
||||||
read(signatureProvider.notifier).resetForNewPage();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class WelcomeScreen extends ConsumerStatefulWidget {
|
class WelcomeScreen extends ConsumerStatefulWidget {
|
||||||
|
|
@ -76,10 +70,9 @@ class _WelcomeScreenState extends ConsumerState<WelcomeScreen> {
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
bytes = null;
|
bytes = null;
|
||||||
}
|
}
|
||||||
ref
|
await ref
|
||||||
.read(documentRepositoryProvider.notifier)
|
.read(welcomeViewModelProvider)
|
||||||
.openPicked(path: file.path, bytes: bytes);
|
.openPdf(path: file.path, bytes: bytes);
|
||||||
ref.read(signatureProvider.notifier).resetForNewPage();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue