From 939e70ef75141141c58c573d319d02ff2181acef Mon Sep 17 00:00:00 2001 From: ggurdin <46800240+ggurdin@users.noreply.github.com> Date: Fri, 21 Feb 2025 14:13:44 -0500 Subject: [PATCH] feat: added reusable widget to show user's public language and level, added to participant list items (#1885) --- .../chat_details/participant_list_item.dart | 4 + .../analytics_misc/level_display_name.dart | 79 +++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 lib/pangea/analytics_misc/level_display_name.dart diff --git a/lib/pages/chat_details/participant_list_item.dart b/lib/pages/chat_details/participant_list_item.dart index 2be366a7c..4b4f27357 100644 --- a/lib/pages/chat_details/participant_list_item.dart +++ b/lib/pages/chat_details/participant_list_item.dart @@ -4,6 +4,7 @@ import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:matrix/matrix.dart'; import 'package:fluffychat/config/app_config.dart'; +import 'package:fluffychat/pangea/analytics_misc/level_display_name.dart'; import 'package:fluffychat/utils/adaptive_bottom_sheet.dart'; import '../../widgets/avatar.dart'; import '../user_bottom_sheet/user_bottom_sheet.dart'; @@ -49,6 +50,9 @@ class ParticipantListItem extends StatelessWidget { overflow: TextOverflow.ellipsis, ), ), + // #Pangea + LevelDisplayName(userId: user.id), + // Pangea# if (permissionBatch.isNotEmpty) Container( padding: const EdgeInsets.symmetric( diff --git a/lib/pangea/analytics_misc/level_display_name.dart b/lib/pangea/analytics_misc/level_display_name.dart new file mode 100644 index 000000000..d13e4860f --- /dev/null +++ b/lib/pangea/analytics_misc/level_display_name.dart @@ -0,0 +1,79 @@ +import 'package:flutter/material.dart'; + +import 'package:fluffychat/pangea/user/models/profile_model.dart'; +import 'package:fluffychat/widgets/matrix.dart'; + +class LevelDisplayName extends StatefulWidget { + final String userId; + const LevelDisplayName({ + required this.userId, + super.key, + }); + + @override + State createState() => LevelDisplayNameState(); +} + +class LevelDisplayNameState extends State { + PublicProfileModel? _profile; + bool _loading = true; + String? _error; + + @override + void initState() { + super.initState(); + _fetchProfile(); + } + + Future _fetchProfile() async { + try { + final userController = MatrixState.pangeaController.userController; + _profile = await userController.getPublicProfile(widget.userId); + } catch (e) { + _error = e.toString(); + } finally { + if (mounted) setState(() => _loading = false); + } + } + + @override + Widget build(BuildContext context) { + return Padding( + padding: const EdgeInsets.symmetric( + horizontal: 8.0, + vertical: 4.0, + ), + child: Row( + children: [ + if (_loading) + const CircularProgressIndicator() + else if (_error != null || _profile == null) + const SizedBox() + else + Row( + spacing: 4.0, + children: [ + if (_profile?.targetLanguage != null) + Text( + _profile!.targetLanguage!.langCode.toUpperCase(), + style: TextStyle( + fontWeight: FontWeight.bold, + color: Theme.of(context).colorScheme.primary, + ), + ), + if (_profile?.level != null) const Text("⭐"), + if (_profile?.level != null) + Text( + "${_profile!.level!}", + style: TextStyle( + fontWeight: FontWeight.bold, + color: Theme.of(context).colorScheme.primary, + ), + ), + ], + ), + ], + ), + ); + } +}