瀏覽代碼

Add widget to display participant avatar

Neeraj Gupta 2 年之前
父節點
當前提交
4e3af9697c
共有 2 個文件被更改,包括 48 次插入0 次删除
  1. 0 0
      lib/ui/sharing/participant_picture_widget.dart
  2. 48 0
      lib/ui/sharing/user_avator_widget.dart

+ 0 - 0
lib/ui/sharing/participant_picture_widget.dart


+ 48 - 0
lib/ui/sharing/user_avator_widget.dart

@@ -0,0 +1,48 @@
+import 'package:flutter/material.dart';
+import 'package:photos/models/collection.dart';
+import 'package:photos/theme/colors.dart';
+import 'package:photos/theme/ente_theme.dart';
+
+class UserAvatarWidget extends StatelessWidget {
+  final User user;
+  final double size;
+  final int currentUserID;
+
+  const UserAvatarWidget(
+    this.user,
+    this.currentUserID, {
+    super.key,
+    this.size = 24,
+  });
+
+  @override
+  Widget build(BuildContext context) {
+    final enteTextTheme = getEnteTextTheme(context);
+    final colorScheme = getEnteColorScheme(context);
+    final displayChar = (user.name == null || user.name!.isEmpty)
+        ? user.email.substring(0, 1)
+        : user.name!.substring(0, 1);
+    final randomColor = colorScheme.avatarColors[
+        (user.id ?? 0).remainder(colorScheme.avatarColors.length)];
+    final Color decorationColor =
+        ((user.id ?? -1) == currentUserID) ? Colors.black : randomColor;
+    return Container(
+      height: size,
+      width: size,
+      padding: const EdgeInsets.all(2),
+      decoration: BoxDecoration(
+        shape: BoxShape.circle,
+        color: decorationColor,
+        border: Border.all(
+          color: colorScheme.strokeBase,
+          width: 1.0,
+        ),
+      ),
+      child: Text(
+        displayChar.toUpperCase(),
+        style: enteTextTheme.mini.copyWith(color: textBaseLight),
+        textAlign: TextAlign.center,
+      ),
+    );
+  }
+}