From d921f6176bb3bdcf044ed0a7c1ea7293a2da2da7 Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Fri, 4 Apr 2025 18:29:57 +0800 Subject: [PATCH] opt: get cacheSize Signed-off-by: bggRGjQaUbCoE --- lib/common/widgets/network_img_layer.dart | 3 +-- lib/utils/extension.dart | 9 ++++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/common/widgets/network_img_layer.dart b/lib/common/widgets/network_img_layer.dart index f7531cc49..e56c3bd4c 100644 --- a/lib/common/widgets/network_img_layer.dart +++ b/lib/common/widgets/network_img_layer.dart @@ -83,7 +83,6 @@ class NetworkImgLayer extends StatelessWidget { } Widget placeholder(BuildContext context) { - int cacheWidth = width.cacheSize(context); return Container( width: width, height: height, @@ -106,7 +105,7 @@ class NetworkImgLayer extends StatelessWidget { : 'assets/images/loading.png', width: width, height: height, - cacheWidth: cacheWidth == 0 ? null : cacheWidth, + cacheWidth: width.cacheSize(context), // cacheHeight: height.cacheSize(context), ), ), diff --git a/lib/utils/extension.dart b/lib/utils/extension.dart index ecc1da14a..03f4fbd86 100644 --- a/lib/utils/extension.dart +++ b/lib/utils/extension.dart @@ -4,9 +4,12 @@ import 'package:floating/floating.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; -extension ImageExtension on num { - int cacheSize(BuildContext context) { - return (this * MediaQuery.of(context).devicePixelRatio).round(); +extension ImageExtension on num? { + int? cacheSize(BuildContext context) { + if (this == null || this == 0) { + return null; + } + return (this! * MediaQuery.of(context).devicePixelRatio).round(); } }