improved performance and battery usage on older devices

This commit is contained in:
2026-09-25 23:58:08 +02:00
parent ed8e52f475
commit 56a497985b
70 changed files with 1631 additions and 621 deletions
+25
View File
@@ -0,0 +1,25 @@
import 'package:flutter/widgets.dart';
/// Wraps [provider] so it decodes at most [scale] × the screen's longest
/// physical side (capped at [maxPx]). Camera-sized photos otherwise decode at
/// full resolution — 50–200 MB each — which gets the app killed on
/// low-memory devices.
ImageProvider screenBoundImage(
BuildContext context,
ImageProvider provider, {
double scale = 1,
int maxPx = 4096,
}) {
final bound =
(MediaQuery.sizeOf(context).longestSide *
MediaQuery.devicePixelRatioOf(context) *
scale)
.round()
.clamp(1, maxPx);
return ResizeImage(
provider,
width: bound,
height: bound,
policy: ResizeImagePolicy.fit,
);
}