David PHAM-VAN

Force Flutter 3.7

... ... @@ -333,7 +333,7 @@ class MultiPage extends Page {
'You probably need a SpanningWidget or use a single page layout');
}
final span = child as SpanningWidget;
final span = child;
if (savedContext != null) {
// Restore saved context
... ...
... ... @@ -9,7 +9,7 @@ screenshots:
version: 3.9.0
environment:
sdk: ">=2.12.0 <3.0.0"
sdk: ">=2.18.0 <3.0.0"
dependencies:
archive: ^3.1.0
... ...
... ... @@ -317,10 +317,10 @@ class PrintingPlugin extends PrintingPlatform {
js.context['document'].createElement('canvas');
final context = canvas.getContext('2d') as html.CanvasRenderingContext2D?;
final _pages =
final computedPages =
pages ?? Iterable<int>.generate(numPages, (index) => index);
for (final pageIndex in _pages) {
for (final pageIndex in computedPages) {
final page =
await promiseToFuture<PdfJsPage>(doc.getPage(pageIndex + 1));
try {
... ...
... ... @@ -237,14 +237,14 @@ class PdfPageFormatAction extends StatelessWidget {
final theme = Theme.of(context);
final iconColor = theme.primaryIconTheme.color ?? Colors.white;
final data = PdfPreviewController.listen(context);
final _pageFormats = <String, PdfPageFormat>{...pageFormats};
final allPageFormats = <String, PdfPageFormat>{...pageFormats};
var format = data.pageFormat;
final orientation = data.horizontal;
if (!_pageFormats.values.contains(data.pageFormat)) {
if (!allPageFormats.values.contains(data.pageFormat)) {
var found = false;
for (final f in _pageFormats.values) {
for (final f in allPageFormats.values) {
if (format.portrait == f.portrait) {
format = f;
found = true;
... ... @@ -252,11 +252,11 @@ class PdfPageFormatAction extends StatelessWidget {
}
}
if (!found) {
_pageFormats['---'] = format;
allPageFormats['---'] = format;
}
}
final keys = _pageFormats.keys.toList()..sort();
final keys = allPageFormats.keys.toList()..sort();
return DropdownButton<PdfPageFormat>(
dropdownColor: theme.primaryColor,
... ... @@ -266,10 +266,10 @@ class PdfPageFormatAction extends StatelessWidget {
),
value: format,
items: List<DropdownMenuItem<PdfPageFormat>>.generate(
_pageFormats.length,
allPageFormats.length,
(int index) {
final key = keys[index];
final val = _pageFormats[key]!;
final val = allPageFormats[key]!;
return DropdownMenuItem<PdfPageFormat>(
value: val,
child: Text(key, style: TextStyle(color: iconColor)),
... ...
... ... @@ -67,12 +67,9 @@ class PdfPreviewData extends ChangeNotifier {
PdfPageFormat get actualPageFormat => _onComputeActualPageFormat();
String get localPageFormat {
// Flutter 3 workaround
// ignore: omit_local_variable_types
final WidgetsBinding? wbi = WidgetsBinding.instance;
final locale = wbi!.window.locale;
// ignore: unnecessary_cast
final cc = (locale as Locale?)?.countryCode ?? 'US';
final wbi = WidgetsBinding.instance;
final locale = wbi.window.locale;
final cc = locale.countryCode ?? 'US';
if (cc == 'US' || cc == 'CA' || cc == 'MX') {
return 'Letter';
... ...
... ... @@ -157,9 +157,9 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom>
void didChangeDependencies() {
if (!infoLoaded) {
infoLoaded = true;
Printing.info().then((PrintingInfo _info) {
Printing.info().then((PrintingInfo printingInfo) {
setState(() {
info = _info;
info = printingInfo;
raster();
});
});
... ... @@ -182,8 +182,8 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom>
return _showError(error!);
}
final _info = info;
if (_info != null && !_info.canRaster) {
final printingInfo = info;
if (printingInfo != null && !printingInfo.canRaster) {
return _showError(_errorMessage);
}
... ...
... ... @@ -228,10 +228,10 @@ class PdfPreview extends StatefulWidget {
final CustomPdfPagesBuilder? _pagesBuilder;
@override
_PdfPreviewState createState() => _PdfPreviewState();
PdfPreviewState createState() => PdfPreviewState();
}
class _PdfPreviewState extends State<PdfPreview> {
class PdfPreviewState extends State<PdfPreview> {
final previewWidget = GlobalKey<PdfPreviewCustomState>();
late PdfPreviewData previewData;
... ... @@ -305,9 +305,9 @@ class _PdfPreviewState extends State<PdfPreview> {
void didChangeDependencies() {
if (!infoLoaded) {
infoLoaded = true;
Printing.info().then((PrintingInfo _info) {
Printing.info().then((PrintingInfo printingInfo) {
setState(() {
info = _info;
info = printingInfo;
});
});
}
... ...
... ... @@ -100,10 +100,10 @@ mixin PdfPreviewRaster on State<PdfPreviewCustom> {
}
_rastering = true;
Uint8List _doc;
Uint8List doc;
final _info = info;
if (_info != null && !_info.canRaster) {
final printingInfo = info;
if (printingInfo != null && !printingInfo.canRaster) {
assert(() {
if (kIsWeb) {
FlutterError.reportError(FlutterErrorDetails(
... ... @@ -122,7 +122,7 @@ mixin PdfPreviewRaster on State<PdfPreviewCustom> {
}
try {
_doc = await widget.build(pageFormat);
doc = await widget.build(pageFormat);
} catch (exception, stack) {
InformationCollector? collector;
... ... @@ -159,7 +159,7 @@ mixin PdfPreviewRaster on State<PdfPreviewCustom> {
try {
var pageNum = 0;
await for (final PdfRaster page in Printing.raster(
_doc,
doc,
dpi: dpi,
pages: widget.pages,
)) {
... ...
... ... @@ -74,9 +74,9 @@ mixin Printing {
Rect? bounds,
String? title,
}) async {
final _info = await info();
final printingInfo = await info();
if (_info.canListPrinters) {
if (printingInfo.canListPrinters) {
final printers = await listPrinters();
printers.sort((a, b) {
if (a.isDefault) {
... ... @@ -88,6 +88,7 @@ mixin Printing {
return a.name.compareTo(b.name);
});
// ignore: use_build_context_synchronously
return await showDialog<Printer>(
context: context,
builder: (context) => SimpleDialog(
... ...
... ... @@ -144,31 +144,32 @@ class WidgetWrapper extends pw.ImageProvider {
child: widget,
);
final _properties = DiagnosticPropertiesBuilder();
widget.debugFillProperties(_properties);
final prop = DiagnosticPropertiesBuilder();
widget.debugFillProperties(prop);
if (_properties.properties.isEmpty) {
if (prop.properties.isEmpty) {
throw ErrorDescription('Unable to get the widget properties');
}
final _constraints = _properties.properties
final computedConstraints = prop.properties
.whereType<DiagnosticsProperty<BoxConstraints>>()
.first
.value;
if (_constraints == null ||
!_constraints.hasBoundedWidth ||
!_constraints.hasBoundedWidth) {
if (computedConstraints == null ||
!computedConstraints.hasBoundedWidth ||
!computedConstraints.hasBoundedWidth) {
throw Exception('Unable to convert an unbounded widget.');
}
final _repaintBoundary = RenderRepaintBoundary();
final repaintBoundary = RenderRepaintBoundary();
final renderView = RenderView(
child: RenderPositionedBox(
alignment: Alignment.center, child: _repaintBoundary),
alignment: Alignment.center, child: repaintBoundary),
configuration: ViewConfiguration(
size: Size(_constraints.maxWidth, _constraints.maxHeight),
size:
Size(computedConstraints.maxWidth, computedConstraints.maxHeight),
devicePixelRatio: ui.window.devicePixelRatio),
window: ui.window,
);
... ... @@ -177,8 +178,8 @@ class WidgetWrapper extends pw.ImageProvider {
renderView.prepareInitialFrame();
final buildOwner = BuildOwner(focusManager: FocusManager());
final _rootElement = RenderObjectToWidgetAdapter<RenderBox>(
container: _repaintBoundary,
final rootElement = RenderObjectToWidgetAdapter<RenderBox>(
container: repaintBoundary,
child: Directionality(
textDirection: TextDirection.ltr,
child: IntrinsicHeight(child: IntrinsicWidth(child: widget)),
... ... @@ -186,7 +187,7 @@ class WidgetWrapper extends pw.ImageProvider {
).attachToRenderTree(buildOwner);
buildOwner
..buildScope(_rootElement)
..buildScope(rootElement)
..finalizeTree();
pipelineOwner
... ... @@ -194,7 +195,7 @@ class WidgetWrapper extends pw.ImageProvider {
..flushCompositingBits()
..flushPaint();
final image = await _repaintBoundary.toImage(pixelRatio: pixelRatio);
final image = await repaintBoundary.toImage(pixelRatio: pixelRatio);
final bytes = await image.toByteData(format: ui.ImageByteFormat.rawRgba);
if (bytes == null) {
throw Exception('Unable to read image data');
... ...
... ... @@ -12,8 +12,8 @@ screenshots:
version: 5.10.0
environment:
sdk: ">=2.12.0 <3.0.0"
flutter: ">=1.16.0"
sdk: ">=2.18.0 <3.0.0"
flutter: ">=3.7.0"
dependencies:
ffi: ">=1.1.0 <3.0.0"
... ... @@ -22,17 +22,17 @@ dependencies:
flutter_web_plugins:
sdk: flutter
http: ^0.13.0
image: ^4.0.0
image: ^4.0.02
js: ^0.6.3
meta: ">=1.3.0 <2.0.0"
pdf: ^3.9.0
plugin_platform_interface: ^2.0.0
plugin_platform_interface: ^2.1.0
dev_dependencies:
flutter_lints: ^1.0.4
flutter_lints: ^2.0.1
flutter_test:
sdk: flutter
mockito: ^5.0.0
mockito: ^5.3.2
dependency_overrides:
pdf:
... ...