improved performance and battery usage on older devices
This commit is contained in:
@@ -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,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user