diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f1baf0..e6a9ada 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ # Changelog +# 2.0.0 +* Null safety upgrade +* Fixed some issues +* new `numberPickerConfirmWidget` ## 1.2.2 * fix error with single page pdf diff --git a/README.md b/README.md index e294b46..24be8e1 100644 --- a/README.md +++ b/README.md @@ -44,16 +44,16 @@ PDFPage pageOne = await doc.get(page: _number); #### Pre-built viewer Use the pre-built PDF Viewer ``` -@override + @override Widget build(BuildContext context) { - Scaffold( - appBar: AppBar( - title: Text('Example'), - ), - body: Center( - child: _isLoading - ? Center(child: CircularProgressIndicator()) - : PDFViewer(document: document)), + return Scaffold( + appBar: AppBar( + title: Text('Example'), + ), + body: Center( + child: _isLoading + ? Center(child: CircularProgressIndicator()) + : PDFViewer(document: document)), ); } ``` diff --git a/example/pubspec.lock b/example/pubspec.lock index 97f5833..4702643 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,63 +7,63 @@ packages: path: ".." relative: true source: path - version: "1.2.2" + version: "2.0.0" + archive: + dependency: transitive + description: + name: archive + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.2" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0-nullsafety.1" + version: "2.6.1" 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" - convert: - dependency: transitive - description: - name: convert - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.1" + version: "1.15.0" crypto: dependency: transitive description: name: crypto url: "https://pub.dartlang.org" source: hosted - version: "2.1.4" + version: "3.0.0" cupertino_icons: dependency: "direct main" description: @@ -77,21 +77,21 @@ packages: 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: "0.1.3" + 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 @@ -103,7 +103,7 @@ packages: name: flutter_cache_manager url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "3.0.2" flutter_test: dependency: "direct dev" description: flutter @@ -115,126 +115,133 @@ packages: name: http url: "https://pub.dartlang.org" source: hosted - version: "0.12.2" + version: "0.13.1" http_parser: dependency: transitive description: name: http_parser url: "https://pub.dartlang.org" source: hosted - version: "3.1.3" - infinite_listview: + version: "4.0.0" + image: dependency: transitive description: - name: infinite_listview + name: image url: "https://pub.dartlang.org" source: hosted - version: "1.0.1+1" - intl: + version: "3.0.2" + infinite_listview: dependency: transitive description: - name: intl + name: infinite_listview url: "https://pub.dartlang.org" source: hosted - version: "0.16.1" + version: "1.1.0" 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" numberpicker: dependency: transitive description: name: numberpicker url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "2.1.1" 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: transitive description: name: path_provider url: "https://pub.dartlang.org" source: hosted - version: "1.6.24" + 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" + 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.4" + version: "2.0.1" path_provider_windows: dependency: transitive description: name: path_provider_windows url: "https://pub.dartlang.org" source: hosted - version: "0.0.4+3" + version: "2.0.0" pedantic: dependency: transitive description: name: pedantic url: "https://pub.dartlang.org" source: hosted - version: "1.9.0" + 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: 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.2.1" rxdart: dependency: transitive description: name: rxdart url: "https://pub.dartlang.org" source: hosted - version: "0.24.1" + version: "0.26.0" sky_engine: dependency: transitive description: flutter @@ -246,98 +253,105 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.2" + version: "1.8.1" sqflite: dependency: transitive description: name: sqflite url: "https://pub.dartlang.org" source: hosted - version: "1.3.1" + version: "2.0.0+3" sqflite_common: dependency: transitive description: name: sqflite_common url: "https://pub.dartlang.org" source: hosted - version: "1.0.2+1" + version: "2.0.0+2" 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" synchronized: dependency: transitive description: name: synchronized url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "3.0.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.3.0" 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" uuid: dependency: transitive description: name: uuid url: "https://pub.dartlang.org" source: hosted - version: "2.2.0" + version: "3.0.3" 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: "1.7.4" + version: "2.0.5" xdg_directories: dependency: transitive description: name: xdg_directories url: "https://pub.dartlang.org" source: hosted - version: "0.1.0" + version: "0.2.0" + xml: + dependency: transitive + description: + name: xml + url: "https://pub.dartlang.org" + source: hosted + version: "5.0.2" sdks: - dart: ">=2.10.0-110 <2.11.0" - flutter: ">=1.17.0 <2.0.0" + dart: ">=2.12.0 <3.0.0" + flutter: ">=1.24.0-10" diff --git a/lib/src/document.dart b/lib/src/document.dart index 9a9fb8a..d159e72 100644 --- a/lib/src/document.dart +++ b/lib/src/document.dart @@ -10,8 +10,8 @@ class PDFDocument { static const MethodChannel _channel = const MethodChannel('flutter_plugin_pdf_viewer'); - String _filePath; - int count; + String? _filePath; + late int count; List _pages = []; bool _preloaded = false; @@ -22,8 +22,8 @@ class PDFDocument { PDFDocument document = PDFDocument(); document._filePath = file.path; try { - var pageCount = - await _channel.invokeMethod('getNumberOfPages', {'filePath': file.path}); + var pageCount = await _channel + .invokeMethod('getNumberOfPages', {'filePath': file.path}); document.count = document.count = int.parse(pageCount); } catch (e) { throw Exception('Error reading PDF!'); @@ -35,10 +35,10 @@ class PDFDocument { /// File is saved in cache /// [String url] url of the pdf file /// [Map fromURL(String url, - {Map headers, CacheManager cacheManager}) async { + {Map? headers, CacheManager? cacheManager}) async { // Download into cache File f = await (cacheManager ?? DefaultCacheManager()) .getSingleFile(url, headers: headers); @@ -85,11 +85,11 @@ class PDFDocument { /// [page] defaults to `1` and must be equal or above it Future get({ int page = 1, - final Function(double) onZoomChanged, - final int zoomSteps, - final double minScale, - final double maxScale, - final double panLimit, + final Function(double)? onZoomChanged, + final int? zoomSteps, + final double? minScale, + final double? maxScale, + final double? panLimit, }) async { assert(page > 0); if (_preloaded && _pages.isNotEmpty) return _pages[page - 1]; @@ -99,41 +99,41 @@ class PDFDocument { data, page, onZoomChanged: onZoomChanged, - zoomSteps: zoomSteps, - minScale: minScale, - maxScale: maxScale, - panLimit: panLimit, + zoomSteps: zoomSteps ?? 3, + minScale: minScale ?? 1.0, + maxScale: maxScale ?? 5.0, + panLimit: panLimit ?? 1.0, ); } Future preloadPages({ - final Function(double) onZoomChanged, - final int zoomSteps, - final double minScale, - final double maxScale, - final double panLimit, + final Function(double)? onZoomChanged, + final int? zoomSteps, + final double? minScale, + final double? maxScale, + final double? panLimit, }) async { int countvar = 1; - await Future.forEach(List(count), (i) async { + for (final _ in List.filled(count, null)) { final data = await _channel.invokeMethod( 'getPage', {'filePath': _filePath, 'pageNumber': countvar}); _pages.add(PDFPage( data, countvar, onZoomChanged: onZoomChanged, - zoomSteps: zoomSteps, - minScale: minScale, - maxScale: maxScale, - panLimit: panLimit, + zoomSteps: zoomSteps ?? 3, + minScale: minScale ?? 1.0, + maxScale: maxScale ?? 5.0, + panLimit: panLimit ?? 1.0, )); countvar++; - }); + } _preloaded = true; } // Stream all pages - Stream getAll({final Function(double) onZoomChanged}) { - return Future.forEach(List(count), (i) async { + Stream getAll({final Function(double)? onZoomChanged}) { + return Future.forEach(List.filled(count, null), (i) async { print(i); final data = await _channel .invokeMethod('getPage', {'filePath': _filePath, 'pageNumber': i}); @@ -142,6 +142,6 @@ class PDFDocument { 1, onZoomChanged: onZoomChanged, ); - }).asStream(); + }).asStream() as Stream; } } diff --git a/lib/src/page.dart b/lib/src/page.dart index 808ec0a..bc6c7df 100644 --- a/lib/src/page.dart +++ b/lib/src/page.dart @@ -1,10 +1,8 @@ import 'dart:io'; -import 'dart:ui'; import 'package:advance_pdf_viewer/src/zoomable_widget.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter/painting.dart'; - /// A class to represent PDF page /// [imgPath], path of the image (pdf page) /// [num], page number @@ -14,9 +12,9 @@ import 'package:flutter/painting.dart'; /// [maxScale] maximum zoom scale /// [panLimit] limit for pan class PDFPage extends StatefulWidget { - final String imgPath; + final String? imgPath; final int num; - final Function(double) onZoomChanged; + final Function(double)? onZoomChanged; final int zoomSteps; final double minScale; final double maxScale; @@ -36,7 +34,7 @@ class PDFPage extends StatefulWidget { } class _PDFPageState extends State { - ImageProvider provider; + late ImageProvider provider; @override void didChangeDependencies() { @@ -53,7 +51,7 @@ class _PDFPageState extends State { } _repaint() { - provider = FileImage(File(widget.imgPath)); + provider = FileImage(File(widget.imgPath!)); final resolver = provider.resolve(createLocalImageConfiguration(context)); resolver.addListener(ImageStreamListener((imgInfo, alreadyPainted) { if (!alreadyPainted) setState(() {}); @@ -66,10 +64,10 @@ class _PDFPageState extends State { decoration: null, child: ZoomableWidget( onZoomChanged: widget.onZoomChanged, - zoomSteps: widget.zoomSteps ?? 3, - minScale: widget.minScale ?? 1.0, - panLimit: widget.panLimit ?? 1.0, - maxScale: widget.maxScale ?? 5.0, + zoomSteps: widget.zoomSteps, + minScale: widget.minScale, + panLimit: widget.panLimit, + maxScale: widget.maxScale, child: Image(image: provider), )); } diff --git a/lib/src/page_picker.dart b/lib/src/page_picker.dart new file mode 100644 index 0000000..36013fe --- /dev/null +++ b/lib/src/page_picker.dart @@ -0,0 +1,49 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; +import 'package:numberpicker/numberpicker.dart'; + +class PagePicker extends StatefulWidget { + PagePicker({ + required this.title, + required this.maxValue, + required this.initialValue, + this.numberPickerConfirmWidget, + }); + + final String title; + final int? maxValue; + final int? initialValue; + final Widget? numberPickerConfirmWidget; + + @override + _PagePickerState createState() => _PagePickerState(); +} + +class _PagePickerState extends State { + int? _currentValue; + + @override + void initState() { + _currentValue = widget.initialValue; + super.initState(); + } + + @override + Widget build(BuildContext context) { + return AlertDialog( + title: Text(widget.title), + content: NumberPicker( + minValue: 1, + maxValue: widget.maxValue!, + value: _currentValue!, + onChanged: (value) => setState(() => _currentValue = value), + ), + actions: [ + TextButton( + child: widget.numberPickerConfirmWidget ?? Text('OK'), + onPressed: () => Navigator.of(context).pop(_currentValue), + ), + ], + ); + } +} diff --git a/lib/src/viewer.dart b/lib/src/viewer.dart index c2246e3..c1383a3 100644 --- a/lib/src/viewer.dart +++ b/lib/src/viewer.dart @@ -1,3 +1,4 @@ +import 'package:advance_pdf_viewer/src/page_picker.dart'; import 'package:flutter/material.dart'; import 'package:advance_pdf_viewer/advance_pdf_viewer.dart'; import 'package:numberpicker/numberpicker.dart'; @@ -25,44 +26,46 @@ enum IndicatorPosition { topLeft, topRight, bottomLeft, bottomRight } /// [maxScale] maximum zoom scale for pdf page /// [panLimit] pan limit for pdf page /// [onPageChanged] function called when page changes -/// +/// class PDFViewer extends StatefulWidget { final PDFDocument document; final Color indicatorText; final Color indicatorBackground; - final Color pickerButtonColor; - final Color pickerIconColor; + final Color? pickerButtonColor; + final Color? pickerIconColor; final IndicatorPosition indicatorPosition; + final Widget numberPickerConfirmWidget; final bool showIndicator; final bool showPicker; final bool showNavigation; final PDFViewerTooltip tooltip; final bool enableSwipeNavigation; - final Axis scrollDirection; + final Axis? scrollDirection; final bool lazyLoad; - final PageController controller; - final int zoomSteps; - final double minScale; - final double maxScale; - final double panLimit; - final ValueChanged onPageChanged; + final PageController? controller; + final int? zoomSteps; + final double? minScale; + final double? maxScale; + final double? panLimit; + final ValueChanged? onPageChanged; final Widget Function( BuildContext, - int pageNumber, - int totalPages, + int? pageNumber, + int? totalPages, void Function({int page}) jumpToPage, - void Function({int page}) animateToPage, - ) navigationBuilder; - final Widget progressIndicator; + void Function({int? page}) animateToPage, + )? navigationBuilder; + final Widget? progressIndicator; PDFViewer({ - Key key, - @required this.document, + Key? key, + required this.document, this.scrollDirection, this.lazyLoad = true, this.indicatorText = Colors.white, this.indicatorBackground = Colors.black54, + this.numberPickerConfirmWidget = const Text('OK'), this.showIndicator = true, this.showPicker = true, this.showNavigation = true, @@ -86,17 +89,17 @@ class PDFViewer extends StatefulWidget { class _PDFViewerState extends State { bool _isLoading = true; - int _pageNumber; + late int _pageNumber; bool _swipeEnabled = true; - List _pages; - PageController _pageController; + List? _pages; + late PageController _pageController; final Duration animationDuration = Duration(milliseconds: 200); final Curve animationCurve = Curves.easeIn; @override void initState() { super.initState(); - _pages = List(widget.document.count); + _pages = List.filled(widget.document.count, null); _pageController = widget.controller ?? PageController(); _pageNumber = _pageController.initialPage + 1; if (!widget.lazyLoad) @@ -114,7 +117,7 @@ class _PDFViewerState extends State { super.didChangeDependencies(); _pageNumber = _pageController.initialPage + 1; _isLoading = true; - _pages = List(widget.document.count); + _pages = List.filled(widget.document.count,null); // _loadAllPages(); _loadPage(); } @@ -137,7 +140,7 @@ class _PDFViewerState extends State { } _loadPage() async { - if (_pages[_pageNumber - 1] != null) return; + if (_pages![_pageNumber - 1] != null) return; setState(() { _isLoading = true; }); @@ -149,7 +152,7 @@ class _PDFViewerState extends State { maxScale: widget.maxScale, panLimit: widget.panLimit, ); - _pages[_pageNumber - 1] = data; + _pages![_pageNumber - 1] = data; if (mounted) { setState(() { _isLoading = false; @@ -157,12 +160,12 @@ class _PDFViewerState extends State { } } - _animateToPage({int page}) { + _animateToPage({int? page}) { _pageController.animateToPage(page != null ? page : _pageNumber - 1, duration: animationDuration, curve: animationCurve); } - _jumpToPage({int page}) { + _jumpToPage({int? page}) { _pageController.jumpToPage(page != null ? page : _pageNumber - 1); } @@ -200,14 +203,12 @@ class _PDFViewerState extends State { showDialog( context: context, builder: (BuildContext context) { - return NumberPickerDialog.integer( - title: Text(widget.tooltip.pick), - minValue: 1, - cancelWidget: Container(), + return PagePicker( + title: widget.tooltip.pick, maxValue: widget.document.count, - initialIntegerValue: _pageNumber, + initialValue: _pageNumber, ); - }).then((int value) { + }).then((int? value) { if (value != null) { _pageNumber = value; _jumpToPage(); @@ -235,12 +236,12 @@ class _PDFViewerState extends State { scrollDirection: widget.scrollDirection ?? Axis.horizontal, controller: _pageController, itemCount: _pages?.length ?? 0, - itemBuilder: (context, index) => _pages[index] == null + itemBuilder: (context, index) => _pages![index] == null ? Center( child: widget.progressIndicator ?? CircularProgressIndicator(), ) - : _pages[index], + : _pages![index]!, ), (widget.showIndicator && !_isLoading) ? _drawIndicator() @@ -264,7 +265,7 @@ class _PDFViewerState extends State { floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, bottomNavigationBar: (widget.showNavigation && widget.document.count > 1) ? widget.navigationBuilder != null - ? widget.navigationBuilder( + ? widget.navigationBuilder!( context, _pageNumber, widget.document.count, @@ -337,7 +338,9 @@ class _PDFViewerState extends State { ], ), ) - : Container(height: 0,), + : Container( + height: 0, + ), ); } } diff --git a/lib/src/zoomable_widget.dart b/lib/src/zoomable_widget.dart index ee13468..eb14c6b 100644 --- a/lib/src/zoomable_widget.dart +++ b/lib/src/zoomable_widget.dart @@ -5,7 +5,7 @@ import 'package:flutter/widgets.dart'; class ZoomableWidget extends StatefulWidget { ZoomableWidget({ - Key key, + Key? key, this.minScale: 0.7, this.maxScale: 1.4, this.initialScale: 1.0, @@ -73,10 +73,10 @@ class ZoomableWidget extends StatefulWidget { final double panLimit; /// The child widget that is display. - final Widget child; + final Widget? child; /// Tap callback for this widget. - final VoidCallback onTap; + final VoidCallback? onTap; /// Allow users to zoom with double tap steps by steps. final int zoomSteps; @@ -94,7 +94,7 @@ class ZoomableWidget extends StatefulWidget { final double flingFactor; /// When the scale value changed, the callback will be invoked. - final ValueChanged onZoomChanged; + final ValueChanged? onZoomChanged; /// The duration of reset animation. final Duration resetDuration; @@ -133,7 +133,7 @@ class _ZoomableWidgetState extends State { void _onScaleStart(ScaleStartDetails details) { if (_childSize == Size.zero) { - final RenderBox renderbox = _key.currentContext.findRenderObject(); + final RenderBox renderbox = _key.currentContext!.findRenderObject() as RenderBox; _childSize = renderbox.size; } setState(() { @@ -158,7 +158,7 @@ class _ZoomableWidgetState extends State { if (widget.enableZoom && details.scale != 1.0) { _zoom = (_previousZoom * details.scale) .clamp(widget.minScale, widget.maxScale); - if (widget.onZoomChanged != null) widget.onZoomChanged(_zoom); + if (widget.onZoomChanged != null) widget.onZoomChanged!(_zoom); } }); @@ -203,7 +203,7 @@ class _ZoomableWidgetState extends State { final double magnitude = velocity.distance; if (magnitude > 800.0 * _zoom && widget.enableFling) { final Offset direction = velocity / magnitude; - final double distance = (Offset.zero & context.size).shortestSide; + final double distance = (Offset.zero & context.size!).shortestSide; final Offset endOffset = _pan + direction * distance * widget.flingFactor * 0.5; _pan = Offset( @@ -250,7 +250,7 @@ class _ZoomableWidgetState extends State { setState(() { _zoom = _tmpZoom; - if (widget.onZoomChanged != null) widget.onZoomChanged(_zoom); + if (widget.onZoomChanged != null) widget.onZoomChanged!(_zoom); _pan = Offset.zero; _rotation = 0.0; _previousZoom = _tmpZoom; @@ -325,12 +325,12 @@ class _ZoomableWidgetLayout extends MultiChildLayoutDelegate { class _ZoomableChild extends ImplicitlyAnimatedWidget { const _ZoomableChild({ - Duration duration, + required Duration duration, Curve curve = Curves.linear, - @required this.zoom, - @required this.panOffset, - @required this.rotation, - @required this.child, + required this.zoom, + required this.panOffset, + required this.rotation, + required this.child, }) : super(duration: duration, curve: curve); final double zoom; @@ -344,49 +344,49 @@ class _ZoomableChild extends ImplicitlyAnimatedWidget { } class _ZoomableChildState extends AnimatedWidgetBaseState<_ZoomableChild> { - DoubleTween _zoom; - OffsetTween _panOffset; + DoubleTween? _zoom; + OffsetTween? _panOffset; // OffsetTween _zoomOriginOffset; - DoubleTween _rotation; + DoubleTween? _rotation; @override void forEachTween(visitor) { _zoom = visitor( - _zoom, widget.zoom, (dynamic value) => DoubleTween(begin: value)); + _zoom, widget.zoom, (dynamic value) => DoubleTween(begin: value)) as DoubleTween?; _panOffset = visitor(_panOffset, widget.panOffset, - (dynamic value) => OffsetTween(begin: value)); + (dynamic value) => OffsetTween(begin: value)) as OffsetTween?; _rotation = visitor(_rotation, widget.rotation, - (dynamic value) => DoubleTween(begin: value)); + (dynamic value) => DoubleTween(begin: value)) as DoubleTween?; } @override Widget build(BuildContext context) { return Transform( alignment: Alignment.center, - origin: Offset(-_panOffset.evaluate(animation).dx, - -_panOffset.evaluate(animation).dy), + origin: Offset(-(_panOffset!.evaluate(animation)?.dx ?? 0), + -(_panOffset!.evaluate(animation)?.dy ?? 0)), transform: Matrix4.identity() - ..translate(_panOffset.evaluate(animation).dx, - _panOffset.evaluate(animation).dy) - ..scale(_zoom.evaluate(animation), _zoom.evaluate(animation)), + ..translate(_panOffset?.evaluate(animation)?.dx, + _panOffset?.evaluate(animation)?.dy ?? 0) + ..scale(_zoom!.evaluate(animation), _zoom!.evaluate(animation)), child: Transform.rotate( - angle: _rotation.evaluate(animation), + angle: _rotation!.evaluate(animation) ?? 0, child: widget.child, ), ); } } -class DoubleTween extends Tween { - DoubleTween({double begin, double end}) : super(begin: begin, end: end); +class DoubleTween extends Tween { + DoubleTween({double? begin, double? end}) : super(begin: begin, end: end); @override - double lerp(double t) => (begin + (end - begin) * t); + double lerp(double t) => (begin! + (end! - begin!) * t); } -class OffsetTween extends Tween { - OffsetTween({Offset begin, Offset end}) : super(begin: begin, end: end); +class OffsetTween extends Tween { + OffsetTween({Offset? begin, Offset? end}) : super(begin: begin, end: end); @override - Offset lerp(double t) => (begin + (end - begin) * t); + Offset lerp(double t) => (begin! + (end! - begin!) * t); } diff --git a/pubspec.lock b/pubspec.lock index d9c0b0d..742a2bb 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,69 +1,69 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + archive: + dependency: transitive + description: + name: archive + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.2" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.2.0" + version: "2.7.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.1.2" + version: "1.2.0" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "1.1.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0-nullsafety.3" - convert: - dependency: transitive - description: - name: convert - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.1" + version: "1.15.0" crypto: dependency: transitive description: name: crypto url: "https://pub.dartlang.org" source: hosted - version: "2.0.6" + version: "3.0.1" ffi: dependency: transitive description: name: ffi url: "https://pub.dartlang.org" source: hosted - version: "0.1.3" + version: "1.0.0" file: dependency: transitive description: name: file url: "https://pub.dartlang.org" source: hosted - version: "5.2.1" + version: "6.1.1" flutter: dependency: "direct main" description: flutter @@ -75,126 +75,133 @@ packages: name: flutter_cache_manager url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "3.0.2" http: dependency: transitive description: name: http url: "https://pub.dartlang.org" source: hosted - version: "0.12.0+2" + version: "0.13.3" http_parser: dependency: transitive description: name: http_parser url: "https://pub.dartlang.org" source: hosted - version: "3.1.3" - infinite_listview: + version: "4.0.0" + image: dependency: transitive description: - name: infinite_listview + name: image url: "https://pub.dartlang.org" source: hosted - version: "1.0.1+1" - intl: + version: "3.0.2" + infinite_listview: dependency: transitive description: - name: intl + name: infinite_listview url: "https://pub.dartlang.org" source: hosted - version: "0.16.1" + version: "1.1.0" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" numberpicker: dependency: "direct main" description: name: numberpicker url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "2.1.1" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.4" + version: "1.8.0" path_provider: dependency: "direct main" description: name: path_provider url: "https://pub.dartlang.org" source: hosted - version: "1.6.24" + 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" + 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.4" + version: "2.0.1" path_provider_windows: dependency: transitive description: name: path_provider_windows url: "https://pub.dartlang.org" source: hosted - version: "0.0.4+3" + version: "2.0.1" pedantic: dependency: transitive description: name: pedantic url: "https://pub.dartlang.org" source: hosted - version: "1.8.0+1" + version: "1.11.0" + petitparser: + dependency: transitive + description: + name: petitparser + url: "https://pub.dartlang.org" + source: hosted + version: "4.1.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.2.1" rxdart: dependency: transitive description: name: rxdart url: "https://pub.dartlang.org" source: hosted - version: "0.24.1" + version: "0.27.0" sky_engine: dependency: transitive description: flutter @@ -206,77 +213,84 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.5.5" + version: "1.8.1" sqflite: dependency: transitive description: name: sqflite url: "https://pub.dartlang.org" source: hosted - version: "1.3.1" + version: "2.0.0+3" sqflite_common: dependency: transitive description: name: sqflite_common url: "https://pub.dartlang.org" source: hosted - version: "1.0.2+1" + version: "2.0.0+2" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.1.0" synchronized: dependency: transitive description: name: synchronized url: "https://pub.dartlang.org" source: hosted - version: "2.1.0+1" + version: "3.0.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" 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" uuid: dependency: transitive description: name: uuid url: "https://pub.dartlang.org" source: hosted - version: "2.0.2" + version: "3.0.4" 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: "1.7.4" + version: "2.1.1" xdg_directories: dependency: transitive description: name: xdg_directories url: "https://pub.dartlang.org" source: hosted - version: "0.1.0" + version: "0.2.0" + xml: + dependency: transitive + description: + name: xml + url: "https://pub.dartlang.org" + source: hosted + version: "5.1.1" sdks: - dart: ">=2.10.0-110 <2.11.0" - flutter: ">=1.17.0 <2.0.0" + dart: ">=2.13.0 <3.0.0" + flutter: ">=1.24.0-10" diff --git a/pubspec.yaml b/pubspec.yaml index 59e3b09..b639174 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,18 +1,18 @@ name: advance_pdf_viewer description: A flutter plugin for handling PDF files. Works on both Android & iOS -version: 1.2.2 +version: 2.0.0 homepage: https://github.com/lohanidamodar/pdf_viewer environment: - sdk: ">=2.1.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' flutter: ">=1.17.0 <2.0.0" dependencies: flutter: sdk: flutter - flutter_cache_manager: ^2.0.0 - numberpicker: ^1.3.0 - path_provider: ^1.6.24 + flutter_cache_manager: ^3.0.2 + numberpicker: ^2.1.1 + path_provider: ^2.0.1 flutter: plugin: