David PHAM-VAN

Force Flutter 3.7

@@ -333,7 +333,7 @@ class MultiPage extends Page { @@ -333,7 +333,7 @@ class MultiPage extends Page {
333 'You probably need a SpanningWidget or use a single page layout'); 333 'You probably need a SpanningWidget or use a single page layout');
334 } 334 }
335 335
336 - final span = child as SpanningWidget; 336 + final span = child;
337 337
338 if (savedContext != null) { 338 if (savedContext != null) {
339 // Restore saved context 339 // Restore saved context
@@ -9,7 +9,7 @@ screenshots: @@ -9,7 +9,7 @@ screenshots:
9 version: 3.9.0 9 version: 3.9.0
10 10
11 environment: 11 environment:
12 - sdk: ">=2.12.0 <3.0.0" 12 + sdk: ">=2.18.0 <3.0.0"
13 13
14 dependencies: 14 dependencies:
15 archive: ^3.1.0 15 archive: ^3.1.0
@@ -317,10 +317,10 @@ class PrintingPlugin extends PrintingPlatform { @@ -317,10 +317,10 @@ class PrintingPlugin extends PrintingPlatform {
317 js.context['document'].createElement('canvas'); 317 js.context['document'].createElement('canvas');
318 318
319 final context = canvas.getContext('2d') as html.CanvasRenderingContext2D?; 319 final context = canvas.getContext('2d') as html.CanvasRenderingContext2D?;
320 - final _pages = 320 + final computedPages =
321 pages ?? Iterable<int>.generate(numPages, (index) => index); 321 pages ?? Iterable<int>.generate(numPages, (index) => index);
322 322
323 - for (final pageIndex in _pages) { 323 + for (final pageIndex in computedPages) {
324 final page = 324 final page =
325 await promiseToFuture<PdfJsPage>(doc.getPage(pageIndex + 1)); 325 await promiseToFuture<PdfJsPage>(doc.getPage(pageIndex + 1));
326 try { 326 try {
@@ -237,14 +237,14 @@ class PdfPageFormatAction extends StatelessWidget { @@ -237,14 +237,14 @@ class PdfPageFormatAction extends StatelessWidget {
237 final theme = Theme.of(context); 237 final theme = Theme.of(context);
238 final iconColor = theme.primaryIconTheme.color ?? Colors.white; 238 final iconColor = theme.primaryIconTheme.color ?? Colors.white;
239 final data = PdfPreviewController.listen(context); 239 final data = PdfPreviewController.listen(context);
240 - final _pageFormats = <String, PdfPageFormat>{...pageFormats}; 240 + final allPageFormats = <String, PdfPageFormat>{...pageFormats};
241 241
242 var format = data.pageFormat; 242 var format = data.pageFormat;
243 final orientation = data.horizontal; 243 final orientation = data.horizontal;
244 244
245 - if (!_pageFormats.values.contains(data.pageFormat)) { 245 + if (!allPageFormats.values.contains(data.pageFormat)) {
246 var found = false; 246 var found = false;
247 - for (final f in _pageFormats.values) { 247 + for (final f in allPageFormats.values) {
248 if (format.portrait == f.portrait) { 248 if (format.portrait == f.portrait) {
249 format = f; 249 format = f;
250 found = true; 250 found = true;
@@ -252,11 +252,11 @@ class PdfPageFormatAction extends StatelessWidget { @@ -252,11 +252,11 @@ class PdfPageFormatAction extends StatelessWidget {
252 } 252 }
253 } 253 }
254 if (!found) { 254 if (!found) {
255 - _pageFormats['---'] = format; 255 + allPageFormats['---'] = format;
256 } 256 }
257 } 257 }
258 258
259 - final keys = _pageFormats.keys.toList()..sort(); 259 + final keys = allPageFormats.keys.toList()..sort();
260 260
261 return DropdownButton<PdfPageFormat>( 261 return DropdownButton<PdfPageFormat>(
262 dropdownColor: theme.primaryColor, 262 dropdownColor: theme.primaryColor,
@@ -266,10 +266,10 @@ class PdfPageFormatAction extends StatelessWidget { @@ -266,10 +266,10 @@ class PdfPageFormatAction extends StatelessWidget {
266 ), 266 ),
267 value: format, 267 value: format,
268 items: List<DropdownMenuItem<PdfPageFormat>>.generate( 268 items: List<DropdownMenuItem<PdfPageFormat>>.generate(
269 - _pageFormats.length, 269 + allPageFormats.length,
270 (int index) { 270 (int index) {
271 final key = keys[index]; 271 final key = keys[index];
272 - final val = _pageFormats[key]!; 272 + final val = allPageFormats[key]!;
273 return DropdownMenuItem<PdfPageFormat>( 273 return DropdownMenuItem<PdfPageFormat>(
274 value: val, 274 value: val,
275 child: Text(key, style: TextStyle(color: iconColor)), 275 child: Text(key, style: TextStyle(color: iconColor)),
@@ -67,12 +67,9 @@ class PdfPreviewData extends ChangeNotifier { @@ -67,12 +67,9 @@ class PdfPreviewData extends ChangeNotifier {
67 PdfPageFormat get actualPageFormat => _onComputeActualPageFormat(); 67 PdfPageFormat get actualPageFormat => _onComputeActualPageFormat();
68 68
69 String get localPageFormat { 69 String get localPageFormat {
70 - // Flutter 3 workaround  
71 - // ignore: omit_local_variable_types  
72 - final WidgetsBinding? wbi = WidgetsBinding.instance;  
73 - final locale = wbi!.window.locale;  
74 - // ignore: unnecessary_cast  
75 - final cc = (locale as Locale?)?.countryCode ?? 'US'; 70 + final wbi = WidgetsBinding.instance;
  71 + final locale = wbi.window.locale;
  72 + final cc = locale.countryCode ?? 'US';
76 73
77 if (cc == 'US' || cc == 'CA' || cc == 'MX') { 74 if (cc == 'US' || cc == 'CA' || cc == 'MX') {
78 return 'Letter'; 75 return 'Letter';
@@ -157,9 +157,9 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom> @@ -157,9 +157,9 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom>
157 void didChangeDependencies() { 157 void didChangeDependencies() {
158 if (!infoLoaded) { 158 if (!infoLoaded) {
159 infoLoaded = true; 159 infoLoaded = true;
160 - Printing.info().then((PrintingInfo _info) { 160 + Printing.info().then((PrintingInfo printingInfo) {
161 setState(() { 161 setState(() {
162 - info = _info; 162 + info = printingInfo;
163 raster(); 163 raster();
164 }); 164 });
165 }); 165 });
@@ -182,8 +182,8 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom> @@ -182,8 +182,8 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom>
182 return _showError(error!); 182 return _showError(error!);
183 } 183 }
184 184
185 - final _info = info;  
186 - if (_info != null && !_info.canRaster) { 185 + final printingInfo = info;
  186 + if (printingInfo != null && !printingInfo.canRaster) {
187 return _showError(_errorMessage); 187 return _showError(_errorMessage);
188 } 188 }
189 189
@@ -228,10 +228,10 @@ class PdfPreview extends StatefulWidget { @@ -228,10 +228,10 @@ class PdfPreview extends StatefulWidget {
228 final CustomPdfPagesBuilder? _pagesBuilder; 228 final CustomPdfPagesBuilder? _pagesBuilder;
229 229
230 @override 230 @override
231 - _PdfPreviewState createState() => _PdfPreviewState(); 231 + PdfPreviewState createState() => PdfPreviewState();
232 } 232 }
233 233
234 -class _PdfPreviewState extends State<PdfPreview> { 234 +class PdfPreviewState extends State<PdfPreview> {
235 final previewWidget = GlobalKey<PdfPreviewCustomState>(); 235 final previewWidget = GlobalKey<PdfPreviewCustomState>();
236 late PdfPreviewData previewData; 236 late PdfPreviewData previewData;
237 237
@@ -305,9 +305,9 @@ class _PdfPreviewState extends State<PdfPreview> { @@ -305,9 +305,9 @@ class _PdfPreviewState extends State<PdfPreview> {
305 void didChangeDependencies() { 305 void didChangeDependencies() {
306 if (!infoLoaded) { 306 if (!infoLoaded) {
307 infoLoaded = true; 307 infoLoaded = true;
308 - Printing.info().then((PrintingInfo _info) { 308 + Printing.info().then((PrintingInfo printingInfo) {
309 setState(() { 309 setState(() {
310 - info = _info; 310 + info = printingInfo;
311 }); 311 });
312 }); 312 });
313 } 313 }
@@ -100,10 +100,10 @@ mixin PdfPreviewRaster on State<PdfPreviewCustom> { @@ -100,10 +100,10 @@ mixin PdfPreviewRaster on State<PdfPreviewCustom> {
100 } 100 }
101 _rastering = true; 101 _rastering = true;
102 102
103 - Uint8List _doc; 103 + Uint8List doc;
104 104
105 - final _info = info;  
106 - if (_info != null && !_info.canRaster) { 105 + final printingInfo = info;
  106 + if (printingInfo != null && !printingInfo.canRaster) {
107 assert(() { 107 assert(() {
108 if (kIsWeb) { 108 if (kIsWeb) {
109 FlutterError.reportError(FlutterErrorDetails( 109 FlutterError.reportError(FlutterErrorDetails(
@@ -122,7 +122,7 @@ mixin PdfPreviewRaster on State<PdfPreviewCustom> { @@ -122,7 +122,7 @@ mixin PdfPreviewRaster on State<PdfPreviewCustom> {
122 } 122 }
123 123
124 try { 124 try {
125 - _doc = await widget.build(pageFormat); 125 + doc = await widget.build(pageFormat);
126 } catch (exception, stack) { 126 } catch (exception, stack) {
127 InformationCollector? collector; 127 InformationCollector? collector;
128 128
@@ -159,7 +159,7 @@ mixin PdfPreviewRaster on State<PdfPreviewCustom> { @@ -159,7 +159,7 @@ mixin PdfPreviewRaster on State<PdfPreviewCustom> {
159 try { 159 try {
160 var pageNum = 0; 160 var pageNum = 0;
161 await for (final PdfRaster page in Printing.raster( 161 await for (final PdfRaster page in Printing.raster(
162 - _doc, 162 + doc,
163 dpi: dpi, 163 dpi: dpi,
164 pages: widget.pages, 164 pages: widget.pages,
165 )) { 165 )) {
@@ -74,9 +74,9 @@ mixin Printing { @@ -74,9 +74,9 @@ mixin Printing {
74 Rect? bounds, 74 Rect? bounds,
75 String? title, 75 String? title,
76 }) async { 76 }) async {
77 - final _info = await info(); 77 + final printingInfo = await info();
78 78
79 - if (_info.canListPrinters) { 79 + if (printingInfo.canListPrinters) {
80 final printers = await listPrinters(); 80 final printers = await listPrinters();
81 printers.sort((a, b) { 81 printers.sort((a, b) {
82 if (a.isDefault) { 82 if (a.isDefault) {
@@ -88,6 +88,7 @@ mixin Printing { @@ -88,6 +88,7 @@ mixin Printing {
88 return a.name.compareTo(b.name); 88 return a.name.compareTo(b.name);
89 }); 89 });
90 90
  91 + // ignore: use_build_context_synchronously
91 return await showDialog<Printer>( 92 return await showDialog<Printer>(
92 context: context, 93 context: context,
93 builder: (context) => SimpleDialog( 94 builder: (context) => SimpleDialog(
@@ -144,31 +144,32 @@ class WidgetWrapper extends pw.ImageProvider { @@ -144,31 +144,32 @@ class WidgetWrapper extends pw.ImageProvider {
144 child: widget, 144 child: widget,
145 ); 145 );
146 146
147 - final _properties = DiagnosticPropertiesBuilder();  
148 - widget.debugFillProperties(_properties); 147 + final prop = DiagnosticPropertiesBuilder();
  148 + widget.debugFillProperties(prop);
149 149
150 - if (_properties.properties.isEmpty) { 150 + if (prop.properties.isEmpty) {
151 throw ErrorDescription('Unable to get the widget properties'); 151 throw ErrorDescription('Unable to get the widget properties');
152 } 152 }
153 153
154 - final _constraints = _properties.properties 154 + final computedConstraints = prop.properties
155 .whereType<DiagnosticsProperty<BoxConstraints>>() 155 .whereType<DiagnosticsProperty<BoxConstraints>>()
156 .first 156 .first
157 .value; 157 .value;
158 158
159 - if (_constraints == null ||  
160 - !_constraints.hasBoundedWidth ||  
161 - !_constraints.hasBoundedWidth) { 159 + if (computedConstraints == null ||
  160 + !computedConstraints.hasBoundedWidth ||
  161 + !computedConstraints.hasBoundedWidth) {
162 throw Exception('Unable to convert an unbounded widget.'); 162 throw Exception('Unable to convert an unbounded widget.');
163 } 163 }
164 164
165 - final _repaintBoundary = RenderRepaintBoundary(); 165 + final repaintBoundary = RenderRepaintBoundary();
166 166
167 final renderView = RenderView( 167 final renderView = RenderView(
168 child: RenderPositionedBox( 168 child: RenderPositionedBox(
169 - alignment: Alignment.center, child: _repaintBoundary), 169 + alignment: Alignment.center, child: repaintBoundary),
170 configuration: ViewConfiguration( 170 configuration: ViewConfiguration(
171 - size: Size(_constraints.maxWidth, _constraints.maxHeight), 171 + size:
  172 + Size(computedConstraints.maxWidth, computedConstraints.maxHeight),
172 devicePixelRatio: ui.window.devicePixelRatio), 173 devicePixelRatio: ui.window.devicePixelRatio),
173 window: ui.window, 174 window: ui.window,
174 ); 175 );
@@ -177,8 +178,8 @@ class WidgetWrapper extends pw.ImageProvider { @@ -177,8 +178,8 @@ class WidgetWrapper extends pw.ImageProvider {
177 renderView.prepareInitialFrame(); 178 renderView.prepareInitialFrame();
178 179
179 final buildOwner = BuildOwner(focusManager: FocusManager()); 180 final buildOwner = BuildOwner(focusManager: FocusManager());
180 - final _rootElement = RenderObjectToWidgetAdapter<RenderBox>(  
181 - container: _repaintBoundary, 181 + final rootElement = RenderObjectToWidgetAdapter<RenderBox>(
  182 + container: repaintBoundary,
182 child: Directionality( 183 child: Directionality(
183 textDirection: TextDirection.ltr, 184 textDirection: TextDirection.ltr,
184 child: IntrinsicHeight(child: IntrinsicWidth(child: widget)), 185 child: IntrinsicHeight(child: IntrinsicWidth(child: widget)),
@@ -186,7 +187,7 @@ class WidgetWrapper extends pw.ImageProvider { @@ -186,7 +187,7 @@ class WidgetWrapper extends pw.ImageProvider {
186 ).attachToRenderTree(buildOwner); 187 ).attachToRenderTree(buildOwner);
187 188
188 buildOwner 189 buildOwner
189 - ..buildScope(_rootElement) 190 + ..buildScope(rootElement)
190 ..finalizeTree(); 191 ..finalizeTree();
191 192
192 pipelineOwner 193 pipelineOwner
@@ -194,7 +195,7 @@ class WidgetWrapper extends pw.ImageProvider { @@ -194,7 +195,7 @@ class WidgetWrapper extends pw.ImageProvider {
194 ..flushCompositingBits() 195 ..flushCompositingBits()
195 ..flushPaint(); 196 ..flushPaint();
196 197
197 - final image = await _repaintBoundary.toImage(pixelRatio: pixelRatio); 198 + final image = await repaintBoundary.toImage(pixelRatio: pixelRatio);
198 final bytes = await image.toByteData(format: ui.ImageByteFormat.rawRgba); 199 final bytes = await image.toByteData(format: ui.ImageByteFormat.rawRgba);
199 if (bytes == null) { 200 if (bytes == null) {
200 throw Exception('Unable to read image data'); 201 throw Exception('Unable to read image data');
@@ -12,8 +12,8 @@ screenshots: @@ -12,8 +12,8 @@ screenshots:
12 version: 5.10.0 12 version: 5.10.0
13 13
14 environment: 14 environment:
15 - sdk: ">=2.12.0 <3.0.0"  
16 - flutter: ">=1.16.0" 15 + sdk: ">=2.18.0 <3.0.0"
  16 + flutter: ">=3.7.0"
17 17
18 dependencies: 18 dependencies:
19 ffi: ">=1.1.0 <3.0.0" 19 ffi: ">=1.1.0 <3.0.0"
@@ -22,17 +22,17 @@ dependencies: @@ -22,17 +22,17 @@ dependencies:
22 flutter_web_plugins: 22 flutter_web_plugins:
23 sdk: flutter 23 sdk: flutter
24 http: ^0.13.0 24 http: ^0.13.0
25 - image: ^4.0.0 25 + image: ^4.0.02
26 js: ^0.6.3 26 js: ^0.6.3
27 meta: ">=1.3.0 <2.0.0" 27 meta: ">=1.3.0 <2.0.0"
28 pdf: ^3.9.0 28 pdf: ^3.9.0
29 - plugin_platform_interface: ^2.0.0 29 + plugin_platform_interface: ^2.1.0
30 30
31 dev_dependencies: 31 dev_dependencies:
32 - flutter_lints: ^1.0.4 32 + flutter_lints: ^2.0.1
33 flutter_test: 33 flutter_test:
34 sdk: flutter 34 sdk: flutter
35 - mockito: ^5.0.0 35 + mockito: ^5.3.2
36 36
37 dependency_overrides: 37 dependency_overrides:
38 pdf: 38 pdf: