Skip to content

Commit

Permalink
Fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
DavBfr committed May 16, 2024
1 parent a171922 commit f4ac9a3
Show file tree
Hide file tree
Showing 25 changed files with 283 additions and 197 deletions.
2 changes: 1 addition & 1 deletion demo/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pdf/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 1 addition & 0 deletions printing/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Migrate to package:web and dart:js_interop
- Set Flutter 3.19 as minimal version
- Fix lints

## 5.12.0

Expand Down
31 changes: 30 additions & 1 deletion printing/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
49 changes: 28 additions & 21 deletions printing/lib/printing_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ class PrintingPlugin extends PrintingPlatform {

bool get _hasPdfJsLib => web.window
.callMethod<js.JSBoolean>(
'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
Expand Down Expand Up @@ -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<js.JSString?>(_dartPdfJsVersion.toJS)!
.toDart
: _pdfJsVersion;
_pdfJsUrlBase = '$_pdfJsCdnPath@$pdfJsVersion/build/';
}
Expand All @@ -119,7 +122,9 @@ class PrintingPlugin extends PrintingPlatform {
.getProperty<js.JSObject>('pdfjsLib'.toJS)
.getProperty<js.JSObject>('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) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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<int>.generate(numPages, (index) => index);

Expand All @@ -360,9 +369,7 @@ class PrintingPlugin extends PrintingPlatform {
// Convert the image to PNG
final completer = Completer<void>();
final blobCompleter = Completer<web.Blob?>();
canvas.toBlob((web.Blob? blob) {
blobCompleter.complete(blob);
}.toJS);
canvas.toBlob(blobCompleter.complete.toJS);
final blob = await blobCompleter.future;
if (blob == null) {
continue;
Expand All @@ -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();
},
);
Expand Down
44 changes: 23 additions & 21 deletions printing/lib/src/asset_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

import 'dart:async';
import 'dart:ui' as ui;

import 'package:flutter/rendering.dart' as rdr;
import 'package:flutter/services.dart';
Expand All @@ -35,30 +34,33 @@ Future<ImageProvider> 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;
Expand Down
4 changes: 1 addition & 3 deletions printing/lib/src/cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion printing/lib/src/fonts/gfonts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion printing/lib/src/fonts/manifest.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}());

Expand Down
27 changes: 17 additions & 10 deletions printing/lib/src/method_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -230,7 +232,9 @@ class MethodChannelPrinting extends PrintingPlatform {
'h': bounds.height,
};
final printer = await _channel.invokeMethod<Map<dynamic, dynamic>>(
'pickPrinter', params);
'pickPrinter',
params,
);
if (printer == null) {
return null;
}
Expand Down Expand Up @@ -262,7 +266,10 @@ class MethodChannelPrinting extends PrintingPlatform {

@override
Future<Uint8List> convertHtml(
String html, String? baseUrl, PdfPageFormat format) async {
String html,
String? baseUrl,
PdfPageFormat format,
) async {
final job = _printJobs.add(
onHtmlRendered: Completer<Uint8List>(),
);
Expand Down
29 changes: 21 additions & 8 deletions printing/lib/src/preview/action_bar_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,26 @@ class PdfActionBarTheme with Diagnosticable {
properties.add(DiagnosticsProperty<TextStyle>('textStyle', textStyle));
properties.add(DoubleProperty('elevation', elevation));
properties.add(DoubleProperty('actionSpacing', actionSpacing));
properties.add(DiagnosticsProperty<WrapAlignment>('alignment', alignment,
defaultValue: WrapAlignment.spaceAround));
properties.add(DiagnosticsProperty<WrapAlignment>(
'runAlignment', runAlignment,
defaultValue: WrapAlignment.center));
properties.add(DiagnosticsProperty<WrapCrossAlignment>(
'crossAxisAlignment', crossAxisAlignment,
defaultValue: WrapCrossAlignment.center));
properties.add(
DiagnosticsProperty<WrapAlignment>(
'alignment',
alignment,
defaultValue: WrapAlignment.spaceAround,
),
);
properties.add(
DiagnosticsProperty<WrapAlignment>(
'runAlignment',
runAlignment,
defaultValue: WrapAlignment.center,
),
);
properties.add(
DiagnosticsProperty<WrapCrossAlignment>(
'crossAxisAlignment',
crossAxisAlignment,
defaultValue: WrapCrossAlignment.center,
),
);
}
}
Loading

0 comments on commit f4ac9a3

Please sign in to comment.