feat: added reusable widget to show user's public language and level, added to participant list items (#1885)
This commit is contained in:
parent
62d5a7190f
commit
939e70ef75
2 changed files with 83 additions and 0 deletions
|
|
@ -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(
|
||||
|
|
|
|||
79
lib/pangea/analytics_misc/level_display_name.dart
Normal file
79
lib/pangea/analytics_misc/level_display_name.dart
Normal file
|
|
@ -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<LevelDisplayName> createState() => LevelDisplayNameState();
|
||||
}
|
||||
|
||||
class LevelDisplayNameState extends State<LevelDisplayName> {
|
||||
PublicProfileModel? _profile;
|
||||
bool _loading = true;
|
||||
String? _error;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_fetchProfile();
|
||||
}
|
||||
|
||||
Future<void> _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: <Widget>[
|
||||
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,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue