Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

minimal try catches

Prateek Sunal9cc56c9770ec
diff --git a/mobile/apps/auth/lib/ui/custom_icon_page.dart b/mobile/apps/auth/lib/ui/custom_icon_page.dart
index 7d1139ebb7..b2c00f857a 100644
--- a/mobile/apps/auth/lib/ui/custom_icon_page.dart
+++ b/mobile/apps/auth/lib/ui/custom_icon_page.dart
@@ -5,6 +5,7 @@ import 'package:ente_auth/theme/ente_theme.dart';
import 'package:ente_auth/ui/utils/icon_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
+import 'package:logging/logging.dart';
class CustomIconPage extends StatefulWidget {
final Map<String, AllIconData> allIcons;
@@ -178,22 +179,35 @@ class _CustomIconPageState extends State<CustomIconPage> {
String? color = iconData.color;
String? slug = iconData.slug;
Widget iconWidget;
- if (iconType == IconType.simpleIcon) {
- final simpleIconPath = normalizeSimpleIconName(title);
- iconWidget = IconUtils.instance.getSVGIcon(
- "assets/simple-icons/icons/$simpleIconPath.svg",
- title,
- color,
- 40,
- context,
+ try {
+ if (iconType == IconType.simpleIcon) {
+ final simpleIconPath = normalizeSimpleIconName(title);
+ iconWidget = IconUtils.instance.getSVGIcon(
+ "assets/simple-icons/icons/$simpleIconPath.svg",
+ title,
+ color,
+ 40,
+ context,
+ );
+ } else {
+ iconWidget = IconUtils.instance.getSVGIcon(
+ "assets/custom-icons/icons/${slug ?? title}.svg",
+ title,
+ color,
+ 40,
+ context,
+ );
+ }
+ } catch (e, s) {
+ Logger("CustomIconPage").warning(
+ "Failed to render icon '$title'",
+ e,
+ s,
);
- } else {
- iconWidget = IconUtils.instance.getSVGIcon(
- "assets/custom-icons/icons/${slug ?? title}.svg",
- title,
- color,
- 40,
+ iconWidget = IconUtils.instance.getIcon(
context,
+ title,
+ width: 40,
);
}
diff --git a/mobile/apps/auth/lib/ui/utils/icon_utils.dart b/mobile/apps/auth/lib/ui/utils/icon_utils.dart
index 78fe597c50..c0c7604829 100644
--- a/mobile/apps/auth/lib/ui/utils/icon_utils.dart
+++ b/mobile/apps/auth/lib/ui/utils/icon_utils.dart
@@ -42,8 +42,7 @@ class IconUtils {
while (simpleEntry != null && customEntry != null) {
if (simpleEntry.key.compareTo(customEntry.key) <= 0) {
- simpleIconPath =
- "assets/simple-icons/icons/${simpleEntry.key}.svg";
+ simpleIconPath = "assets/simple-icons/icons/${simpleEntry.key}.svg";
if (!processedIconPaths.contains(simpleIconPath)) {
allIcons[simpleEntry.key] = AllIconData(
title: simpleEntry.key,
@@ -52,7 +51,8 @@ class IconUtils {
);
processedIconPaths.add(simpleIconPath);
}
- simpleEntry = simpleIterator.moveNext() ? simpleIterator.current : null;
+ simpleEntry =
+ simpleIterator.moveNext() ? simpleIterator.current : null;
} else {
customIconPath =
"assets/custom-icons/icons/${customEntry.value.slug ?? customEntry.key}.svg";
@@ -164,22 +164,31 @@ class IconUtils {
BuildContext context,
) {
final iconColor = _getAdaptiveColor(color, context);
- return SvgPicture.asset(
- path,
- width: width,
- semanticsLabel: title,
- colorFilter: iconColor != null
- ? ColorFilter.mode(
- iconColor,
- BlendMode.srcIn,
- )
- : null,
- errorBuilder: (context, error, stackTrace) {
- Logger("IconUtils")
- .warning("Failed to load icon $path", error, stackTrace);
- return _fallbackAvatar(title, width, context);
- },
- );
+ try {
+ return SvgPicture.asset(
+ path,
+ width: width,
+ semanticsLabel: title,
+ colorFilter: iconColor != null
+ ? ColorFilter.mode(
+ iconColor,
+ BlendMode.srcIn,
+ )
+ : null,
+ errorBuilder: (context, error, stackTrace) {
+ Logger("IconUtils")
+ .warning("Failed to load icon $path", error, stackTrace);
+ return _fallbackAvatar(title, width, context);
+ },
+ );
+ } catch (e, s) {
+ Logger("IconUtils").warning(
+ "Failed to create SVG icon for '$title' at path '$path'",
+ e,
+ s,
+ );
+ return _fallbackAvatar(title, width, context);
+ }
}
Widget _fallbackAvatar(String provider, double width, BuildContext context) {
@@ -194,9 +203,11 @@ class IconUtils {
child: Text(
providerTitle.toUpperCase()[0],
style: showLargeIcon
- ? getEnteTextTheme(context).h3Bold
+ ? getEnteTextTheme(context)
+ .h3Bold
.copyWith(color: Colors.white, fontSize: width * 0.6)
- : getEnteTextTheme(context).body
+ : getEnteTextTheme(context)
+ .body
.copyWith(color: Colors.white, fontSize: width * 0.6),
),
);