From dafbf081152a890e1ae34096aa9f081296f0f814 Mon Sep 17 00:00:00 2001 From: DASHU <385321165@qq.com> Date: Tue, 22 Jul 2025 21:48:14 +0800 Subject: [PATCH] user name component add show both support --- .../auth_dialog_base_componnet.dart | 6 +++++- lib/component/user/user_name_component.dart | 18 +++++++++++++++--- lib/router/app_detail/app_detail_router.dart | 9 +++++---- lib/router/apps/add_remote_app_router.dart | 6 +++++- lib/router/keys/keys_item_component.dart | 11 ++++++++--- 5 files changed, 38 insertions(+), 12 deletions(-) diff --git a/lib/component/auth_dialog/auth_dialog_base_componnet.dart b/lib/component/auth_dialog/auth_dialog_base_componnet.dart index 2aaeec0..b63e63e 100644 --- a/lib/component/auth_dialog/auth_dialog_base_componnet.dart +++ b/lib/component/auth_dialog/auth_dialog_base_componnet.dart @@ -64,7 +64,11 @@ class _AuthDialog extends State { for (var pubkey in pubkeys) { items.add(DropdownMenuItem( value: pubkey, - child: UserNameComponent(pubkey), + child: UserNameComponent( + pubkey, + showBoth: true, + fullNpubName: true, + ), )); } diff --git a/lib/component/user/user_name_component.dart b/lib/component/user/user_name_component.dart index d9decf9..0c2cf0d 100644 --- a/lib/component/user/user_name_component.dart +++ b/lib/component/user/user_name_component.dart @@ -10,7 +10,10 @@ class UserNameComponent extends StatefulWidget { bool fullNpubName; - UserNameComponent(this.pubkey, {this.fullNpubName = false}); + bool showBoth; + + UserNameComponent(this.pubkey, + {this.fullNpubName = false, this.showBoth = false}); @override State createState() { @@ -30,10 +33,19 @@ class _UserNameComponent extends State { var name = npub; if (metadata != null) { + String? niceName; if (StringUtil.isNotBlank(metadata.displayName)) { - name = metadata.displayName!; + niceName = metadata.displayName!; } else if (StringUtil.isNotBlank(metadata.name)) { - name = metadata.name!; + niceName = metadata.name!; + } + + if (StringUtil.isNotBlank(niceName)) { + if (widget.showBoth) { + name = "$niceName / $npub"; + } else { + name = niceName!; + } } } diff --git a/lib/router/app_detail/app_detail_router.dart b/lib/router/app_detail/app_detail_router.dart index f3b2675..ad3b4d4 100644 --- a/lib/router/app_detail/app_detail_router.dart +++ b/lib/router/app_detail/app_detail_router.dart @@ -3,6 +3,7 @@ import 'package:nostr_sdk/nip19/nip19.dart'; import 'package:nostr_sdk/utils/string_util.dart'; import 'package:nowser/component/app/app_type_component.dart'; import 'package:nowser/component/image_component.dart'; +import 'package:nowser/component/user/user_name_component.dart'; import 'package:nowser/const/connect_type.dart'; import 'package:nowser/data/app.dart'; import 'package:nowser/main.dart'; @@ -120,10 +121,10 @@ class _AppDetailRouter extends State { for (var pubkey in pubkeys) { items.add(DropdownMenuItem( value: pubkey, - child: Text( - Nip19.encodePubKey(pubkey), - maxLines: 1, - overflow: TextOverflow.ellipsis, + child: UserNameComponent( + pubkey, + fullNpubName: true, + showBoth: true, ), )); } diff --git a/lib/router/apps/add_remote_app_router.dart b/lib/router/apps/add_remote_app_router.dart index 404e9f9..093bbe3 100644 --- a/lib/router/apps/add_remote_app_router.dart +++ b/lib/router/apps/add_remote_app_router.dart @@ -74,7 +74,11 @@ class _AddRemoteAppRouter extends CustState { for (var pubkey in pubkeys) { items.add(DropdownMenuItem( value: pubkey, - child: UserNameComponent(pubkey), + child: UserNameComponent( + pubkey, + showBoth: true, + fullNpubName: true, + ), )); } diff --git a/lib/router/keys/keys_item_component.dart b/lib/router/keys/keys_item_component.dart index 3480f35..5670fa8 100644 --- a/lib/router/keys/keys_item_component.dart +++ b/lib/router/keys/keys_item_component.dart @@ -36,10 +36,15 @@ class _KeysItemComponent extends State { ), )); list.add(Expanded( + child: Container( + margin: const EdgeInsets.only(left: Base.BASE_PADDING_HALF), child: UserNameComponent( - widget.pubkey, - fullNpubName: true, - ))); + widget.pubkey, + fullNpubName: true, + showBoth: true, + ), + ), + )); list.add(GestureDetector( onTap: () { keyProvider.removeKey(widget.pubkey);