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
59 changes: 59 additions & 0 deletions example/test/viewer_test.dart
Original file line number Diff line number Diff line change
@@ -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<MethodCall> 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<MethodCall> logPath;

channelPath.setMockMethodCallHandler((MethodCall methodCall) async {
logPath.add(methodCall);
switch (methodCall.method) {
case 'getApplicationDocumentsDirectory':
return Directory.current.path;
default:
return null;
}
});

setUp(() {
logPath = <MethodCall>[];
log = <MethodCall>[];
});

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);
});
}
2 changes: 1 addition & 1 deletion lib/src/document.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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!');
}
Expand Down