Compare commits

..

No commits in common. "b2bf489af09e367ee52ca0dbc34fa87a50c4c7e9" and "0a512919a54d5f416e0bc68a6bb2d067dee7a48d" have entirely different histories.

16 changed files with 169 additions and 401 deletions

View File

@ -22,9 +22,8 @@ flutter analyze
# > run unit tests and widget tests
flutter test
# > run integration tests
# flutter test integration_test/ -d <device_id>
# Examples: --device=windows | --device=linux | --device=macos | --device=chrome
dart run tool/run_integration_tests.dart --device=<device_id>
flutter test integration_test/ -d <device_id>
# dart run tool/run_integration_tests.dart --device=linux (necessary for linux)
# dart run tool/gen_view_wireframe_md.dart
# flutter pub run dead_code_analyzer

View File

@ -19,7 +19,7 @@ pluginManagement {
plugins {
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
id("com.android.application") version "8.7.0" apply false
id("org.jetbrains.kotlin.android") version "2.1.0" apply false
id("org.jetbrains.kotlin.android") version "1.8.22" apply false
}
include(":app")

View File

@ -94,5 +94,3 @@ Some rule of thumb:
* whole app use its image object as image representation.
* aware that minimize, encode/decode usage, because its has poor performance on web
* `ColorFilterGenerator` can not replace `adjustColor` due to custom background removal algorithm need at last stage. It is GPU based, and offscreen-render then readback is not ideal.
* [responsive_framework]
* RWD support

View File

@ -1,6 +1,6 @@
import 'dart:io';
import 'package:cross_file/cross_file.dart';
import 'package:file_selector/file_selector.dart' as fs;
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
@ -63,7 +63,7 @@ void main() {
home: PdfSignatureHomePage(
onPickPdf: () async {},
onClosePdf: () {},
currentFile: XFile('test.pdf'),
currentFile: fs.XFile('test.pdf'),
),
),
),
@ -119,7 +119,7 @@ void main() {
home: PdfSignatureHomePage(
onPickPdf: () async {},
onClosePdf: () {},
currentFile: XFile('test.pdf'),
currentFile: fs.XFile('test.pdf'),
),
),
),
@ -177,7 +177,7 @@ void main() {
home: PdfSignatureHomePage(
onPickPdf: () async {},
onClosePdf: () {},
currentFile: XFile('test.pdf'),
currentFile: fs.XFile('test.pdf'),
),
),
),
@ -223,7 +223,7 @@ void main() {
home: PdfSignatureHomePage(
onPickPdf: () async {},
onClosePdf: () {},
currentFile: XFile('test.pdf'),
currentFile: fs.XFile('test.pdf'),
),
),
),
@ -272,7 +272,7 @@ void main() {
home: PdfSignatureHomePage(
onPickPdf: () async {},
onClosePdf: () {},
currentFile: XFile('test.pdf'),
currentFile: fs.XFile('test.pdf'),
),
),
),
@ -324,7 +324,7 @@ void main() {
home: PdfSignatureHomePage(
onPickPdf: () async {},
onClosePdf: () {},
currentFile: XFile('test.pdf'),
currentFile: fs.XFile('test.pdf'),
),
),
),
@ -390,7 +390,7 @@ void main() {
home: PdfSignatureHomePage(
onPickPdf: () async {},
onClosePdf: () {},
currentFile: XFile('test.pdf'),
currentFile: fs.XFile('test.pdf'),
),
),
),

View File

@ -3,7 +3,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'dart:io';
import 'package:cross_file/cross_file.dart';
import 'package:file_selector/file_selector.dart' as fs;
import 'package:pdf_signature/ui/features/pdf/widgets/pdf_screen.dart';
import 'package:pdf_signature/ui/features/pdf/widgets/pages_sidebar.dart';
@ -47,7 +47,7 @@ void main() {
home: PdfSignatureHomePage(
onPickPdf: () async {},
onClosePdf: () {},
currentFile: XFile('test.pdf'),
currentFile: fs.XFile('test.pdf'),
),
),
),
@ -101,7 +101,7 @@ void main() {
home: PdfSignatureHomePage(
onPickPdf: () async {},
onClosePdf: () {},
currentFile: XFile('test.pdf'),
currentFile: fs.XFile('test.pdf'),
),
),
),
@ -155,7 +155,7 @@ void main() {
home: PdfSignatureHomePage(
onPickPdf: () async {},
onClosePdf: () {},
currentFile: XFile('test.pdf'),
currentFile: fs.XFile('test.pdf'),
),
),
),
@ -242,7 +242,7 @@ void main() {
home: PdfSignatureHomePage(
onPickPdf: () async {},
onClosePdf: () {},
currentFile: XFile('test.pdf'),
currentFile: fs.XFile('test.pdf'),
),
),
),
@ -308,7 +308,7 @@ void main() {
home: PdfSignatureHomePage(
onPickPdf: () async {},
onClosePdf: () {},
currentFile: XFile('test.pdf'),
currentFile: fs.XFile('test.pdf'),
),
),
),

View File

@ -5,7 +5,6 @@ import 'package:pdf_signature/l10n/app_localizations.dart';
import 'package:pdf_signature/routing/router.dart';
import 'package:pdf_signature/ui/features/preferences/widgets/settings_screen.dart';
import 'data/repositories/preferences_repository.dart';
import 'package:responsive_framework/responsive_framework.dart';
class MyApp extends StatelessWidget {
const MyApp({super.key});
@ -57,7 +56,7 @@ class MyApp extends StatelessWidget {
routerConfig: ref.watch(routerProvider),
builder: (context, child) {
final router = ref.watch(routerProvider);
final content = Scaffold(
return Scaffold(
appBar: AppBar(
title: Text(AppLocalizations.of(context).appTitle),
actions: [
@ -79,17 +78,6 @@ class MyApp extends StatelessWidget {
),
body: child,
);
// Apply Responsive Framework globally for layout and scrolling.
return ResponsiveBreakpoints.builder(
child: ClampingScrollWrapper.builder(context, content),
breakpoints: const [
Breakpoint(start: 0, end: 450, name: MOBILE),
Breakpoint(start: 451, end: 800, name: TABLET),
Breakpoint(start: 801, end: 1920, name: DESKTOP),
Breakpoint(start: 1921, end: double.infinity, name: '4K'),
],
);
},
);
},

View File

@ -1,6 +1,4 @@
import 'dart:io' show Platform;
import 'package:file_picker/file_picker.dart' as fp;
import 'package:path_provider/path_provider.dart' as pp;
import 'package:file_selector/file_selector.dart' as fs;
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
@ -74,51 +72,13 @@ class PdfExportViewModel extends ChangeNotifier {
static Future<String?> _defaultSavePathPickerWithSuggestedName(
String suggestedName,
) async {
// Prefer native save dialog via file_picker on all non-web platforms.
// If the user cancels (null) simply bubble up null. If an exception occurs
// (unsupported platform or plugin issue), fall back to an app documents path.
try {
final result = await fp.FilePicker.platform.saveFile(
dialogTitle: 'Please select an output file:',
fileName: suggestedName,
type: fp.FileType.custom,
allowedExtensions: const ['pdf'],
// lockParentWindow is ignored on mobile; useful on desktop.
lockParentWindow: true,
final group = fs.XTypeGroup(label: 'PDF', extensions: ['pdf']);
final location = await fs.getSaveLocation(
acceptedTypeGroups: [group],
suggestedName: suggestedName,
confirmButtonText: 'Save',
);
return result; // null if canceled
} catch (_) {
// Fall through to app documents fallback below.
}
debugPrint(
'Fallback: select a folder and build path with suggested name (mobile platform)',
);
// On some mobile providers, saveFile may not present a picker or returns null.
// Offer a folder picker and compose the final path.
if (Platform.isAndroid || Platform.isIOS) {
final dir = await fp.FilePicker.platform.getDirectoryPath(
dialogTitle: 'Select folder to save',
lockParentWindow: true,
);
if (dir != null && dir.trim().isNotEmpty) {
final d = dir.trim();
final needsSep = !(d.endsWith('/') || d.endsWith('\\'));
return (needsSep ? (d + '/') : d) + suggestedName;
}
// User canceled directory selection; bubble up null.
return null;
}
debugPrint('Fallback: build a default path (web platform)');
try {
final dir = await pp.getApplicationDocumentsDirectory();
return '${dir.path}/$suggestedName';
} catch (_) {
// Last resort: let the caller handle a null path
return null;
}
return location?.path; // null if user cancels
}
}

View File

@ -1,12 +1,12 @@
import 'dart:typed_data';
import 'package:cross_file/cross_file.dart';
import 'package:file_selector/file_selector.dart';
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';
import 'package:file_picker/file_picker.dart' as fp;
import 'package:file_selector/file_selector.dart' as fs;
import 'package:go_router/go_router.dart';
class PdfViewModel extends ChangeNotifier {
@ -247,7 +247,7 @@ final pdfViewModelProvider = ChangeNotifierProvider<PdfViewModel>((ref) {
class PdfSessionViewModel extends ChangeNotifier {
final Ref ref;
final GoRouter router;
XFile _currentFile = XFile('');
fs.XFile _currentFile = fs.XFile('');
// Keep a human display name in addition to XFile, because on Linux via
// xdg-desktop-portal the path can look like /run/user/.../doc/<UUID>, and
// XFile.name derives from that basename, yielding a random UUID instead of
@ -257,29 +257,21 @@ class PdfSessionViewModel extends ChangeNotifier {
PdfSessionViewModel({required this.ref, required this.router});
XFile get currentFile => _currentFile;
fs.XFile get currentFile => _currentFile;
String get displayFileName => _displayFileName;
Future<void> pickAndOpenPdf() async {
final result = await fp.FilePicker.platform.pickFiles(
type: fp.FileType.custom,
allowedExtensions: const ['pdf'],
withData: true,
);
if (result == null || result.files.isEmpty) return;
final picked = result.files.single;
final String name = picked.name;
final String? path = picked.path;
final Uint8List? bytes = picked.bytes;
Uint8List? effectiveBytes = bytes;
if (effectiveBytes == null && path != null && path.isNotEmpty) {
final typeGroup = const fs.XTypeGroup(label: 'PDF', extensions: ['pdf']);
final XFile? file = await fs.openFile(acceptedTypeGroups: [typeGroup]);
if (file != null) {
Uint8List? bytes;
try {
effectiveBytes = await XFile(path).readAsBytes();
bytes = await file.readAsBytes();
} catch (_) {
effectiveBytes = null;
bytes = null;
}
await openPdf(path: file.path, bytes: bytes, fileName: file.name);
}
await openPdf(path: path, bytes: effectiveBytes, fileName: name);
}
Future<void> openPdf({
@ -297,20 +289,20 @@ class PdfSessionViewModel extends ChangeNotifier {
}
}
if (path != null && path.isNotEmpty) {
_currentFile = XFile(path);
_currentFile = fs.XFile(path);
} else if (bytes != null && (fileName != null && fileName.isNotEmpty)) {
// Keep in-memory XFile so .name is available for suggestion
try {
_currentFile = XFile.fromData(
_currentFile = fs.XFile.fromData(
bytes,
name: fileName,
mimeType: 'application/pdf',
);
} catch (_) {
_currentFile = XFile(fileName);
_currentFile = fs.XFile(fileName);
}
} else {
_currentFile = XFile('');
_currentFile = fs.XFile('');
}
// Update display name: prefer explicit fileName (from picker/drop),
@ -333,7 +325,7 @@ class PdfSessionViewModel extends ChangeNotifier {
void closePdf() {
ref.read(documentRepositoryProvider.notifier).close();
ref.read(signatureCardRepositoryProvider.notifier).clearAll();
_currentFile = XFile('');
_currentFile = fs.XFile('');
_displayFileName = '';
router.go('/');
notifyListeners();

View File

@ -93,11 +93,8 @@ class ThumbnailsView extends ConsumerWidget {
padding: const EdgeInsets.all(6),
child: Column(
children: [
ConstrainedBox(
constraints: const BoxConstraints(maxHeight: 180),
child: AspectRatio(
// A4 portrait aspect: width:height 1:1.4142
aspectRatio: 1 / 1.4142,
SizedBox(
height: 180,
child: ClipRRect(
borderRadius: BorderRadius.circular(4),
child: PdfPageView(
@ -107,7 +104,6 @@ class ThumbnailsView extends ConsumerWidget {
),
),
),
),
const SizedBox(height: 4),
Text('$pageNumber', style: theme.textTheme.bodySmall),
],

View File

@ -1,5 +1,4 @@
import 'package:cross_file/cross_file.dart';
import 'package:file_picker/file_picker.dart' as fp;
import 'package:file_selector/file_selector.dart' as fs;
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
@ -18,12 +17,11 @@ import 'package:pdf_signature/utils/download.dart';
import '../view_model/pdf_view_model.dart';
import 'package:image/image.dart' as img;
import 'package:pdf_signature/data/repositories/document_repository.dart';
import 'package:responsive_framework/responsive_framework.dart';
class PdfSignatureHomePage extends ConsumerStatefulWidget {
final Future<void> Function() onPickPdf;
final VoidCallback onClosePdf;
final XFile currentFile;
final fs.XFile currentFile;
// Optional display name for the currently opened file. On Linux
// xdg-desktop-portal, XFile.name/path can be a UUID-like value. When
// available, this name preserves the user-selected filename so we can
@ -60,7 +58,6 @@ class _PdfSignatureHomePageState extends ConsumerState<PdfSignatureHomePage> {
final double _signaturesMin = 140;
final double _signaturesMax = 250;
late PdfViewModel _viewModel;
bool? _lastCanShowPagesSidebar;
// Exposed for tests to trigger the invalid-file SnackBar without UI.
@visibleForTesting
@ -114,18 +111,15 @@ class _PdfSignatureHomePageState extends ConsumerState<PdfSignatureHomePage> {
}
Future<img.Image?> _loadSignatureFromFile() async {
final result = await fp.FilePicker.platform.pickFiles(
type: fp.FileType.custom,
allowedExtensions: const ['png', 'jpg', 'jpeg', 'webp'],
withData: true,
final typeGroup = fs.XTypeGroup(
label:
Localizations.of<AppLocalizations>(context, AppLocalizations)?.image,
extensions: ['png', 'jpg', 'jpeg', 'webp'],
);
if (result == null || result.files.isEmpty) return null;
final picked = result.files.single;
final Uint8List? bytes =
picked.bytes ??
(picked.path != null ? await XFile(picked.path!).readAsBytes() : null);
final file = await fs.openFile(acceptedTypeGroups: [typeGroup]);
if (file == null) return null;
final bytes = await file.readAsBytes();
try {
if (bytes == null) return null;
var sigImage = img.decodeImage(bytes);
return _toStdSignatureImage(sigImage);
} catch (_) {
@ -312,9 +306,7 @@ class _PdfSignatureHomePageState extends ConsumerState<PdfSignatureHomePage> {
max: _pagesMax,
builder:
(context, area) => Offstage(
offstage:
!(ResponsiveBreakpoints.of(context).largerThan(MOBILE) &&
_showPagesSidebar),
offstage: !_showPagesSidebar,
child: Consumer(
builder: (context, ref, child) {
final pdfViewModel = ref.watch(pdfViewModelProvider);
@ -368,24 +360,6 @@ class _PdfSignatureHomePageState extends ConsumerState<PdfSignatureHomePage> {
_applySidebarVisibility();
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
// Detect breakpoint changes from Responsive Framework and update areas once.
bool canShowPagesSidebar = true;
try {
canShowPagesSidebar = ResponsiveBreakpoints.of(
context,
).largerThan(MOBILE);
} catch (_) {
canShowPagesSidebar = true;
}
if (_lastCanShowPagesSidebar != canShowPagesSidebar) {
_lastCanShowPagesSidebar = canShowPagesSidebar;
_applySidebarVisibility();
}
}
@override
void dispose() {
_viewModel.controller.removeListener(_onControllerChanged);
@ -394,67 +368,31 @@ class _PdfSignatureHomePageState extends ConsumerState<PdfSignatureHomePage> {
}
void _applySidebarVisibility() {
// Respect responsive layout: disable Pages sidebar on MOBILE.
bool canShowPagesSidebar = true;
try {
canShowPagesSidebar = ResponsiveBreakpoints.of(
context,
).largerThan(MOBILE);
} catch (_) {
// If ResponsiveBreakpoints isn't available yet (e.g., during early init),
// fall back to allowing sidebars to avoid crashes; builders also guard.
canShowPagesSidebar = true;
}
// Left pages sidebar
final left = _splitController.areas[0];
final wantPagesVisible = _showPagesSidebar && canShowPagesSidebar;
final isPagesHidden =
(left.max == 1 && left.min == 0 && (left.size ?? 1) == 1);
if (wantPagesVisible) {
// Only expand if currently hidden; otherwise keep user's size.
if (isPagesHidden) {
if (_showPagesSidebar) {
left.max = _pagesMax;
left.min = _pagesMin;
left.size = _lastPagesWidth.clamp(_pagesMin, _pagesMax);
} else {
left.max = _pagesMax;
left.min = _pagesMin;
// Preserve current size (user may have adjusted it).
_lastPagesWidth = left.size ?? _lastPagesWidth;
}
} else {
// Only collapse if currently visible; remember current size for restore.
if (!isPagesHidden) {
_lastPagesWidth = left.size ?? _lastPagesWidth;
left.min = 0;
left.max = 1;
left.size = 1; // effectively hidden
}
}
// Right signatures sidebar
final right = _splitController.areas[2];
final isSignaturesHidden =
(right.max == 1 && right.min == 0 && (right.size ?? 1) == 1);
if (_showSignaturesSidebar) {
if (isSignaturesHidden) {
right.max = _signaturesMax;
right.min = _signaturesMin;
right.size = _lastSignaturesWidth.clamp(_signaturesMin, _signaturesMax);
} else {
right.max = _signaturesMax;
right.min = _signaturesMin;
_lastSignaturesWidth = right.size ?? _lastSignaturesWidth;
}
} else {
if (!isSignaturesHidden) {
_lastSignaturesWidth = right.size ?? _lastSignaturesWidth;
right.min = 0;
right.max = 1;
right.size = 1;
}
}
}
@override
Widget build(BuildContext context) {

View File

@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:pdf_signature/l10n/app_localizations.dart';
import 'package:responsive_framework/responsive_framework.dart';
import 'package:pdf_signature/ui/features/pdf/view_model/pdf_view_model.dart';
@ -68,16 +67,6 @@ class _PdfToolbarState extends ConsumerState<PdfToolbar> {
builder: (context, constraints) {
final bool compact = constraints.maxWidth < 260;
final double gotoWidth = 50;
final bool isLargerThanMobile = ResponsiveBreakpoints.of(
context,
).largerThan(MOBILE);
final String fileDisplay = () {
final path = widget.filePath;
if (path == null || path.isEmpty) return 'No file selected';
if (isLargerThanMobile) return path;
// Extract file name for mobile (supports both / and \ separators)
return path.split('/').last.split('\\').last;
}();
// Center content of the toolbar
final center = Wrap(
@ -93,17 +82,16 @@ class _PdfToolbarState extends ConsumerState<PdfToolbar> {
children: [
const Icon(Icons.insert_drive_file, size: 18),
const SizedBox(width: 6),
Flexible(
child: ConstrainedBox(
ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 220),
child: Text(
fileDisplay,
maxLines: 1,
softWrap: false,
// if filePath not null
widget.filePath != null
? widget.filePath!
: 'No file selected',
overflow: TextOverflow.ellipsis,
),
),
),
],
),
),
@ -142,7 +130,6 @@ class _PdfToolbarState extends ConsumerState<PdfToolbar> {
),
],
),
if (ResponsiveBreakpoints.of(context).largerThan(MOBILE))
Wrap(
spacing: 6,
runSpacing: 4,
@ -175,8 +162,6 @@ class _PdfToolbarState extends ConsumerState<PdfToolbar> {
),
],
),
if (ResponsiveBreakpoints.of(context).largerThan(MOBILE)) ...[
const SizedBox(width: 8),
Wrap(
crossAxisAlignment: WrapCrossAlignment.center,
@ -189,9 +174,7 @@ class _PdfToolbarState extends ConsumerState<PdfToolbar> {
),
Text(
//if not null
widget.zoomLevel != null
? '${widget.zoomLevel}%'
: '',
widget.zoomLevel != null ? '${widget.zoomLevel}%' : '',
style: const TextStyle(fontSize: 12),
),
IconButton(
@ -204,7 +187,6 @@ class _PdfToolbarState extends ConsumerState<PdfToolbar> {
),
SizedBox(width: 6),
],
],
),
],
],
@ -212,7 +194,6 @@ class _PdfToolbarState extends ConsumerState<PdfToolbar> {
return Row(
children: [
if (ResponsiveBreakpoints.of(context).largerThan(MOBILE)) ...[
IconButton(
key: const Key('btn_toggle_pages_sidebar'),
tooltip: 'Toggle pages overview',
@ -226,7 +207,6 @@ class _PdfToolbarState extends ConsumerState<PdfToolbar> {
),
),
const SizedBox(width: 8),
],
Expanded(child: center),
const SizedBox(width: 8),
IconButton(

View File

@ -37,6 +37,7 @@ dependencies:
flutter_riverpod: ^2.6.1
shared_preferences: ^2.5.3
flutter_dotenv: ^6.0.0
file_selector: ^1.0.3
path_provider: ^2.1.5
pdfrx: ^2.1.9
pdf: ^3.10.8
@ -58,8 +59,6 @@ dependencies:
riverpod_annotation: ^2.6.1
colorfilter_generator: ^0.0.8
flutter_box_transform: ^0.4.7
file_picker: ^10.3.3
responsive_framework: ^1.5.1
# disable_web_context_menu: ^1.1.0
# ml_linalg: ^13.12.6

View File

@ -1,5 +1,5 @@
import 'dart:typed_data';
import 'package:cross_file/cross_file.dart';
import 'package:file_selector/file_selector.dart' as fs;
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
@ -14,26 +14,6 @@ import 'package:pdf_signature/data/repositories/document_repository.dart';
import 'package:pdf_signature/ui/features/pdf/widgets/pdf_screen.dart';
import 'package:pdf_signature/l10n/app_localizations.dart';
// A fake export VM that always reports success, so this widget test doesn't
// depend on PDF validity or platform specifics.
bool exported = false;
class _FakePdfExportViewModel extends PdfExportViewModel {
_FakePdfExportViewModel(Ref ref)
: super(ref, savePathPicker: () async => 'C:/tmp/output.pdf');
@override
Future<bool> exportToPath({
required String outputPath,
required Size uiPageSize,
required Uint8List? signatureImageBytes,
double targetDpi = 144.0,
}) async {
exported = true;
return true;
}
}
void main() {
testWidgets('Save uses file selector (via provider) and injected exporter', (
tester,
@ -55,7 +35,10 @@ void main() {
(ref) => PdfViewModel(ref, useMockViewer: true),
),
pdfExportViewModelProvider.overrideWith(
(ref) => _FakePdfExportViewModel(ref),
(ref) => PdfExportViewModel(
ref,
savePathPicker: () async => 'C:/tmp/output.pdf',
),
),
],
child: MaterialApp(
@ -64,7 +47,7 @@ void main() {
home: PdfSignatureHomePage(
onPickPdf: () async {},
onClosePdf: () {},
currentFile: XFile(''),
currentFile: fs.XFile(''),
),
),
),
@ -74,10 +57,10 @@ void main() {
// Trigger save directly (mark toggle no longer required)
await tester.tap(find.byKey(const Key('btn_save_pdf')));
// Pump a bit to allow async export flow to run.
await tester.pump(const Duration(milliseconds: 100));
await tester.pump(const Duration(milliseconds: 200));
// Basic assertion: export was invoked
expect(exported, isTrue);
await tester.pumpAndSettle();
// Expect success UI (localized)
expect(find.textContaining('Saved:'), findsOneWidget);
// Basic assertion: a save flow completed and snackbar showed
});
}

View File

@ -1,5 +1,5 @@
import 'dart:typed_data';
import 'package:cross_file/cross_file.dart';
import 'package:file_selector/file_selector.dart' as fs;
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
@ -36,7 +36,7 @@ Future<void> pumpWithOpenPdf(WidgetTester tester) async {
home: PdfSignatureHomePage(
onPickPdf: () async {},
onClosePdf: () {},
currentFile: XFile(''),
currentFile: fs.XFile(''),
),
),
),
@ -413,7 +413,7 @@ Future<void> pumpWithOpenPdfAndSig(WidgetTester tester) async {
home: PdfSignatureHomePage(
onPickPdf: () async {},
onClosePdf: () {},
currentFile: XFile(''),
currentFile: fs.XFile(''),
),
),
),

View File

@ -1,4 +1,4 @@
import 'package:cross_file/cross_file.dart';
import 'package:file_selector/file_selector.dart' as fs;
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
@ -38,7 +38,7 @@ void main() {
home: PdfSignatureHomePage(
onPickPdf: () async {},
onClosePdf: () {},
currentFile: XFile(''),
currentFile: fs.XFile(''),
),
),
),

View File

@ -12,15 +12,7 @@ import 'dart:io';
/// --reporter=compact
/// --pattern=*.dart (all files in integration_test/)
Future<int> main(List<String> args) async {
// Default device depends on host OS for a better out-of-the-box experience.
String device =
Platform.isWindows
? 'windows'
: Platform.isMacOS
? 'macos'
: Platform.isLinux
? 'linux'
: 'chrome';
String device = 'linux';
String reporter = 'compact';
String pattern = '*.dart';
@ -92,34 +84,16 @@ Future<int> main(List<String> args) async {
return 3;
}
// Normalize and map device aliases (helpful on Windows/macOS)
device = _normalizedDeviceId(device);
// Preflight: ensure `flutter` is invokable in this environment.
final flutterOk = await _checkFlutterAvailable();
if (!flutterOk) {
stderr.writeln(
'Could not execute `flutter`. Ensure Flutter is installed and on PATH.',
);
return 4;
}
stdout.writeln(
'Running ${selected.length} integration test file(s) sequentially on device: $device...',
'Running ${selected.length} integration test file(s) sequentially...',
);
final results = <String, int>{};
for (final f in selected) {
// Convert to forward slashes for tool compatibility across platforms.
final rel = f.path.replaceAll('\\', '/');
final rel = f.path;
stdout.writeln('\n=== Running: $rel ===');
final args = <String>['test', rel, '-d', device, '-r', reporter];
stdout.writeln('> flutter ${args.join(' ')}');
final proc = await Process.start(
'flutter',
args,
runInShell: Platform.isWindows, // ensures flutter.bat resolves on Windows
);
final proc = await Process.start('flutter', args);
// Pipe output live
unawaited(proc.stdout.transform(utf8.decoder).forEach(stdout.write));
unawaited(proc.stderr.transform(utf8.decoder).forEach(stderr.write));
@ -130,12 +104,8 @@ Future<int> main(List<String> args) async {
} else {
stderr.writeln('=== FAILED (exit $code): $rel ===');
}
// Small pause between launches to let desktop/device settle (slightly longer for desktop)
await Future<void>.delayed(
Platform.isWindows || Platform.isMacOS || Platform.isLinux
? const Duration(milliseconds: 1200)
: const Duration(milliseconds: 300),
);
// Small pause between launches to let desktop/device settle
await Future<void>.delayed(const Duration(milliseconds: 300));
}
stdout.writeln('\nSummary:');
@ -148,38 +118,3 @@ Future<int> main(List<String> args) async {
return failures == 0 ? 0 : 1;
}
String _normalizedDeviceId(String input) {
final lower = input.toLowerCase();
switch (lower) {
case 'win':
case 'windows':
case 'windows-desktop':
return 'windows';
case 'mac':
case 'macos':
case 'darwin':
return 'macos';
case 'linux':
case 'gnu/linux':
return 'linux';
case 'web':
case 'chrome':
case 'browser':
return 'chrome';
default:
return input; // assume caller provided a concrete device id
}
}
Future<bool> _checkFlutterAvailable() async {
try {
final result = await Process.run('flutter', const [
'--version',
'--suppress-analytics',
], runInShell: Platform.isWindows);
return result.exitCode == 0;
} catch (_) {
return false;
}
}