26 lines
723 B
Dart
26 lines
723 B
Dart
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,
|
||
);
|
||
}
|