Skip to content

armgit / ente

Public Imported from GitHub
0

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

Show placeholder icons when icon is missing

Neeraj Guptad496adaed20a
diff --git a/lib/theme/colors.dart b/lib/theme/colors.dart
index ef068c9f66..1d4a8517c2 100644
--- a/lib/theme/colors.dart
+++ b/lib/theme/colors.dart
@@ -47,7 +47,7 @@ class EnteColorScheme {
final Color warning800;
final Color caution500;
-
+ final List<Color> avatarColors;
const EnteColorScheme(
this.backgroundBase,
this.backgroundElevated,
@@ -69,7 +69,8 @@ class EnteColorScheme {
this.strokeFainter,
this.blurStrokeBase,
this.blurStrokeFaint,
- this.blurStrokePressed, {
+ this.blurStrokePressed,
+ this.avatarColors, {
this.primaryGreen = _primaryGreen,
this.primary700 = _primary700,
this.primary500 = _primary500,
@@ -105,6 +106,7 @@ const EnteColorScheme lightScheme = EnteColorScheme(
blurStrokeBaseLight,
blurStrokeFaintLight,
blurStrokePressedLight,
+ avatarLight,
);
const EnteColorScheme darkScheme = EnteColorScheme(
@@ -129,6 +131,7 @@ const EnteColorScheme darkScheme = EnteColorScheme(
blurStrokeBaseDark,
blurStrokeFaintDark,
blurStrokePressedDark,
+ avatarDark,
);
// Background Colors
@@ -204,3 +207,55 @@ const Color warning500 = Color.fromRGBO(255, 101, 101, 1);
const Color _warning400 = Color.fromRGBO(255, 111, 111, 1);
const Color _caution500 = Color.fromRGBO(255, 194, 71, 1);
+
+const List<Color> avatarLight = [
+ Color.fromRGBO(118, 84, 154, 1),
+ Color.fromRGBO(223, 120, 97, 1),
+ Color.fromRGBO(148, 180, 159, 1),
+ Color.fromRGBO(135, 162, 251, 1),
+ Color.fromRGBO(198, 137, 198, 1),
+ Color.fromRGBO(198, 137, 198, 1),
+ Color.fromRGBO(50, 82, 136, 1),
+ Color.fromRGBO(133, 180, 224, 1),
+ Color.fromRGBO(193, 163, 163, 1),
+ Color.fromRGBO(193, 163, 163, 1),
+ Color.fromRGBO(66, 97, 101, 1),
+ Color.fromRGBO(66, 97, 101, 1),
+ Color.fromRGBO(66, 97, 101, 1),
+ Color.fromRGBO(221, 157, 226, 1),
+ Color.fromRGBO(130, 171, 139, 1),
+ Color.fromRGBO(155, 187, 232, 1),
+ Color.fromRGBO(143, 190, 190, 1),
+ Color.fromRGBO(138, 195, 161, 1),
+ Color.fromRGBO(168, 176, 242, 1),
+ Color.fromRGBO(176, 198, 149, 1),
+ Color.fromRGBO(233, 154, 173, 1),
+ Color.fromRGBO(209, 132, 132, 1),
+ Color.fromRGBO(120, 181, 167, 1),
+];
+
+const List<Color> avatarDark = [
+ Color.fromRGBO(118, 84, 154, 1),
+ Color.fromRGBO(223, 120, 97, 1),
+ Color.fromRGBO(148, 180, 159, 1),
+ Color.fromRGBO(135, 162, 251, 1),
+ Color.fromRGBO(198, 137, 198, 1),
+ Color.fromRGBO(147, 125, 194, 1),
+ Color.fromRGBO(50, 82, 136, 1),
+ Color.fromRGBO(133, 180, 224, 1),
+ Color.fromRGBO(193, 163, 163, 1),
+ Color.fromRGBO(225, 160, 89, 1),
+ Color.fromRGBO(66, 97, 101, 1),
+ Color.fromRGBO(107, 119, 178, 1),
+ Color.fromRGBO(149, 127, 239, 1),
+ Color.fromRGBO(221, 157, 226, 1),
+ Color.fromRGBO(130, 171, 139, 1),
+ Color.fromRGBO(155, 187, 232, 1),
+ Color.fromRGBO(143, 190, 190, 1),
+ Color.fromRGBO(138, 195, 161, 1),
+ Color.fromRGBO(168, 176, 242, 1),
+ Color.fromRGBO(176, 198, 149, 1),
+ Color.fromRGBO(233, 154, 173, 1),
+ Color.fromRGBO(209, 132, 132, 1),
+ Color.fromRGBO(120, 181, 167, 1),
+];
diff --git a/lib/ui/code_widget.dart b/lib/ui/code_widget.dart
index 7641e6d0f6..6494df5cf7 100644
--- a/lib/ui/code_widget.dart
+++ b/lib/ui/code_widget.dart
@@ -325,6 +325,7 @@ class _CodeWidgetState extends State<CodeWidget> {
? const EdgeInsets.only(left: 16)
: const EdgeInsets.all(0),
child: IconUtils.instance.getIcon(
+ context,
safeDecode(widget.code.issuer).trim(),
width: _shouldShowLargeIcon ? 42 : 24,
),
diff --git a/lib/ui/utils/icon_utils.dart b/lib/ui/utils/icon_utils.dart
index a1a9246585..cfb6cc29ec 100644
--- a/lib/ui/utils/icon_utils.dart
+++ b/lib/ui/utils/icon_utils.dart
@@ -1,8 +1,8 @@
import 'dart:convert';
+import 'package:ente_auth/theme/ente_theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
-import 'package:flutter/widgets.dart';
import 'package:flutter_svg/svg.dart';
class IconUtils {
@@ -19,6 +19,7 @@ class IconUtils {
}
Widget getIcon(
+ BuildContext context,
String provider, {
double width = 24,
}) {
@@ -37,6 +38,25 @@ class IconUtils {
_simpleIcons[title],
width,
);
+ } else if (title.isNotEmpty) {
+ return SizedBox(
+ width: width + 6,
+ child: CircleAvatar(
+ backgroundColor: getEnteColorScheme(context).avatarColors[
+ title.hashCode % getEnteColorScheme(context).avatarColors.length],
+ child: Text(
+ title.toUpperCase()[0],
+ // fixed color
+ style: width > 24
+ ? getEnteTextTheme(context)
+ .largeBold
+ .copyWith(color: Colors.white)
+ : getEnteTextTheme(context)
+ .bodyBold
+ .copyWith(color: Colors.white),
+ ),
+ ),
+ );
} else {
return const SizedBox.shrink();
}