Skip to content

Commit 9ee6b4b

Browse files
committed
feat: CTabFolder and CLabel icons support
1 parent 8eb8988 commit 9ee6b4b

2 files changed

Lines changed: 58 additions & 18 deletions

File tree

flutter-lib/lib/src/impl/clabel_evolve.dart

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,40 @@ class CLabelImpl<T extends CLabelSwt, V extends VCLabel>
173173
}
174174

175175
Widget? _buildImageWidget(VImage? image, bool enabled) {
176-
return ImageUtils.buildVImage(
177-
image,
178-
width: image?.imageData?.width?.toDouble() ?? 0,
179-
height: image?.imageData?.height?.toDouble() ?? 0,
180-
enabled: enabled,
181-
constraints: null,
182-
useBinaryImage: true,
183-
renderAsIcon: false,
176+
if (image == null) return null;
177+
final w = image.imageData?.width?.toDouble();
178+
final h = image.imageData?.height?.toDouble();
179+
final validW = (w != null && w > 0) ? w : null;
180+
final validH = (h != null && h > 0) ? h : null;
181+
final imageKey =
182+
image.filename ?? image.imageData?.hashCode.toString() ?? 'no-image';
183+
final futureKey = '${imageKey}_${validW}_${validH}_$enabled';
184+
// sync fallback shown immediately while async loads
185+
final fallback = ImageUtils.buildVImage(
186+
image,
187+
width: validW,
188+
height: validH,
189+
enabled: enabled,
190+
useBinaryImage: true,
191+
renderAsIcon: false,
192+
) ??
193+
const SizedBox.shrink();
194+
return FutureBuilder<Widget?>(
195+
key: ValueKey(futureKey),
196+
future: ImageUtils.buildVImageAsync(
197+
image,
198+
width: validW,
199+
height: validH,
200+
enabled: enabled,
201+
useBinaryImage: true,
202+
renderAsIcon: false,
203+
),
204+
builder: (context, snapshot) {
205+
if (snapshot.connectionState == ConnectionState.done) {
206+
return snapshot.data ?? fallback;
207+
}
208+
return fallback;
209+
},
184210
);
185211
}
186212

flutter-lib/lib/src/impl/ctabitem_evolve.dart

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import 'dart:io';
2-
import 'dart:typed_data' show Uint8List;
3-
41
import 'package:flutter/material.dart';
52
import 'package:flutter/material.dart' as material;
63
import 'package:flutter/widgets.dart';
@@ -24,14 +21,30 @@ class CTabItemImpl<T extends CTabItemSwt, V extends VCTabItem>
2421
CTabFolderThemeExtension folderTheme,
2522
VImage? image,
2623
Color? iconColor,
24+
bool enabled,
2725
) {
28-
return ImageUtils.buildVImage(
29-
image,
30-
size: folderTheme.tabIconSize,
31-
color: iconColor,
32-
enabled: true,
33-
useBinaryImage: true,
34-
renderAsIcon: true,
26+
if (image == null) return null;
27+
final iconSize = folderTheme.tabIconSize;
28+
final imageKey =
29+
image.filename ?? image.imageData?.hashCode.toString() ?? 'no-image';
30+
final futureKey =
31+
'${imageKey}_${iconSize}_${iconColor?.value ?? 'null'}_$enabled';
32+
return FutureBuilder<Widget?>(
33+
key: ValueKey(futureKey),
34+
future: ImageUtils.buildVImageAsync(
35+
image,
36+
size: iconSize,
37+
color: iconColor,
38+
enabled: enabled,
39+
useBinaryImage: true,
40+
renderAsIcon: true,
41+
),
42+
builder: (context, snapshot) {
43+
if (snapshot.connectionState == ConnectionState.done) {
44+
return snapshot.data ?? const SizedBox.shrink();
45+
}
46+
return SizedBox(width: iconSize, height: iconSize);
47+
},
3548
);
3649
}
3750

@@ -71,6 +84,7 @@ class CTabItemImpl<T extends CTabItemSwt, V extends VCTabItem>
7184
folderTheme,
7285
state.image,
7386
preserveIconColors ? null : textColor,
87+
isEnabled,
7488
);
7589

7690
return Padding(

0 commit comments

Comments
 (0)