diff --git a/demo/pubspec.yaml b/demo/pubspec.yaml index facc4dc1..30092923 100644 --- a/demo/pubspec.yaml +++ b/demo/pubspec.yaml @@ -20,7 +20,7 @@ dependencies: dev_dependencies: # flutter_launcher_icons: ^0.10.0 - flutter_lints: ^3.0.0 + flutter_lints: ^4.0.0 flutter_test: sdk: flutter test: diff --git a/pdf/pubspec.yaml b/pdf/pubspec.yaml index 9e10e741..5946587c 100644 --- a/pdf/pubspec.yaml +++ b/pdf/pubspec.yaml @@ -29,5 +29,5 @@ dependencies: xml: ">=6.3.0 <7.0.0" dev_dependencies: - flutter_lints: ^3.0.0 + flutter_lints: ^4.0.0 test: ">=1.16.0 <2.0.0" diff --git a/printing/analysis_options.yaml b/printing/analysis_options.yaml index d77d7078..e0fca127 100644 --- a/printing/analysis_options.yaml +++ b/printing/analysis_options.yaml @@ -6,33 +6,62 @@ analyzer: missing_return: warning public_member_api_docs: ignore todo: ignore - use_super_parameters: ignore linter: rules: + - always_declare_return_types - always_put_control_body_on_new_line - avoid_bool_literals_in_conditional_expressions - avoid_classes_with_only_static_members - avoid_field_initializers_in_const_classes + - avoid_redundant_argument_values - avoid_slow_async_io - avoid_unused_constructor_parameters - avoid_void_async + - await_only_futures - cancel_subscriptions + - cast_nullable_to_non_nullable - directives_ordering + - file_names - flutter_style_todos + - leading_newlines_in_multiline_strings - no_adjacent_strings_in_list + - no_default_cases - omit_local_variable_types - package_api_docs + - parameter_assignments - prefer_asserts_in_initializer_lists + - prefer_const_constructors_in_immutables + - prefer_final_fields + - prefer_final_in_for_each - prefer_final_locals - prefer_foreach + - prefer_generic_function_type_aliases - prefer_if_elements_to_conditional_expressions + - prefer_if_null_operators + - prefer_interpolation_to_compose_strings + - prefer_null_aware_operators - prefer_relative_imports - prefer_single_quotes + - prefer_typing_uninitialized_variables - public_member_api_docs + - require_trailing_commas - sort_constructors_first - sort_pub_dependencies - sort_unnamed_constructors_first - test_types_in_equals - throw_in_finally + - unnecessary_brace_in_string_interps + - unnecessary_getters_setters + - unnecessary_lambdas + - unnecessary_null_checks + - unnecessary_nullable_for_final_variable_declarations + - unnecessary_overrides + - unnecessary_parenthesis - unnecessary_statements + - unnecessary_this + - use_build_context_synchronously + - use_function_type_syntax_for_parameters + - use_late_for_private_fields_and_variables + - use_named_constants + - void_checks diff --git a/printing/lib/printing_web.dart b/printing/lib/printing_web.dart index 54d950a0..81c81c4e 100644 --- a/printing/lib/printing_web.dart +++ b/printing/lib/printing_web.dart @@ -56,9 +56,10 @@ class PrintingPlugin extends PrintingPlatform { bool get _hasPdfJsLib => web.window .callMethod( - 'eval'.toJS, - 'typeof pdfjsLib !== "undefined" && pdfjsLib.GlobalWorkerOptions.workerSrc != "";' - .toJS) + 'eval'.toJS, + 'typeof pdfjsLib !== "undefined" && pdfjsLib.GlobalWorkerOptions.workerSrc != "";' + .toJS, + ) .toDart; /// The base URL for loading pdf.js library @@ -93,11 +94,13 @@ class PrintingPlugin extends PrintingPlatform { // Check if the source of PDF.js library is overridden via // [dartPdfJsBaseUrl] JavaScript variable. if (web.window.hasProperty(_dartPdfJsBaseUrl.toJS).toDart) { - _pdfJsUrlBase = web.window[_dartPdfJsBaseUrl] as String; + _pdfJsUrlBase = web.window.getProperty(_dartPdfJsBaseUrl.toJS); } else { final pdfJsVersion = web.window.hasProperty(_dartPdfJsVersion.toJS).toDart - ? web.window[_dartPdfJsVersion] + ? web.window + .getProperty(_dartPdfJsVersion.toJS)! + .toDart : _pdfJsVersion; _pdfJsUrlBase = '$_pdfJsCdnPath@$pdfJsVersion/build/'; } @@ -119,7 +122,9 @@ class PrintingPlugin extends PrintingPlatform { .getProperty('pdfjsLib'.toJS) .getProperty('GlobalWorkerOptions'.toJS) .setProperty( - 'workerSrc'.toJS, '${_pdfJsUrlBase}pdf.worker.min.js'.toJS); + 'workerSrc'.toJS, + '${_pdfJsUrlBase}pdf.worker.min.js'.toJS, + ); // Restore module and exports if (module != null) { @@ -165,14 +170,16 @@ class PrintingPlugin extends PrintingPlatform { return true; }()); - FlutterError.reportError(FlutterErrorDetails( - exception: e, - stack: s, - stackFilter: (input) => input, - library: 'printing', - context: ErrorDescription('while generating a PDF'), - informationCollector: collector, - )); + FlutterError.reportError( + FlutterErrorDetails( + exception: e, + stack: s, + stackFilter: (input) => input, + library: 'printing', + context: ErrorDescription('while generating a PDF'), + informationCollector: collector, + ), + ); rethrow; } @@ -211,8 +218,10 @@ class PrintingPlugin extends PrintingPlatform { // Set the iframe to be is visible on the page (guaranteed by fixed position) but hidden using opacity 0, because // this works in Firefox. The height needs to be sufficient for some part of the document other than the PDF // viewer's toolbar to be visible in the page - frame.setAttribute('style', - 'width: 1px; height: 100px; position: fixed; left: 0; top: 0; opacity: 0; border-width: 0; margin: 0; padding: 0'); + frame.setAttribute( + 'style', + 'width: 1px; height: 100px; position: fixed; left: 0; top: 0; opacity: 0; border-width: 0; margin: 0; padding: 0', + ); } else { // Hide the iframe in other browsers frame.setAttribute( @@ -338,7 +347,7 @@ class PrintingPlugin extends PrintingPlatform { final canvas = web.window.document.createElement('canvas') as web.HTMLCanvasElement; - final context = canvas.getContext('2d') as web.CanvasRenderingContext2D; + final context = canvas.getContext('2d')! as web.CanvasRenderingContext2D; final computedPages = pages ?? Iterable.generate(numPages, (index) => index); @@ -360,9 +369,7 @@ class PrintingPlugin extends PrintingPlatform { // Convert the image to PNG final completer = Completer(); final blobCompleter = Completer(); - canvas.toBlob((web.Blob? blob) { - blobCompleter.complete(blob); - }.toJS); + canvas.toBlob(blobCompleter.complete.toJS); final blob = await blobCompleter.future; if (blob == null) { continue; @@ -373,7 +380,7 @@ class PrintingPlugin extends PrintingPlatform { r.onLoadEnd.listen( (web.ProgressEvent e) { - data.add((r.result as js.JSArrayBuffer).toDart.asInt8List()); + data.add((r.result! as js.JSArrayBuffer).toDart.asInt8List()); completer.complete(); }, ); diff --git a/printing/lib/src/asset_utils.dart b/printing/lib/src/asset_utils.dart index ee0e7421..65392345 100644 --- a/printing/lib/src/asset_utils.dart +++ b/printing/lib/src/asset_utils.dart @@ -15,7 +15,6 @@ */ import 'dart:async'; -import 'dart:ui' as ui; import 'package:flutter/rendering.dart' as rdr; import 'package:flutter/services.dart'; @@ -35,30 +34,33 @@ Future flutterImageProvider( final stream = image.resolve(configuration ?? rdr.ImageConfiguration.empty); late rdr.ImageStreamListener listener; - listener = rdr.ImageStreamListener((rdr.ImageInfo image, bool sync) async { - final bytes = - await image.image.toByteData(format: ui.ImageByteFormat.rawRgba); + listener = rdr.ImageStreamListener( + (rdr.ImageInfo image, bool sync) async { + final bytes = await image.image.toByteData(); - final result = RawImage( + final result = RawImage( bytes: bytes!.buffer.asUint8List(), width: image.image.width, - height: image.image.height); + height: image.image.height, + ); - if (!completer.isCompleted) { - completer.complete(result); - } - stream.removeListener(listener); - }, onError: (dynamic exception, StackTrace? stackTrace) { - if (!completer.isCompleted) { - completer.completeError('image failed to load'); - } - if (onError != null) { - onError(exception, stackTrace); - } else { - // https://groups.google.com/forum/#!topic/flutter-announce/hp1RNIgej38 - assert(false, 'image failed to load'); - } - }); + if (!completer.isCompleted) { + completer.complete(result); + } + stream.removeListener(listener); + }, + onError: (dynamic exception, StackTrace? stackTrace) { + if (!completer.isCompleted) { + completer.completeError('image failed to load'); + } + if (onError != null) { + onError(exception, stackTrace); + } else { + // https://groups.google.com/forum/#!topic/flutter-announce/hp1RNIgej38 + assert(false, 'image failed to load'); + } + }, + ); stream.addListener(listener); return completer.future; diff --git a/printing/lib/src/cache.dart b/printing/lib/src/cache.dart index 5ddd1ebe..610999e4 100644 --- a/printing/lib/src/cache.dart +++ b/printing/lib/src/cache.dart @@ -92,9 +92,7 @@ class PdfMemoryCache extends PdfBaseCache { void _resetTimer() { _timer?.cancel(); - _timer = Timer(const Duration(minutes: 20), () { - clear(); - }); + _timer = Timer(const Duration(minutes: 20), clear); } @override diff --git a/printing/lib/src/fonts/gfonts.dart b/printing/lib/src/fonts/gfonts.dart index d33d1b71..26bd9356 100644 --- a/printing/lib/src/fonts/gfonts.dart +++ b/printing/lib/src/fonts/gfonts.dart @@ -5503,7 +5503,7 @@ import 'font.dart'; /// - materialIcons (MaterialIcons) /// - notoColorEmoji (NotoColorEmoji) class PdfGoogleFonts extends DownloadableFont { - const PdfGoogleFonts._(String url, String name) : super(url, name); + const PdfGoogleFonts._(super.url, super.name); /// @nodoc /// ABeeZee regular diff --git a/printing/lib/src/fonts/manifest.dart b/printing/lib/src/fonts/manifest.dart index 1f647e51..42fe440b 100644 --- a/printing/lib/src/fonts/manifest.dart +++ b/printing/lib/src/fonts/manifest.dart @@ -47,7 +47,8 @@ mixin AssetManifest { assert(() { // ignore: avoid_print print( - 'Error loading AssetManifest.json $e Try to call first:\nWidgetsFlutterBinding.ensureInitialized();'); + 'Error loading AssetManifest.json $e Try to call first:\nWidgetsFlutterBinding.ensureInitialized();', + ); return true; }()); diff --git a/printing/lib/src/method_channel.dart b/printing/lib/src/method_channel.dart index 31e36c10..343eced9 100644 --- a/printing/lib/src/method_channel.dart +++ b/printing/lib/src/method_channel.dart @@ -77,14 +77,16 @@ class MethodChannelPrinting extends PrintingPlatform { return true; }()); - FlutterError.reportError(FlutterErrorDetails( - exception: e, - stack: s, - stackFilter: (input) => input, - library: 'printing', - context: ErrorDescription('while generating a PDF'), - informationCollector: collector, - )); + FlutterError.reportError( + FlutterErrorDetails( + exception: e, + stack: s, + stackFilter: (input) => input, + library: 'printing', + context: ErrorDescription('while generating a PDF'), + informationCollector: collector, + ), + ); if (job.useFFI) { return setErrorFfi(job, e.toString()); @@ -230,7 +232,9 @@ class MethodChannelPrinting extends PrintingPlatform { 'h': bounds.height, }; final printer = await _channel.invokeMethod>( - 'pickPrinter', params); + 'pickPrinter', + params, + ); if (printer == null) { return null; } @@ -262,7 +266,10 @@ class MethodChannelPrinting extends PrintingPlatform { @override Future convertHtml( - String html, String? baseUrl, PdfPageFormat format) async { + String html, + String? baseUrl, + PdfPageFormat format, + ) async { final job = _printJobs.add( onHtmlRendered: Completer(), ); diff --git a/printing/lib/src/preview/action_bar_theme.dart b/printing/lib/src/preview/action_bar_theme.dart index f245cd9d..340cc5ee 100644 --- a/printing/lib/src/preview/action_bar_theme.dart +++ b/printing/lib/src/preview/action_bar_theme.dart @@ -93,13 +93,26 @@ class PdfActionBarTheme with Diagnosticable { properties.add(DiagnosticsProperty('textStyle', textStyle)); properties.add(DoubleProperty('elevation', elevation)); properties.add(DoubleProperty('actionSpacing', actionSpacing)); - properties.add(DiagnosticsProperty('alignment', alignment, - defaultValue: WrapAlignment.spaceAround)); - properties.add(DiagnosticsProperty( - 'runAlignment', runAlignment, - defaultValue: WrapAlignment.center)); - properties.add(DiagnosticsProperty( - 'crossAxisAlignment', crossAxisAlignment, - defaultValue: WrapCrossAlignment.center)); + properties.add( + DiagnosticsProperty( + 'alignment', + alignment, + defaultValue: WrapAlignment.spaceAround, + ), + ); + properties.add( + DiagnosticsProperty( + 'runAlignment', + runAlignment, + defaultValue: WrapAlignment.center, + ), + ); + properties.add( + DiagnosticsProperty( + 'crossAxisAlignment', + crossAxisAlignment, + defaultValue: WrapCrossAlignment.center, + ), + ); } } diff --git a/printing/lib/src/preview/actions.dart b/printing/lib/src/preview/actions.dart index 37625f75..2f4c8f3a 100644 --- a/printing/lib/src/preview/actions.dart +++ b/printing/lib/src/preview/actions.dart @@ -36,7 +36,7 @@ mixin PdfPreviewActionBounds { /// Calculate the widget bounds for iPad popup position Rect get bounds { final referenceBox = - childKey.currentContext!.findRenderObject() as RenderBox; + childKey.currentContext!.findRenderObject()! as RenderBox; final topLeft = referenceBox.localToGlobal(referenceBox.paintBounds.topLeft); final bottomRight = @@ -49,10 +49,10 @@ mixin PdfPreviewActionBounds { class PdfPreviewAction extends StatelessWidget { /// Represents an icon to add to [PdfPreview] const PdfPreviewAction({ - Key? key, + super.key, required this.icon, required this.onPressed, - }) : super(key: key); + }); /// The icon to display final Widget icon; @@ -76,7 +76,7 @@ class PdfPreviewAction extends StatelessWidget { class PdfPrintAction extends StatelessWidget { const PdfPrintAction({ - Key? key, + super.key, Widget? icon, String? jobName, this.onPrinted, @@ -84,8 +84,7 @@ class PdfPrintAction extends StatelessWidget { this.dynamicLayout = true, this.usePrinterSettings = false, }) : icon = icon ?? const Icon(Icons.print), - jobName = jobName ?? 'Document', - super(key: key); + jobName = jobName ?? 'Document'; final Widget icon; @@ -144,13 +143,15 @@ class PdfPrintAction extends StatelessWidget { return true; }()); - FlutterError.reportError(FlutterErrorDetails( - exception: exception, - stack: stack, - library: 'printing', - context: ErrorDescription('while printing a PDF'), - informationCollector: collector, - )); + FlutterError.reportError( + FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'printing', + context: ErrorDescription('while printing a PDF'), + informationCollector: collector, + ), + ); onPrintError?.call(exception); } @@ -159,7 +160,7 @@ class PdfPrintAction extends StatelessWidget { class PdfShareAction extends StatelessWidget with PdfPreviewActionBounds { PdfShareAction({ - Key? key, + super.key, Widget? icon, String? filename, this.subject, @@ -168,8 +169,7 @@ class PdfShareAction extends StatelessWidget with PdfPreviewActionBounds { this.onShared, this.onShareError, }) : icon = icon ?? const Icon(Icons.share), - filename = filename ?? 'document.pdf', - super(key: key); + filename = filename ?? 'document.pdf'; final Widget icon; @@ -225,9 +225,9 @@ class PdfShareAction extends StatelessWidget with PdfPreviewActionBounds { class PdfPageFormatAction extends StatelessWidget { const PdfPageFormatAction({ - Key? key, + super.key, required this.pageFormats, - }) : super(key: key); + }); /// List of page formats the user can choose final Map pageFormats; @@ -288,8 +288,8 @@ class PdfPageFormatAction extends StatelessWidget { class PdfPageOrientationAction extends StatelessWidget { const PdfPageOrientationAction({ - Key? key, - }) : super(key: key); + super.key, + }); @override Widget build(BuildContext context) { diff --git a/printing/lib/src/preview/controller.dart b/printing/lib/src/preview/controller.dart index ac94cd57..a553ab83 100644 --- a/printing/lib/src/preview/controller.dart +++ b/printing/lib/src/preview/controller.dart @@ -79,10 +79,10 @@ class PdfPreviewData extends ChangeNotifier { class PdfPreviewController extends InheritedNotifier { const PdfPreviewController({ - Key? key, + super.key, required this.data, - required Widget child, - }) : super(key: key, child: child, notifier: data); + required super.child, + }) : super(notifier: data); final PdfPreviewData data; diff --git a/printing/lib/src/preview/custom.dart b/printing/lib/src/preview/custom.dart index 47f1b635..d516e582 100644 --- a/printing/lib/src/preview/custom.dart +++ b/printing/lib/src/preview/custom.dart @@ -29,13 +29,15 @@ import 'raster.dart'; /// Custom widget builder that's used for custom /// rasterized pdf pages rendering typedef CustomPdfPagesBuilder = Widget Function( - BuildContext context, List pages); + BuildContext context, + List pages, +); /// Flutter widget that uses the rasterized pdf pages to display a document. class PdfPreviewCustom extends StatefulWidget { /// Show a pdf document built on demand const PdfPreviewCustom({ - Key? key, + super.key, this.pageFormat = PdfPageFormat.a4, required this.build, this.maxPageWidth, @@ -53,7 +55,7 @@ class PdfPreviewCustom extends StatefulWidget { this.pagesBuilder, this.enableScrollToPage = false, this.onZoomChanged, - }) : super(key: key); + }); /// Pdf paper page format final PdfPageFormat pageFormat; @@ -127,9 +129,7 @@ class PdfPreviewCustomState extends State double? updatePosition; - final scrollController = ScrollController( - keepScrollOffset: true, - ); + final scrollController = ScrollController(); final transformationController = TransformationController(); @@ -198,8 +198,12 @@ class PdfPreviewCustomState extends State assert(index >= 0, 'Index of page cannot be negative'); final pageContext = _pageGlobalKeys[index].currentContext; assert(pageContext != null, 'Context of GlobalKey cannot be null'); - return Scrollable.ensureVisible(pageContext!, - duration: duration, curve: curve, alignmentPolicy: alignmentPolicy); + return Scrollable.ensureVisible( + pageContext!, + duration: duration, + curve: curve, + alignmentPolicy: alignmentPolicy, + ); } /// Returns the global key for page with [index]. diff --git a/printing/lib/src/preview/page.dart b/printing/lib/src/preview/page.dart index c4ac1bce..b85fbdc5 100644 --- a/printing/lib/src/preview/page.dart +++ b/printing/lib/src/preview/page.dart @@ -65,11 +65,11 @@ class PdfPreviewPageData { class PdfPreviewPage extends StatelessWidget { /// Create a PDF page widget const PdfPreviewPage({ - Key? key, + super.key, required this.pageData, this.pdfPreviewPageDecoration, this.pageMargin, - }) : super(key: key); + }); /// Image representing the content of the page final PdfPreviewPageData pageData; @@ -103,7 +103,6 @@ class PdfPreviewPage extends StatelessWidget { BoxShadow( offset: Offset(0, 3), blurRadius: 5, - color: Color(0xFF000000), ), ], ), diff --git a/printing/lib/src/preview/pdf_preview.dart b/printing/lib/src/preview/pdf_preview.dart index 73fc64be..c397459b 100644 --- a/printing/lib/src/preview/pdf_preview.dart +++ b/printing/lib/src/preview/pdf_preview.dart @@ -33,7 +33,7 @@ export 'page.dart' show PdfPreviewPageData; class PdfPreview extends StatefulWidget { /// Show a pdf document built on demand const PdfPreview({ - Key? key, + super.key, required this.build, this.initialPageFormat, this.allowPrinting = true, @@ -66,8 +66,7 @@ class PdfPreview extends StatefulWidget { this.actionBarTheme = const PdfActionBarTheme(), this.enableScrollToPage = false, this.onZoomChanged, - }) : _pagesBuilder = null, - super(key: key); + }) : _pagesBuilder = null; /// Build a custom layout. /// @@ -93,7 +92,7 @@ class PdfPreview extends StatefulWidget { /// ) /// ``` const PdfPreview.builder({ - Key? key, + super.key, required this.build, this.initialPageFormat, this.allowPrinting = true, @@ -127,8 +126,7 @@ class PdfPreview extends StatefulWidget { required CustomPdfPagesBuilder pagesBuilder, this.enableScrollToPage = false, this.onZoomChanged, - }) : _pagesBuilder = pagesBuilder, - super(key: key); + }) : _pagesBuilder = pagesBuilder; static const _defaultPageFormats = { 'A4': PdfPageFormat.a4, @@ -341,32 +339,40 @@ class PdfPreviewState extends State { final actions = []; if (widget.useActions && widget.allowPrinting && info?.canPrint == true) { - actions.add(PdfPrintAction( - jobName: widget.pdfFileName, - dynamicLayout: widget.dynamicLayout, - onPrinted: - widget.onPrinted == null ? null : () => widget.onPrinted!(context), - onPrintError: widget.onPrintError == null - ? null - : (dynamic error) => widget.onPrintError!(context, error), - )); + actions.add( + PdfPrintAction( + jobName: widget.pdfFileName, + dynamicLayout: widget.dynamicLayout, + onPrinted: widget.onPrinted == null + ? null + : () => widget.onPrinted!(context), + onPrintError: widget.onPrintError == null + ? null + : (dynamic error) => widget.onPrintError!(context, error), + ), + ); } if (widget.useActions && widget.allowSharing && info?.canShare == true) { - actions.add(PdfShareAction( - filename: widget.pdfFileName, - onShared: - widget.onPrinted == null ? null : () => widget.onPrinted!(context), - subject: widget.shareActionExtraSubject, - emails: widget.shareActionExtraEmails, - body: widget.shareActionExtraBody, - )); + actions.add( + PdfShareAction( + filename: widget.pdfFileName, + onShared: widget.onPrinted == null + ? null + : () => widget.onPrinted!(context), + subject: widget.shareActionExtraSubject, + emails: widget.shareActionExtraEmails, + body: widget.shareActionExtraBody, + ), + ); } if (widget.useActions && widget.canChangePageFormat) { - actions.add(PdfPageFormatAction( - pageFormats: widget.pageFormats, - )); + actions.add( + PdfPageFormatAction( + pageFormats: widget.pageFormats, + ), + ); } if (widget.useActions && widget.canChangeOrientation) { @@ -401,27 +407,29 @@ class PdfPreviewState extends State { mainAxisAlignment: MainAxisAlignment.center, children: [ Expanded( - child: Builder(builder: (context) { - final controller = PdfPreviewController.listen(context); - return PdfPreviewCustom( - key: previewWidget, - build: controller.buildDocument, - loadingWidget: widget.loadingWidget, - maxPageWidth: widget.maxPageWidth, - onError: widget.onError, - padding: widget.padding, - pageFormat: controller.pageFormat, - pages: widget.pages, - pdfPreviewPageDecoration: widget.pdfPreviewPageDecoration, - previewPageMargin: widget.previewPageMargin, - scrollViewDecoration: widget.scrollViewDecoration, - shouldRepaint: widget.shouldRepaint, - pagesBuilder: widget._pagesBuilder, - dpi: widget.dpi, - enableScrollToPage: widget.enableScrollToPage, - onZoomChanged: widget.onZoomChanged, - ); - }), + child: Builder( + builder: (context) { + final controller = PdfPreviewController.listen(context); + return PdfPreviewCustom( + key: previewWidget, + build: controller.buildDocument, + loadingWidget: widget.loadingWidget, + maxPageWidth: widget.maxPageWidth, + onError: widget.onError, + padding: widget.padding, + pageFormat: controller.pageFormat, + pages: widget.pages, + pdfPreviewPageDecoration: widget.pdfPreviewPageDecoration, + previewPageMargin: widget.previewPageMargin, + scrollViewDecoration: widget.scrollViewDecoration, + shouldRepaint: widget.shouldRepaint, + pagesBuilder: widget._pagesBuilder, + dpi: widget.dpi, + enableScrollToPage: widget.enableScrollToPage, + onZoomChanged: widget.onZoomChanged, + ); + }, + ), ), if (actions.isNotEmpty) IconTheme.merge( diff --git a/printing/lib/src/preview/raster.dart b/printing/lib/src/preview/raster.dart index 0e9371ed..a0f64d10 100644 --- a/printing/lib/src/preview/raster.dart +++ b/printing/lib/src/preview/raster.dart @@ -106,12 +106,15 @@ mixin PdfPreviewRaster on State { if (printingInfo != null && !printingInfo.canRaster) { assert(() { if (kIsWeb) { - FlutterError.reportError(FlutterErrorDetails( - exception: Exception( - 'Unable to find the `pdf.js` library.\nPlease follow the installation instructions at https://github.com/DavBfr/dart_pdf/tree/master/printing#installing'), - library: 'printing', - context: ErrorDescription('while rendering a PDF'), - )); + FlutterError.reportError( + FlutterErrorDetails( + exception: Exception( + 'Unable to find the `pdf.js` library.\nPlease follow the installation instructions at https://github.com/DavBfr/dart_pdf/tree/master/printing#installing', + ), + library: 'printing', + context: ErrorDescription('while rendering a PDF'), + ), + ); } return true; @@ -133,13 +136,15 @@ mixin PdfPreviewRaster on State { return true; }()); - FlutterError.reportError(FlutterErrorDetails( - exception: exception, - stack: stack, - library: 'printing', - context: ErrorDescription('while generating a PDF'), - informationCollector: collector, - )); + FlutterError.reportError( + FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'printing', + context: ErrorDescription('while generating a PDF'), + informationCollector: collector, + ), + ); if (mounted) { setState(() { error = exception; @@ -168,11 +173,13 @@ mixin PdfPreviewRaster on State { return; } if (pages.length <= pageNum) { - pages.add(PdfPreviewPageData( - image: MemoryImage(await page.toPng()), - width: page.width, - height: page.height, - )); + pages.add( + PdfPreviewPageData( + image: MemoryImage(await page.toPng()), + width: page.width, + height: page.height, + ), + ); } else { pages[pageNum].image.evict(); pages[pageNum] = PdfPreviewPageData( @@ -206,13 +213,15 @@ mixin PdfPreviewRaster on State { return true; }()); - FlutterError.reportError(FlutterErrorDetails( - exception: exception, - stack: stack, - library: 'printing', - context: ErrorDescription('while rastering a PDF'), - informationCollector: collector, - )); + FlutterError.reportError( + FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'printing', + context: ErrorDescription('while rastering a PDF'), + informationCollector: collector, + ), + ); if (mounted) { setState(() { diff --git a/printing/lib/src/printer.dart b/printing/lib/src/printer.dart index 5d17a05a..902a9846 100644 --- a/printing/lib/src/printer.dart +++ b/printing/lib/src/printer.dart @@ -65,7 +65,8 @@ class Printer { final bool isAvailable; @override - String toString() => '''$runtimeType $name + String toString() => ''' +$runtimeType $name url:$url location:$location model:$model diff --git a/printing/lib/src/printing_info.dart b/printing/lib/src/printing_info.dart index 4111d01c..19848991 100644 --- a/printing/lib/src/printing_info.dart +++ b/printing/lib/src/printing_info.dart @@ -66,7 +66,8 @@ class PrintingInfo { final bool canRaster; @override - String toString() => '''$runtimeType: + String toString() => ''' +$runtimeType: canPrint: $canPrint directPrint: $directPrint dynamicLayout: $dynamicLayout diff --git a/printing/lib/src/raster.dart b/printing/lib/src/raster.dart index ba35f97a..a7eb8be4 100644 --- a/printing/lib/src/raster.dart +++ b/printing/lib/src/raster.dart @@ -38,7 +38,7 @@ class PdfRaster extends PdfRasterBase { width, height, ui.PixelFormat.rgba8888, - (ui.Image image) => comp.complete(image), + comp.complete, ); return comp.future; } @@ -62,7 +62,7 @@ class PdfRasterImage extends ImageProvider { Future _loadAsync() async { final uiImage = await raster.toImage(); - return ImageInfo(image: uiImage, scale: 1); + return ImageInfo(image: uiImage); } @override diff --git a/printing/pubspec.yaml b/printing/pubspec.yaml index 371310fa..fb0fb407 100644 --- a/printing/pubspec.yaml +++ b/printing/pubspec.yaml @@ -36,7 +36,7 @@ dependencies: web: ^0.5.1 dev_dependencies: - flutter_lints: ^3.0.0 + flutter_lints: ^4.0.0 flutter_test: sdk: flutter mockito: ^5.3.2 diff --git a/printing/test/info_test.dart b/printing/test/info_test.dart index ed84cad3..6713db05 100644 --- a/printing/test/info_test.dart +++ b/printing/test/info_test.dart @@ -18,9 +18,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:printing/printing.dart'; void main() { - setUp(() { - TestWidgetsFlutterBinding.ensureInitialized(); - }); + setUp(TestWidgetsFlutterBinding.ensureInitialized); test('PrintingInfo', () async { const info = PrintingInfo.unavailable; diff --git a/printing/test/printing_test.dart b/printing/test/printing_test.dart index 0392ea38..37a5c45e 100644 --- a/printing/test/printing_test.dart +++ b/printing/test/printing_test.dart @@ -38,12 +38,13 @@ void main() { test('layoutPdf', () async { expect( - await Printing.layoutPdf( - onLayout: (_) => Uint8List(0), - name: 'doc', - format: PdfPageFormat.letter, - ), - true); + await Printing.layoutPdf( + onLayout: (_) => Uint8List(0), + name: 'doc', + format: PdfPageFormat.letter, + ), + true, + ); }); test('sharePdf', () async { @@ -86,7 +87,7 @@ void main() { 69, 181, 208, 208, 99, 4, 22, 234, 0, 0, 0, 31, 73, 68, 65, 84, 104, 129, 237, 193, 1, 13, 0, 0, 0, 194, 160, 247, 79, 109, 14, 55, 160, 0, 0, 0, 0, 0, 0, 0, 0, 190, 13, 33, 0, 0, 1, 154, 96, 225, 213, 0, 0, 0, 0, 73, - 69, 78, 68, 174, 66, 96, 130 + 69, 78, 68, 174, 66, 96, 130, ]); final imageProvider = Image.memory(bytes).image; expect(await flutterImageProvider(imageProvider), isNotNull); @@ -97,7 +98,7 @@ class MockPrinting extends Mock with MockPlatformInterfaceMixin implements PrintingPlatform { @override - Future info() async => const PrintingInfo(); + Future info() async => PrintingInfo.unavailable; @override Future layoutPdf( @@ -111,8 +112,14 @@ class MockPrinting extends Mock true; @override - Future sharePdf(Uint8List bytes, String filename, Rect bounds, - String? subject, String? body, List? emails) async => + Future sharePdf( + Uint8List bytes, + String filename, + Rect bounds, + String? subject, + String? body, + List? emails, + ) async => true; @override @@ -120,7 +127,10 @@ class MockPrinting extends Mock @override Stream raster( - Uint8List document, List? pages, double dpi) async* {} + Uint8List document, + List? pages, + double dpi, + ) async* {} } class MockContext extends Mock implements BuildContext {} diff --git a/printing/test/raster_test.dart b/printing/test/raster_test.dart index 1fe123cd..7d413283 100644 --- a/printing/test/raster_test.dart +++ b/printing/test/raster_test.dart @@ -22,9 +22,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:printing/printing.dart'; void main() { - setUp(() { - TestWidgetsFlutterBinding.ensureInitialized(); - }); + setUp(TestWidgetsFlutterBinding.ensureInitialized); test('PdfRaster', () async { final raster = diff --git a/widget_wrapper/pubspec.yaml b/widget_wrapper/pubspec.yaml index 3296a2be..3d061259 100644 --- a/widget_wrapper/pubspec.yaml +++ b/widget_wrapper/pubspec.yaml @@ -20,7 +20,7 @@ dependency_overrides: path: ../pdf dev_dependencies: - flutter_lints: ^3.0.0 + flutter_lints: ^4.0.0 flutter_test: sdk: flutter