diff --git a/example/lib/main.dart b/example/lib/main.dart index 74c62613..ad67723f 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -163,9 +163,9 @@ class _MyAppState extends State { } class PDFScreen extends StatefulWidget { - final String path; + final String? path; - PDFScreen({Key key, this.path}) : super(key: key); + PDFScreen({Key? key, this.path}) : super(key: key); _PDFScreenState createState() => _PDFScreenState(); } @@ -173,8 +173,8 @@ class PDFScreen extends StatefulWidget { class _PDFScreenState extends State with WidgetsBindingObserver { final Completer _controller = Completer(); - int pages = 0; - int currentPage = 0; + int? pages = 0; + int? currentPage = 0; bool isReady = false; String errorMessage = ''; @@ -199,7 +199,7 @@ class _PDFScreenState extends State with WidgetsBindingObserver { autoSpacing: false, pageFling: true, pageSnap: true, - defaultPage: currentPage, + defaultPage: currentPage!, fitPolicy: FitPolicy.BOTH, preventLinkNavigation: false, // if set to true the link is handled in flutter @@ -224,10 +224,10 @@ class _PDFScreenState extends State with WidgetsBindingObserver { onViewCreated: (PDFViewController pdfViewController) { _controller.complete(pdfViewController); }, - onLinkHandler: (String uri) { + onLinkHandler: (String? uri) { print('goto uri: $uri'); }, - onPageChanged: (int page, int total) { + onPageChanged: (int? page, int? total) { print('page change: $page/$total'); setState(() { currentPage = page; @@ -250,9 +250,9 @@ class _PDFScreenState extends State with WidgetsBindingObserver { builder: (context, AsyncSnapshot snapshot) { if (snapshot.hasData) { return FloatingActionButton.extended( - label: Text("Go to ${pages ~/ 2}"), + label: Text("Go to ${pages! ~/ 2}"), onPressed: () async { - await snapshot.data.setPage(pages ~/ 2); + await snapshot.data!.setPage(pages! ~/ 2); }, ); } diff --git a/example/pubspec.lock b/example/pubspec.lock index 7b9af710..5ec19c3f 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,63 +7,70 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0-nullsafety.1" + version: "2.5.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.3" + version: "1.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0-nullsafety.3" + version: "1.15.0" cupertino_icons: dependency: "direct main" description: name: cupertino_icons url: "https://pub.dartlang.org" source: hosted - version: "0.1.3" + version: "1.0.2" fake_async: dependency: transitive description: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" + ffi: + dependency: transitive + description: + name: ffi + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" file: dependency: transitive description: name: file url: "https://pub.dartlang.org" source: hosted - version: "5.2.1" + version: "6.1.0" flutter: dependency: "direct main" description: flutter @@ -81,83 +88,83 @@ packages: description: flutter source: sdk version: "0.0.0" - intl: - dependency: transitive - description: - name: intl - url: "https://pub.dartlang.org" - source: hosted - version: "0.16.1" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10-nullsafety.1" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.1" + version: "1.8.0" path_provider: dependency: "direct main" description: name: path_provider url: "https://pub.dartlang.org" source: hosted - version: "1.6.11" + version: "2.0.1" path_provider_linux: dependency: transitive description: name: path_provider_linux url: "https://pub.dartlang.org" source: hosted - version: "0.0.1+2" + version: "2.0.0" path_provider_macos: dependency: transitive description: name: path_provider_macos url: "https://pub.dartlang.org" source: hosted - version: "0.0.4+3" + version: "2.0.0" path_provider_platform_interface: dependency: transitive description: name: path_provider_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.2" + version: "2.0.1" + path_provider_windows: + dependency: transitive + description: + name: path_provider_windows + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" platform: dependency: transitive description: name: platform url: "https://pub.dartlang.org" source: hosted - version: "2.2.1" + version: "3.0.0" plugin_platform_interface: dependency: transitive description: name: plugin_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.2" + version: "2.0.0" process: dependency: transitive description: name: process url: "https://pub.dartlang.org" source: hosted - version: "3.0.13" + version: "4.1.0" sky_engine: dependency: transitive description: flutter @@ -169,63 +176,70 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.2" + version: "1.8.0" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.10.0-nullsafety.1" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19-nullsafety.2" + version: "0.2.19" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.3" + version: "2.1.0" + win32: + dependency: transitive + description: + name: win32 + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" xdg_directories: dependency: transitive description: name: xdg_directories url: "https://pub.dartlang.org" source: hosted - version: "0.1.0" + version: "0.2.0" sdks: - dart: ">=2.10.0-110 <2.11.0" - flutter: ">=1.12.13+hotfix.5 <2.0.0" + dart: ">=2.12.0 <3.0.0" + flutter: ">=1.20.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 95eec568..082b360c 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -4,7 +4,7 @@ description: Demonstrates how to use the flutter_pdfview plugin. publish_to: "none" environment: - sdk: ">=2.1.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' dependencies: flutter: @@ -12,8 +12,8 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^0.1.2 - path_provider: ^1.2.0 + cupertino_icons: ^1.0.2 + path_provider: ^2.0.1 dev_dependencies: flutter_test: diff --git a/example/test/widget_test.dart b/example/test/widget_test.dart index 92c3bfde..3aad454f 100644 --- a/example/test/widget_test.dart +++ b/example/test/widget_test.dart @@ -19,7 +19,7 @@ void main() { expect( find.byWidgetPredicate( (Widget widget) => - widget is Text && widget.data.startsWith('Running on:'), + widget is Text && widget.data!.startsWith('Running on:'), ), findsOneWidget, ); diff --git a/lib/flutter_pdfview.dart b/lib/flutter_pdfview.dart index e2016b4c..76c96916 100644 --- a/lib/flutter_pdfview.dart +++ b/lib/flutter_pdfview.dart @@ -7,17 +7,17 @@ import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; typedef PDFViewCreatedCallback = void Function(PDFViewController controller); -typedef RenderCallback = void Function(int pages); -typedef PageChangedCallback = void Function(int page, int total); +typedef RenderCallback = void Function(int? pages); +typedef PageChangedCallback = void Function(int? page, int? total); typedef ErrorCallback = void Function(dynamic error); -typedef PageErrorCallback = void Function(int page, dynamic error); -typedef LinkHandlerCallback = void Function(String uri); +typedef PageErrorCallback = void Function(int? page, dynamic error); +typedef LinkHandlerCallback = void Function(String? uri); enum FitPolicy { WIDTH, HEIGHT, BOTH } class PDFView extends StatefulWidget { const PDFView({ - Key key, + Key? key, this.filePath, this.pdfData, this.onViewCreated, @@ -45,12 +45,12 @@ class PDFView extends StatefulWidget { _PDFViewState createState() => _PDFViewState(); /// If not null invoked once the web view is created. - final PDFViewCreatedCallback onViewCreated; - final RenderCallback onRender; - final PageChangedCallback onPageChanged; - final ErrorCallback onError; - final PageErrorCallback onPageError; - final LinkHandlerCallback onLinkHandler; + final PDFViewCreatedCallback? onViewCreated; + final RenderCallback? onRender; + final PageChangedCallback? onPageChanged; + final ErrorCallback? onError; + final PageErrorCallback? onPageError; + final LinkHandlerCallback? onLinkHandler; /// Which gestures should be consumed by the pdf view. /// @@ -61,15 +61,15 @@ class PDFView extends StatefulWidget { /// /// When this set is empty or null, the pdf view will only handle pointer events for gestures that /// were not claimed by any other gesture recognizer. - final Set> gestureRecognizers; + final Set>? gestureRecognizers; /// The initial URL to load. - final String filePath; - final Uint8List pdfData; + final String? filePath; + final Uint8List? pdfData; final bool enableSwipe; final bool swipeHorizontal; - final String password; + final String? password; final bool nightMode; final bool autoSpacing; final bool pageFling; @@ -110,7 +110,7 @@ class _PDFViewState extends State { final PDFViewController controller = PDFViewController._(id, widget); _controller.complete(controller); if (widget.onViewCreated != null) { - widget.onViewCreated(controller); + widget.onViewCreated!(controller); } } @@ -137,10 +137,10 @@ class _CreationParams { ); } - final String filePath; - final Uint8List pdfData; + final String? filePath; + final Uint8List? pdfData; - final _PDFViewSettings settings; + final _PDFViewSettings? settings; Map toMap() { Map params = { @@ -148,7 +148,7 @@ class _CreationParams { 'pdfData': pdfData, }; - params.addAll(settings.toMap()); + params.addAll(settings!.toMap()); return params; } @@ -182,17 +182,17 @@ class _PDFViewSettings { preventLinkNavigation: widget.preventLinkNavigation); } - final bool enableSwipe; - final bool swipeHorizontal; - final String password; - final bool nightMode; - final bool autoSpacing; - final bool pageFling; - final bool pageSnap; - final int defaultPage; - final FitPolicy fitPolicy; - final bool fitEachPage; - final bool preventLinkNavigation; + final bool? enableSwipe; + final bool? swipeHorizontal; + final String? password; + final bool? nightMode; + final bool? autoSpacing; + final bool? pageFling; + final bool? pageSnap; + final int? defaultPage; + final FitPolicy? fitPolicy; + final bool? fitEachPage; + final bool? preventLinkNavigation; Map toMap() { return { @@ -239,40 +239,40 @@ class PDFViewController { final MethodChannel _channel; - _PDFViewSettings _settings; + late _PDFViewSettings _settings; PDFView _widget; - Future _onMethodCall(MethodCall call) async { + Future _onMethodCall(MethodCall call) async { switch (call.method) { case 'onRender': if (_widget.onRender != null) { - _widget.onRender(call.arguments['pages']); + _widget.onRender!(call.arguments['pages']); } return null; case 'onPageChanged': if (_widget.onPageChanged != null) { - _widget.onPageChanged( + _widget.onPageChanged!( call.arguments['page'], call.arguments['total']); } return null; case 'onError': if (_widget.onError != null) { - _widget.onError(call.arguments['error']); + _widget.onError!(call.arguments['error']); } return null; case 'onPageError': if (_widget.onPageError != null) { - _widget.onPageError(call.arguments['page'], call.arguments['error']); + _widget.onPageError!(call.arguments['page'], call.arguments['error']); } return null; case 'onLinkHandler': if (_widget.onLinkHandler != null) { - _widget.onLinkHandler(call.arguments); + _widget.onLinkHandler!(call.arguments); } return null; @@ -281,18 +281,18 @@ class PDFViewController { '${call.method} was invoked but has no handler'); } - Future getPageCount() async { - final int pageCount = await _channel.invokeMethod('pageCount'); + Future getPageCount() async { + final int? pageCount = await _channel.invokeMethod('pageCount'); return pageCount; } - Future getCurrentPage() async { - final int currentPage = await _channel.invokeMethod('currentPage'); + Future getCurrentPage() async { + final int? currentPage = await _channel.invokeMethod('currentPage'); return currentPage; } - Future setPage(int page) async { - final bool isSet = await _channel.invokeMethod('setPage', { + Future setPage(int page) async { + final bool? isSet = await _channel.invokeMethod('setPage', { 'page': page, }); return isSet; diff --git a/pubspec.lock b/pubspec.lock index 51836182..78f8dced 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,49 +7,49 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0-nullsafety.1" + version: "2.5.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.3" + version: "1.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0-nullsafety.3" + version: "1.15.0" fake_async: dependency: transitive description: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -66,21 +66,21 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10-nullsafety.1" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.1" + version: "1.8.0" sky_engine: dependency: transitive description: flutter @@ -92,56 +92,56 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.2" + version: "1.8.0" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.10.0-nullsafety.1" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19-nullsafety.2" + version: "0.2.19" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.3" + version: "2.1.0" sdks: - dart: ">=2.10.0-110 <2.11.0" + dart: ">=2.12.0 <3.0.0" flutter: ">=1.12.13+hotfix.5" diff --git a/pubspec.yaml b/pubspec.yaml index f86cd5a3..06c703f5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ version: 1.0.4 homepage: /~https://github.com/endigo/flutter_pdfview environment: - sdk: ">=2.1.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' flutter: ">=1.12.13+hotfix.5" dependencies: