improved performance and battery usage on older devices
This commit is contained in:
1 parent
ed8e52f475
commit
56a497985b
70 files changed
+1631
-621
No files matched your search
@@ -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