Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions lib/src/document.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class PDFDocument {
try {
var pageCount = await _channel.invokeMethod('getNumberOfPages',
{'filePath': file.path, 'clearCacheDir': clearPreviewCache});
document.count = document.count = int.parse(pageCount);
document.count = document.count = _safeParseInt(pageCount);
} catch (e) {
throw Exception('Error reading PDF!');
}
Expand Down Expand Up @@ -62,7 +62,7 @@ class PDFDocument {
try {
var pageCount = await _channel.invokeMethod('getNumberOfPages',
{'filePath': f.path, 'clearCacheDir': clearPreviewCache});
document.count = document.count = int.parse(pageCount);
document.count = document.count = _safeParseInt(pageCount);
} catch (e) {
throw Exception('Error reading PDF!');
}
Expand Down Expand Up @@ -141,7 +141,7 @@ class PDFDocument {
try {
var pageCount = await _channel.invokeMethod('getNumberOfPages',
{'filePath': file.path, 'clearCacheDir': clearPreviewCache});
document.count = document.count = int.parse(pageCount);
document.count = document.count = _safeParseInt(pageCount);
} catch (e) {
throw Exception('Error reading PDF!');
}
Expand Down Expand Up @@ -221,4 +221,15 @@ class PDFDocument {
);
}).asStream() as Stream<PDFPage?>;
}
static int _safeParseInt(String input) {
const easternArabic = ['٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩'];
const persian = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
const western = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];

for (int i = 0; i < 10; i++) {
input = input.replaceAll(easternArabic[i], western[i]);
input = input.replaceAll(persian[i], western[i]);
}
return int.parse(input);
}
}
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ version: 1.0.8
homepage: https://github.com/kaichii/pdf_viewer

environment:
sdk: '>=3.3.1 <4.0.0'
sdk: '>=2.12.0 <4.0.0'
flutter: '>=1.20.0'

dependencies:
flutter:
Expand Down