diff --git a/example/test/viewer_test.dart b/example/test/viewer_test.dart new file mode 100644 index 0000000..31c2bcc --- /dev/null +++ b/example/test/viewer_test.dart @@ -0,0 +1,59 @@ +import 'dart:io'; + +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_plugin_pdf_viewer/flutter_plugin_pdf_viewer.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + const MethodChannel channel = MethodChannel('flutter_plugin_pdf_viewer'); + List log; + + channel.setMockMethodCallHandler((MethodCall methodCall) async { + log.add(methodCall); + switch (methodCall.method) { + case 'getNumberOfPages': + return '5'; + default: + return null; + } + }); + + TestWidgetsFlutterBinding.ensureInitialized(); + + const MethodChannel channelPath = + MethodChannel('plugins.flutter.io/path_provider'); + List logPath; + + channelPath.setMockMethodCallHandler((MethodCall methodCall) async { + logPath.add(methodCall); + switch (methodCall.method) { + case 'getApplicationDocumentsDirectory': + return Directory.current.path; + default: + return null; + } + }); + + setUp(() { + logPath = []; + log = []; + }); + + Widget createWidgetForTesting({Widget child}) { + return MaterialApp( + home: child, + ); + } + + testWidgets('PDFViewer with BottomAppBar', (WidgetTester tester) async { + PDFDocument _document = await PDFDocument.fromAsset('assets/sample2.pdf'); + await tester.pumpWidget( + createWidgetForTesting(child: PDFViewer(document: _document))); + + var bottomBar = find.byType(BottomAppBar); + expect(bottomBar, findsOneWidget); + }); +} diff --git a/lib/src/document.dart b/lib/src/document.dart index 4844297..5825891 100644 --- a/lib/src/document.dart +++ b/lib/src/document.dart @@ -59,7 +59,7 @@ class PDFDocument { file = File("${dir.path}/file.pdf"); var data = await rootBundle.load(asset); var bytes = data.buffer.asUint8List(); - await file.writeAsBytes(bytes, flush: true); + file.writeAsBytesSync(bytes, flush: true); } catch (e) { throw Exception('Error parsing asset file!'); }