refactor image handling in ProviderOptionTile (#2549)
Serhii committed
Sep 29, 2025 at 15:26 UTC
5c34b6193df49da80b8181b4134682c417508749
1 file changed
+9
-88
lib/src/widgets/provider_optoin_tile.dart
+9
-88
@@ -1,6 +1,5 @@
1
-import 'package:cw_core/utils/proxy_wrapper.dart';
1
+import 'package:cake_wallet/utils/image_utill.dart';
2
import 'package:flutter/material.dart';
3
-import 'package:flutter_svg/svg.dart';
3
4
class ProviderOptionTile extends StatelessWidget {
5
const ProviderOptionTile({
@@ -78,16 +77,16 @@ class ProviderOptionTile extends StatelessWidget {
77
? darkImagePath
78
: lightImagePath
79
: !isLightMode
81
- ? darkImagePath
82
- : lightImagePath;
80
+ ? lightImagePath
81
+ : darkImagePath;
82
83
final rightSubTitleIconPath = isSelected
84
? !isLightMode
85
? rightSubTitleDarkIconPath
86
: rightSubTitleLightIconPath
87
: !isLightMode
89
- ? rightSubTitleDarkIconPath
90
- : rightSubTitleLightIconPath;
88
+ ? rightSubTitleLightIconPath
89
+ : rightSubTitleDarkIconPath;
90
91
return GestureDetector(
92
onTap: onPressed,
@@ -106,8 +105,8 @@ class ProviderOptionTile extends StatelessWidget {
105
children: [
106
Row(
107
children: [
109
- getImage(imagePath,
110
- height: imageHeight, width: imageWidth, imageColor: textColor),
108
+ ImageUtil.getImageFromPath(imagePath:imagePath,
109
+ height: imageHeight, width: imageWidth),
110
SizedBox(width: 8),
111
Expanded(
112
child: Container(
@@ -203,7 +202,7 @@ class subTitleWidget extends StatelessWidget {
202
if (subTitleIconPath != null && subTitleIconPath!.isNotEmpty)
203
Padding(
204
padding: const EdgeInsets.only(right: 6),
206
- child: getImage(subTitleIconPath!),
205
+ child: ImageUtil.getImageFromPath(imagePath: subTitleIconPath!),
206
),
207
Text(
208
leftSubTitle ?? '',
@@ -219,7 +218,7 @@ class subTitleWidget extends StatelessWidget {
218
if (rightSubTitleIconPath != null && rightSubTitleIconPath!.isNotEmpty)
219
Padding(
220
padding: const EdgeInsets.only(right: 4),
222
- child: getImage(rightSubTitleIconPath!, imageColor: textColor),
221
+ child: ImageUtil.getImageFromPath(imagePath: rightSubTitleIconPath!),
222
),
223
Text(
224
rightSubTitle ?? '',
@@ -265,84 +264,6 @@ class Badge extends StatelessWidget {
264
}
265
}
266
268
-Widget getImage(String imagePath, {double? height, double? width, Color? imageColor}) {
269
- bool isNetworkImage = imagePath.startsWith('http') || imagePath.startsWith('https');
270
- if (CakeTor.instance!.enabled && isNetworkImage) {
271
- imagePath = "assets/images/tor_logo.svg";
272
- isNetworkImage = false;
273
- }
274
- final bool isSvg = imagePath.endsWith('.svg');
275
- final double imageHeight = height ?? 35;
276
- final double imageWidth = width ?? 35;
277
-
278
- if (isNetworkImage) {
279
- return isSvg
280
- ? SvgPicture.network(
281
- imagePath,
282
- height: imageHeight,
283
- width: imageWidth,
284
- colorFilter: imageColor != null ? ColorFilter.mode(imageColor, BlendMode.srcIn) : null,
285
- placeholderBuilder: (BuildContext context) => Container(
286
- height: imageHeight,
287
- width: imageWidth,
288
- child: Center(
289
- child: CircularProgressIndicator(),
290
- ),
291
- ),
292
- errorBuilder: (_, __, ___) {
293
- return Container(
294
- height: imageHeight,
295
- width: imageWidth,
296
- child: Center(
297
- child: Icon(Icons.error_outline, color: Colors.grey),
298
- ),
299
- );
300
- },
301
- )
302
- : Image.network(
303
- imagePath,
304
- height: imageHeight,
305
- width: imageWidth,
306
- loadingBuilder: (BuildContext context, Widget child, ImageChunkEvent? loadingProgress) {
307
- if (loadingProgress == null) {
308
- return child;
309
- }
310
- return Container(
311
- height: imageHeight,
312
- width: imageWidth,
313
- child: Center(
314
- child: CircularProgressIndicator(
315
- value: loadingProgress.expectedTotalBytes != null
316
- ? loadingProgress.cumulativeBytesLoaded /
317
- loadingProgress.expectedTotalBytes!
318
- : null,
319
- ),
320
- ),
321
- );
322
- },
323
- errorBuilder: (BuildContext context, Object exception, StackTrace? stackTrace) {
324
- return Container(
325
- height: imageHeight,
326
- width: imageWidth,
327
- child: Center(
328
- child: Icon(Icons.error_outline, color: Colors.grey),
329
- ),
330
- );
331
- },
332
- );
333
- } else {
334
- return isSvg
335
- ? SvgPicture.asset(
336
- imagePath,
337
- height: imageHeight,
338
- width: imageWidth,
339
- colorFilter: imageColor != null ? ColorFilter.mode(imageColor, BlendMode.srcIn) : null,
340
- errorBuilder: (_, __, ___) => Icon(Icons.error, color: Colors.grey),
341
- )
342
- : Image.asset(imagePath, height: imageHeight, width: imageWidth);
343
- }
344
-}
345
-
267
class OptionTilePlaceholder extends StatefulWidget {
268
OptionTilePlaceholder({
269
this.borderRadius,