Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lohanidamodar committed Jan 4, 2022
1 parent e9b2aea commit c171b32
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static void registerWith(@NonNull FlutterEngine flutterEngine) {
try {
flutterEngine.getPlugins().add(new io.flutter.plugins.pathprovider.PathProviderPlugin());
} catch(Exception e) {
Log.e(TAG, "Error registering plugin path_provider, io.flutter.plugins.pathprovider.PathProviderPlugin", e);
Log.e(TAG, "Error registering plugin path_provider_android, io.flutter.plugins.pathprovider.PathProviderPlugin", e);
}
try {
flutterEngine.getPlugins().add(new com.tekartik.sqflite.SqflitePlugin());
Expand Down
10 changes: 5 additions & 5 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ PODS:
- FMDB (2.7.5):
- FMDB/standard (= 2.7.5)
- FMDB/standard (2.7.5)
- path_provider (0.0.1):
- path_provider_ios (0.0.1):
- Flutter
- sqflite (0.0.2):
- Flutter
Expand All @@ -14,7 +14,7 @@ PODS:
DEPENDENCIES:
- advance_pdf_viewer (from `.symlinks/plugins/advance_pdf_viewer/ios`)
- Flutter (from `Flutter`)
- path_provider (from `.symlinks/plugins/path_provider/ios`)
- path_provider_ios (from `.symlinks/plugins/path_provider_ios/ios`)
- sqflite (from `.symlinks/plugins/sqflite/ios`)

SPEC REPOS:
Expand All @@ -26,16 +26,16 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/advance_pdf_viewer/ios"
Flutter:
:path: Flutter
path_provider:
:path: ".symlinks/plugins/path_provider/ios"
path_provider_ios:
:path: ".symlinks/plugins/path_provider_ios/ios"
sqflite:
:path: ".symlinks/plugins/sqflite/ios"

SPEC CHECKSUMS:
advance_pdf_viewer: 5c832f382b4ca84fe735f893b7e91aa830c27d7b
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a
path_provider: abfe2b5c733d04e238b0d8691db0cfd63a27a93c
path_provider_ios: 7d7ce634493af4477d156294792024ec3485acd5
sqflite: 6d358c025f5b867b29ed92fc697fd34924e11904

PODFILE CHECKSUM: 8e679eca47255a8ca8067c4c67aab20e64cb974d
Expand Down
151 changes: 76 additions & 75 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:flutter/material.dart';
import 'package:advance_pdf_viewer/advance_pdf_viewer.dart';

void main() => runApp(MyApp());
void main() => runApp(MaterialApp(
home: MyApp(),
));

class MyApp extends StatefulWidget {
@override
Expand Down Expand Up @@ -43,86 +45,85 @@ class _MyAppState extends State<MyApp> {
document = await PDFDocument.fromAsset('assets/sample.pdf');
}
setState(() => _isLoading = false);
Navigator.pop(context);
}

@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
drawer: Drawer(
child: Column(
children: <Widget>[
SizedBox(height: 36),
ListTile(
title: Text('Load from Assets'),
onTap: () {
changePDF(1);
},
),
ListTile(
title: Text('Load from URL'),
onTap: () {
changePDF(2);
},
),
ListTile(
title: Text('Restore default'),
onTap: () {
changePDF(3);
},
),
],
),
),
appBar: AppBar(
title: const Text('FlutterPluginPDFViewer'),
return Scaffold(
drawer: Drawer(
child: Column(
children: <Widget>[
SizedBox(height: 36),
ListTile(
title: Text('Load from Assets'),
onTap: () {
changePDF(1);
},
),
ListTile(
title: Text('Load from URL'),
onTap: () {
changePDF(2);
},
),
ListTile(
title: Text('Restore default'),
onTap: () {
changePDF(3);
},
),
],
),
body: Center(
child: _isLoading
? Center(child: CircularProgressIndicator())
: PDFViewer(
document: document,
zoomSteps: 1,
//uncomment below line to preload all pages
// lazyLoad: false,
// uncomment below line to scroll vertically
// scrollDirection: Axis.vertical,
),
appBar: AppBar(
title: const Text('FlutterPluginPDFViewer'),
),
body: Center(
child: _isLoading
? Center(child: CircularProgressIndicator())
: PDFViewer(
document: document,
zoomSteps: 1,
//uncomment below line to preload all pages
// lazyLoad: false,
// uncomment below line to scroll vertically
// scrollDirection: Axis.vertical,

//uncomment below code to replace bottom navigation with your own
/* navigationBuilder:
(context, page, totalPages, jumpToPage, animateToPage) {
return ButtonBar(
alignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
IconButton(
icon: Icon(Icons.first_page),
onPressed: () {
jumpToPage()(page: 0);
},
),
IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {
animateToPage(page: page - 2);
},
),
IconButton(
icon: Icon(Icons.arrow_forward),
onPressed: () {
animateToPage(page: page);
},
),
IconButton(
icon: Icon(Icons.last_page),
onPressed: () {
jumpToPage(page: totalPages - 1);
},
),
],
);
}, */
),
),
//uncomment below code to replace bottom navigation with your own
/* navigationBuilder:
(context, page, totalPages, jumpToPage, animateToPage) {
return ButtonBar(
alignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
IconButton(
icon: Icon(Icons.first_page),
onPressed: () {
jumpToPage()(page: 0);
},
),
IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {
animateToPage(page: page - 2);
},
),
IconButton(
icon: Icon(Icons.arrow_forward),
onPressed: () {
animateToPage(page: page);
},
),
IconButton(
icon: Icon(Icons.last_page),
onPressed: () {
jumpToPage(page: totalPages - 1);
},
),
],
);
}, */
),
),
);
}
Expand Down
52 changes: 19 additions & 33 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ packages:
relative: true
source: path
version: "2.0.1"
archive:
dependency: transitive
description:
name: archive
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.2"
async:
dependency: transitive
description:
Expand Down Expand Up @@ -103,7 +96,7 @@ packages:
name: flutter_cache_manager
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.2"
version: "3.3.0"
flutter_test:
dependency: "direct dev"
description: flutter
Expand All @@ -123,13 +116,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.0"
image:
dependency: transitive
description:
name: image
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.2"
infinite_listview:
dependency: transitive
description:
Expand Down Expand Up @@ -171,14 +157,28 @@ packages:
name: path_provider
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
version: "2.0.8"
path_provider_android:
dependency: transitive
description:
name: path_provider_android
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.11"
path_provider_ios:
dependency: transitive
description:
name: path_provider_ios
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.7"
path_provider_linux:
dependency: transitive
description:
name: path_provider_linux
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "2.1.2"
path_provider_macos:
dependency: transitive
description:
Expand All @@ -199,21 +199,14 @@ packages:
name: path_provider_windows
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "2.0.4"
pedantic:
dependency: transitive
description:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.11.0"
petitparser:
dependency: transitive
description:
name: petitparser
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.2"
platform:
dependency: transitive
description:
Expand Down Expand Up @@ -345,13 +338,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.0"
xml:
dependency: transitive
description:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "5.0.2"
sdks:
dart: ">=2.14.0 <3.0.0"
flutter: ">=1.24.0-10"
flutter: ">=2.5.0"
12 changes: 11 additions & 1 deletion lib/src/document.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class PDFDocument {
File file;
try {
final dir = await getApplicationDocumentsDirectory();
file = File("${dir.path}/file.pdf");
file = File("${dir.path}/${DateTime.now().millisecondsSinceEpoch}.pdf");
final data = await rootBundle.load(asset);
final bytes = data.buffer.asUint8List();
await file.writeAsBytes(bytes, flush: true);
Expand Down Expand Up @@ -144,4 +144,14 @@ class PDFDocument {
);
}).asStream() as Stream<PDFPage?>;
}

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is PDFDocument &&
runtimeType == other.runtimeType &&
_filePath == other._filePath;

@override
int get hashCode => Object.hash(_filePath, count);
}
2 changes: 1 addition & 1 deletion lib/src/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class _PDFPageState extends State<PDFPage> {
resolver.addListener(
ImageStreamListener(
(imgInfo, alreadyPainted) {
if (!alreadyPainted) setState(() {});
if (!alreadyPainted && mounted) setState(() {});
},
),
);
Expand Down
7 changes: 3 additions & 4 deletions lib/src/viewer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,20 @@ class _PDFViewerState extends State<PDFViewer> {
if (!widget.lazyLoad) _preloadPages();
}

@override
@override
void didUpdateWidget(PDFViewer oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.document.filePath != widget.document.filePath) {
_initialize();
_isLoading = true;
_loadPage();
}
}

@override
void didChangeDependencies() {
super.didChangeDependencies();
_pageNumber = _pageController.initialPage + 1;
_isLoading = true;
_pages = List.filled(widget.document.count, null);
_initialize();
_loadPage();
}

Expand Down
Loading

0 comments on commit c171b32

Please sign in to comment.