main
dart 75 lines 2 KB
Raw
1 import 'package:flutter/material.dart';
2 import 'package:hugeicons/hugeicons.dart';
3
4 import '../models/enums.dart';
5
6 class ServerLogo extends StatelessWidget {
7 final ServerType type;
8 final double size;
9 final double? borderRadius;
10 final Color? iconColor;
11 final List<List<dynamic>>? customIcon;
12
13 const ServerLogo({
14 super.key,
15 required this.type,
16 this.size = 24,
17 this.borderRadius,
18 this.iconColor,
19 this.customIcon,
20 });
21
22 static List<List<dynamic>> defaultHugeIconForType(ServerType type) {
23 switch (type) {
24 case ServerType.lmStudio:
25 return HugeIcons.strokeRoundedComputerTerminal01;
26 case ServerType.openAICompatible:
27 return HugeIcons.strokeRoundedApi;
28 case ServerType.ollama:
29 return HugeIcons.strokeRoundedRobot01;
30 case ServerType.ollamaCloud:
31 return HugeIcons.strokeRoundedAiCloud;
32 case ServerType.openRouter:
33 return HugeIcons.strokeRoundedCloud;
34 case ServerType.requesty:
35 return HugeIcons.strokeRoundedAiNetwork;
36 case ServerType.onDevice:
37 return HugeIcons.strokeRoundedSmartPhone01;
38 }
39 }
40
41 @override
42 Widget build(BuildContext context) {
43 final theme = Theme.of(context);
44 final fallbackColor = iconColor ?? theme.colorScheme.onSurface;
45
46 if (customIcon != null) {
47 return HugeIcon(icon: customIcon!, size: size, color: fallbackColor);
48 }
49
50 final asset = type.logoAsset;
51 if (asset != null) {
52 final radius = borderRadius ?? (size * 0.22);
53 return ClipRRect(
54 borderRadius: BorderRadius.circular(radius),
55 child: Image.asset(
56 asset,
57 width: size,
58 height: size,
59 fit: BoxFit.contain,
60 errorBuilder: (context, error, stackTrace) => HugeIcon(
61 icon: defaultHugeIconForType(type),
62 size: size,
63 color: fallbackColor,
64 ),
65 ),
66 );
67 }
68
69 return HugeIcon(
70 icon: defaultHugeIconForType(type),
71 size: size,
72 color: fallbackColor,
73 );
74 }
75 }