Files
Client/lib/utils/screen_bound_image.dart
T

26 lines
723 B
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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,
);
}