Repository navigation
Commit 9f2f8a4
Add useLogicalPixels to ResizeImage for logical pixel cache sizing (flutter#184549)
fix flutter#56239
Add `useLogicalPixels` to `ResizeImage` and `useLogicalCacheSize` to
`Image.{network, file, asset, memory}` and `FadeInImage.{memoryNetwork,
assetNetwork}` constructors.
When `true`, the cache dimensions are interpreted as logical pixels
rather than physical pixels, so the cached resolution follows the
surrounding device pixel ratio without requiring `BuildContext` at the
call site. Default is `false`; existing callers are unaffected.
<img width="300" alt="example"
src="https://github.com/user-attachments/assets/43c10cd6-8b8e-4c87-93fd-b2be80030af2"
/>
<details>
<summary>app(lib/main.dart)</summary>
```dart
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@OverRide
Widget build(BuildContext context) {
return MaterialApp(home: const MyWidget());
}
}
class MyWidget extends StatelessWidget {
const MyWidget({super.key});
@OverRide
Widget build(BuildContext context) {
final dpr = MediaQuery.devicePixelRatioOf(context);
const url =
'https://images.unsplash.com/photo-1550613097-fe6c2c321cd3'
'?auto=format&fit=crop&w=1200&q=80';
return Scaffold(
appBar: AppBar(title: Text('devicePixelRatio: $dpr')),
body: Center(
child: Column(
spacing: 8,
children: [
const Text('No cacheWidth (reference)'),
Image.network(url, width: 300, fit: BoxFit.cover),
const Text('cacheWidth: 300, useLogicalCacheSize: false'),
Image.network(url, width: 300, fit: BoxFit.cover, cacheWidth: 300),
const Text('cacheWidth: 300, useLogicalCacheSize: true'),
Image.network(
url,
width: 300,
fit: BoxFit.cover,
cacheWidth: 300,
useLogicalCacheSize: true,
),
],
),
),
);
}
}
```
</details>
## Pre-launch Checklist
- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [AI contribution guidelines] and understand my
responsibilities, or I am not using AI tools.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.
If you need help, consider asking for advice on the #hackers-new channel
on [Discord].
**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
Comments from the `gemini-code-assist` bot should not be taken as
authoritative feedback from the Flutter team. If you find its comments
useful you can update your code accordingly, but if you are unsure or
disagree with the feedback, please feel free to wait for a Flutter team
member's review for guidance on which automated comments should be
addressed.
<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[AI contribution guidelines]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
---------
Co-authored-by: Justin McCandless <[email protected]>
Co-authored-by: Victor Sanni <[email protected]>1 parent 65a3f54 commit 9f2f8a4
6 files changed
Lines changed: 305 additions & 22 deletions
File tree
- packages/flutter
- lib/src
- painting
- widgets
- test
- painting
- widgets
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1263 | 1263 | | |
1264 | 1264 | | |
1265 | 1265 | | |
| 1266 | + | |
| 1267 | + | |
1266 | 1268 | | |
1267 | 1269 | | |
1268 | 1270 | | |
1269 | 1271 | | |
1270 | 1272 | | |
1271 | 1273 | | |
| 1274 | + | |
1272 | 1275 | | |
1273 | 1276 | | |
1274 | 1277 | | |
1275 | 1278 | | |
1276 | 1279 | | |
1277 | | - | |
| 1280 | + | |
| 1281 | + | |
1278 | 1282 | | |
1279 | 1283 | | |
1280 | 1284 | | |
1281 | 1285 | | |
1282 | | - | |
| 1286 | + | |
| 1287 | + | |
1283 | 1288 | | |
1284 | 1289 | | |
1285 | 1290 | | |
| |||
1298 | 1303 | | |
1299 | 1304 | | |
1300 | 1305 | | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
1301 | 1322 | | |
1302 | 1323 | | |
1303 | 1324 | | |
1304 | 1325 | | |
1305 | | - | |
| 1326 | + | |
| 1327 | + | |
1306 | 1328 | | |
1307 | 1329 | | |
1308 | 1330 | | |
1309 | | - | |
1310 | | - | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
1311 | 1334 | | |
1312 | | - | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
1313 | 1341 | | |
1314 | 1342 | | |
1315 | 1343 | | |
| |||
1333 | 1361 | | |
1334 | 1362 | | |
1335 | 1363 | | |
1336 | | - | |
1337 | | - | |
| 1364 | + | |
| 1365 | + | |
1338 | 1366 | | |
1339 | 1367 | | |
1340 | 1368 | | |
| |||
1352 | 1380 | | |
1353 | 1381 | | |
1354 | 1382 | | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
1355 | 1386 | | |
1356 | 1387 | | |
1357 | 1388 | | |
| |||
1366 | 1397 | | |
1367 | 1398 | | |
1368 | 1399 | | |
1369 | | - | |
1370 | | - | |
| 1400 | + | |
| 1401 | + | |
1371 | 1402 | | |
1372 | 1403 | | |
1373 | 1404 | | |
| |||
1381 | 1412 | | |
1382 | 1413 | | |
1383 | 1414 | | |
1384 | | - | |
1385 | | - | |
| 1415 | + | |
| 1416 | + | |
1386 | 1417 | | |
1387 | 1418 | | |
1388 | 1419 | | |
| |||
1397 | 1428 | | |
1398 | 1429 | | |
1399 | 1430 | | |
1400 | | - | |
1401 | | - | |
1402 | | - | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
1403 | 1434 | | |
1404 | | - | |
1405 | | - | |
| 1435 | + | |
| 1436 | + | |
1406 | 1437 | | |
1407 | 1438 | | |
1408 | 1439 | | |
| |||
1443 | 1474 | | |
1444 | 1475 | | |
1445 | 1476 | | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
1446 | 1480 | | |
1447 | 1481 | | |
1448 | 1482 | | |
| |||
1452 | 1486 | | |
1453 | 1487 | | |
1454 | 1488 | | |
1455 | | - | |
| 1489 | + | |
1456 | 1490 | | |
1457 | 1491 | | |
1458 | 1492 | | |
1459 | | - | |
| 1493 | + | |
| 1494 | + | |
| 1495 | + | |
1460 | 1496 | | |
1461 | 1497 | | |
1462 | 1498 | | |
| |||
1481 | 1517 | | |
1482 | 1518 | | |
1483 | 1519 | | |
1484 | | - | |
| 1520 | + | |
| 1521 | + | |
1485 | 1522 | | |
1486 | 1523 | | |
1487 | 1524 | | |
1488 | | - | |
| 1525 | + | |
| 1526 | + | |
1489 | 1527 | | |
1490 | 1528 | | |
1491 | 1529 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
119 | 124 | | |
120 | 125 | | |
121 | 126 | | |
| |||
158 | 163 | | |
159 | 164 | | |
160 | 165 | | |
| 166 | + | |
161 | 167 | | |
162 | 168 | | |
163 | 169 | | |
164 | 170 | | |
| 171 | + | |
165 | 172 | | |
166 | 173 | | |
167 | 174 | | |
168 | 175 | | |
169 | 176 | | |
| 177 | + | |
170 | 178 | | |
171 | 179 | | |
172 | 180 | | |
| |||
190 | 198 | | |
191 | 199 | | |
192 | 200 | | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
193 | 206 | | |
194 | 207 | | |
195 | 208 | | |
| |||
228 | 241 | | |
229 | 242 | | |
230 | 243 | | |
| 244 | + | |
231 | 245 | | |
232 | 246 | | |
233 | 247 | | |
234 | 248 | | |
235 | 249 | | |
| 250 | + | |
236 | 251 | | |
237 | 252 | | |
238 | 253 | | |
239 | 254 | | |
240 | 255 | | |
| 256 | + | |
241 | 257 | | |
242 | 258 | | |
243 | 259 | | |
244 | 260 | | |
245 | 261 | | |
| 262 | + | |
246 | 263 | | |
247 | 264 | | |
248 | 265 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
405 | 405 | | |
406 | 406 | | |
407 | 407 | | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
408 | 413 | | |
409 | 414 | | |
410 | 415 | | |
| |||
467 | 472 | | |
468 | 473 | | |
469 | 474 | | |
| 475 | + | |
470 | 476 | | |
471 | 477 | | |
472 | 478 | | |
| |||
477 | 483 | | |
478 | 484 | | |
479 | 485 | | |
| 486 | + | |
480 | 487 | | |
481 | 488 | | |
482 | 489 | | |
| |||
505 | 512 | | |
506 | 513 | | |
507 | 514 | | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
508 | 520 | | |
509 | 521 | | |
510 | 522 | | |
| |||
536 | 548 | | |
537 | 549 | | |
538 | 550 | | |
| 551 | + | |
539 | 552 | | |
540 | 553 | | |
541 | 554 | | |
542 | 555 | | |
543 | 556 | | |
544 | 557 | | |
545 | | - | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
546 | 564 | | |
547 | 565 | | |
548 | 566 | | |
| |||
585 | 603 | | |
586 | 604 | | |
587 | 605 | | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
588 | 611 | | |
589 | 612 | | |
590 | 613 | | |
| |||
699 | 722 | | |
700 | 723 | | |
701 | 724 | | |
| 725 | + | |
702 | 726 | | |
703 | 727 | | |
704 | 728 | | |
705 | 729 | | |
706 | 730 | | |
707 | 731 | | |
| 732 | + | |
708 | 733 | | |
709 | 734 | | |
710 | 735 | | |
| |||
738 | 763 | | |
739 | 764 | | |
740 | 765 | | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
741 | 771 | | |
742 | 772 | | |
743 | 773 | | |
| |||
761 | 791 | | |
762 | 792 | | |
763 | 793 | | |
| 794 | + | |
764 | 795 | | |
765 | 796 | | |
766 | 797 | | |
767 | 798 | | |
| 799 | + | |
768 | 800 | | |
769 | 801 | | |
770 | 802 | | |
| |||
0 commit comments