Skip to content

PasteFerry (隔空贴): clipboard and file sync across macOS, Windows and Linux. Direct-first, end-to-end encrypted. Optional official access: no server to host. Independent self-hosting remains available.

feat(ui): contacts page in the sidebar

baiyuzea5ade0a7ca2a
diff --git a/ui/lib/l10n/app_en.arb b/ui/lib/l10n/app_en.arb
index 31b1b77..1d87cb1 100644
--- a/ui/lib/l10n/app_en.arb
+++ b/ui/lib/l10n/app_en.arb
@@ -1563,5 +1563,17 @@
"settingsQuickPasteSummary": "Shortcut and what happens after you pick",
"settingsSendSummary": "Receiving files, save location",
"settingsStorageSummary": "How long history is kept, space used",
- "settingsAboutSummary": "Version, updates, feedback"
+ "settingsAboutSummary": "Version, updates, feedback",
+ "friendsSubtitle": "Send files to other people's computers, no pairing needed",
+ "friendsSearch": "Search contacts",
+ "friendsNoMatch": "No matching contacts",
+ "friendsPick": "Pick a contact to see your transfers or send files",
+ "friendDropHint": "Drop files here to send them to {name}",
+ "@friendDropHint": {
+ "placeholders": {
+ "name": {
+ "type": "String"
+ }
+ }
+ }
}
diff --git a/ui/lib/l10n/app_ja.arb b/ui/lib/l10n/app_ja.arb
index 22904d9..d0a3b4c 100644
--- a/ui/lib/l10n/app_ja.arb
+++ b/ui/lib/l10n/app_ja.arb
@@ -610,5 +610,10 @@
"settingsQuickPasteSummary": "ショートカット、選んだ後の動作",
"settingsSendSummary": "ファイルの受信、保存先",
"settingsStorageSummary": "履歴の保存期間と使用量",
- "settingsAboutSummary": "バージョン、アップデート、フィードバック"
+ "settingsAboutSummary": "バージョン、アップデート、フィードバック",
+ "friendsSubtitle": "ほかの人のパソコンにファイルを送れます。ペアリングは不要です",
+ "friendsSearch": "連絡先を検索",
+ "friendsNoMatch": "一致する連絡先はありません",
+ "friendsPick": "連絡先を選ぶと、転送履歴の確認やファイル送信ができます",
+ "friendDropHint": "ここにドロップすると {name} に送ります"
}
diff --git a/ui/lib/l10n/app_localizations.dart b/ui/lib/l10n/app_localizations.dart
index 6eb5942..daada8a 100644
--- a/ui/lib/l10n/app_localizations.dart
+++ b/ui/lib/l10n/app_localizations.dart
@@ -3775,6 +3775,36 @@ abstract class AppLocalizations {
/// In en, this message translates to:
/// **'Version, updates, feedback'**
String get settingsAboutSummary;
+
+ /// No description provided for @friendsSubtitle.
+ ///
+ /// In en, this message translates to:
+ /// **'Send files to other people\'s computers, no pairing needed'**
+ String get friendsSubtitle;
+
+ /// No description provided for @friendsSearch.
+ ///
+ /// In en, this message translates to:
+ /// **'Search contacts'**
+ String get friendsSearch;
+
+ /// No description provided for @friendsNoMatch.
+ ///
+ /// In en, this message translates to:
+ /// **'No matching contacts'**
+ String get friendsNoMatch;
+
+ /// No description provided for @friendsPick.
+ ///
+ /// In en, this message translates to:
+ /// **'Pick a contact to see your transfers or send files'**
+ String get friendsPick;
+
+ /// No description provided for @friendDropHint.
+ ///
+ /// In en, this message translates to:
+ /// **'Drop files here to send them to {name}'**
+ String friendDropHint(String name);
}
class _AppLocalizationsDelegate
diff --git a/ui/lib/l10n/app_localizations_en.dart b/ui/lib/l10n/app_localizations_en.dart
index 36f8510..a32ce51 100644
--- a/ui/lib/l10n/app_localizations_en.dart
+++ b/ui/lib/l10n/app_localizations_en.dart
@@ -2304,4 +2304,23 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get settingsAboutSummary => 'Version, updates, feedback';
+
+ @override
+ String get friendsSubtitle =>
+ 'Send files to other people\'s computers, no pairing needed';
+
+ @override
+ String get friendsSearch => 'Search contacts';
+
+ @override
+ String get friendsNoMatch => 'No matching contacts';
+
+ @override
+ String get friendsPick =>
+ 'Pick a contact to see your transfers or send files';
+
+ @override
+ String friendDropHint(String name) {
+ return 'Drop files here to send them to $name';
+ }
}
diff --git a/ui/lib/l10n/app_localizations_ja.dart b/ui/lib/l10n/app_localizations_ja.dart
index d5a7025..0bf3563 100644
--- a/ui/lib/l10n/app_localizations_ja.dart
+++ b/ui/lib/l10n/app_localizations_ja.dart
@@ -2134,4 +2134,21 @@ class AppLocalizationsJa extends AppLocalizations {
@override
String get settingsAboutSummary => 'バージョン、アップデート、フィードバック';
+
+ @override
+ String get friendsSubtitle => 'ほかの人のパソコンにファイルを送れます。ペアリングは不要です';
+
+ @override
+ String get friendsSearch => '連絡先を検索';
+
+ @override
+ String get friendsNoMatch => '一致する連絡先はありません';
+
+ @override
+ String get friendsPick => '連絡先を選ぶと、転送履歴の確認やファイル送信ができます';
+
+ @override
+ String friendDropHint(String name) {
+ return 'ここにドロップすると $name に送ります';
+ }
}
diff --git a/ui/lib/l10n/app_localizations_zh.dart b/ui/lib/l10n/app_localizations_zh.dart
index b2c7be5..46dfcac 100644
--- a/ui/lib/l10n/app_localizations_zh.dart
+++ b/ui/lib/l10n/app_localizations_zh.dart
@@ -2110,6 +2110,23 @@ class AppLocalizationsZh extends AppLocalizations {
@override
String get settingsAboutSummary => '版本、更新、反馈';
+
+ @override
+ String get friendsSubtitle => '给别人的电脑发文件,不用配对';
+
+ @override
+ String get friendsSearch => '搜索好友';
+
+ @override
+ String get friendsNoMatch => '没有找到这个好友';
+
+ @override
+ String get friendsPick => '选一个好友,查看传输记录或发文件';
+
+ @override
+ String friendDropHint(String name) {
+ return '松开即可发给 $name';
+ }
}
/// The translations for Chinese, as used in Hong Kong, using the Han script (`zh_Hant_HK`).
@@ -4218,6 +4235,23 @@ class AppLocalizationsZhHantHk extends AppLocalizationsZh {
@override
String get settingsAboutSummary => '版本、更新、回報';
+
+ @override
+ String get friendsSubtitle => '傳檔案給別人的電腦,不用配對';
+
+ @override
+ String get friendsSearch => '搜尋好友';
+
+ @override
+ String get friendsNoMatch => '找不到這個好友';
+
+ @override
+ String get friendsPick => '選一個好友,查看傳輸記錄或傳檔案';
+
+ @override
+ String friendDropHint(String name) {
+ return '放開即可傳給 $name';
+ }
}
/// The translations for Chinese, as used in Taiwan, using the Han script (`zh_Hant_TW`).
@@ -6326,4 +6360,21 @@ class AppLocalizationsZhHantTw extends AppLocalizationsZh {
@override
String get settingsAboutSummary => '版本、更新、回報';
+
+ @override
+ String get friendsSubtitle => '傳檔案給別人的電腦,不用配對';
+
+ @override
+ String get friendsSearch => '搜尋好友';
+
+ @override
+ String get friendsNoMatch => '沒有找到這個好友';
+
+ @override
+ String get friendsPick => '選一個好友,查看傳輸記錄或傳檔案';
+
+ @override
+ String friendDropHint(String name) {
+ return '放開即可傳給 $name';
+ }
}
diff --git a/ui/lib/l10n/app_zh.arb b/ui/lib/l10n/app_zh.arb
index 39f44d9..7dbe8b5 100644
--- a/ui/lib/l10n/app_zh.arb
+++ b/ui/lib/l10n/app_zh.arb
@@ -610,5 +610,10 @@
"settingsQuickPasteSummary": "快捷键、选中后的操作",
"settingsSendSummary": "接收文件、保存位置",
"settingsStorageSummary": "记录保留多久、占用空间",
- "settingsAboutSummary": "版本、更新、反馈"
+ "settingsAboutSummary": "版本、更新、反馈",
+ "friendsSubtitle": "给别人的电脑发文件,不用配对",
+ "friendsSearch": "搜索好友",
+ "friendsNoMatch": "没有找到这个好友",
+ "friendsPick": "选一个好友,查看传输记录或发文件",
+ "friendDropHint": "松开即可发给 {name}"
}
diff --git a/ui/lib/l10n/app_zh_Hant_HK.arb b/ui/lib/l10n/app_zh_Hant_HK.arb
index 9410fb8..569d901 100644
--- a/ui/lib/l10n/app_zh_Hant_HK.arb
+++ b/ui/lib/l10n/app_zh_Hant_HK.arb
@@ -610,5 +610,10 @@
"settingsQuickPasteSummary": "快速鍵、選取後的動作",
"settingsSendSummary": "接收檔案、儲存位置",
"settingsStorageSummary": "記錄保留多久、佔用空間",
- "settingsAboutSummary": "版本、更新、回報"
+ "settingsAboutSummary": "版本、更新、回報",
+ "friendsSubtitle": "傳檔案給別人的電腦,不用配對",
+ "friendsSearch": "搜尋好友",
+ "friendsNoMatch": "找不到這個好友",
+ "friendsPick": "選一個好友,查看傳輸記錄或傳檔案",
+ "friendDropHint": "放開即可傳給 {name}"
}
diff --git a/ui/lib/l10n/app_zh_Hant_TW.arb b/ui/lib/l10n/app_zh_Hant_TW.arb
index 6149df7..54ffd97 100644
--- a/ui/lib/l10n/app_zh_Hant_TW.arb
+++ b/ui/lib/l10n/app_zh_Hant_TW.arb
@@ -610,5 +610,10 @@
"settingsQuickPasteSummary": "快速鍵、選取後的動作",
"settingsSendSummary": "接收檔案、儲存位置",
"settingsStorageSummary": "記錄保留多久、佔用空間",
- "settingsAboutSummary": "版本、更新、回報"
+ "settingsAboutSummary": "版本、更新、回報",
+ "friendsSubtitle": "傳檔案給別人的電腦,不用配對",
+ "friendsSearch": "搜尋好友",
+ "friendsNoMatch": "沒有找到這個好友",
+ "friendsPick": "選一個好友,查看傳輸記錄或傳檔案",
+ "friendDropHint": "放開即可傳給 {name}"
}
diff --git a/ui/lib/main.dart b/ui/lib/main.dart
index 63ceae6..95c2d62 100644
--- a/ui/lib/main.dart
+++ b/ui/lib/main.dart
@@ -10,6 +10,7 @@ import 'i18n.dart';
import 'pages/devices_page.dart';
import 'pages/favorites_page.dart';
import 'pages/history_page.dart';
+import 'pages/friends_page.dart';
import 'pages/send_page.dart';
import 'pages/service_page.dart';
import 'pages/settings_page.dart';
@@ -126,7 +127,7 @@ class AppScope extends InheritedNotifier<AppState> {
context.getInheritedWidgetOfExactType<AppScope>()!.notifier!;
}
-enum Section { history, favorites, send, devices, official, settings }
+enum Section { history, favorites, send, friends, devices, official, settings }
class Shell extends StatefulWidget {
const Shell({super.key, this.initialSection = Section.history});
@@ -179,6 +180,7 @@ class _ShellState extends State<Shell> with WidgetsBindingObserver {
if (state.pageRequestSerial != _seenPageRequest) {
_seenPageRequest = state.pageRequestSerial;
if (state.pageRequest == 'send') _section = Section.send;
+ if (state.pageRequest == 'friends') _section = Section.friends;
if (state.pageRequest == 'settings') _section = Section.settings;
}
if (!state.officialEnabled && _section == Section.official) {
@@ -330,6 +332,7 @@ class _ShellState extends State<Shell> with WidgetsBindingObserver {
Section.history => const HistoryPage(),
Section.favorites => const FavoritesPage(),
Section.send => const SendPage(),
+ Section.friends => const FriendsPage(),
Section.devices => const DevicesPage(),
Section.official => const OfficialServicePage(),
Section.settings => const SettingsPage(),
@@ -404,6 +407,17 @@ class _Sidebar extends StatelessWidget {
trailingWidget: _SendBadge(state: state),
onTap: () => onSelect(Section.send),
),
+ _NavItem(
+ icon: AppIcons.people,
+ label: l.friendsTitle,
+ selected: current == Section.friends,
+ // 好友发来、等你接受的文件
+ trailing: () {
+ final n = state.askingIncoming.where((t) => t.peerRole == 'friend').length;
+ return n == 0 ? null : '$n';
+ }(),
+ onTap: () => onSelect(Section.friends),
+ ),
// 分两组:上面是用的(复制的内容、发文件),下面是管的(设备、服务、设置)
const SizedBox(height: Insets.lg),
_NavItem(
diff --git a/ui/lib/pages/friends_page.dart b/ui/lib/pages/friends_page.dart
new file mode 100644
index 0000000..f60ba0e
--- /dev/null
+++ b/ui/lib/pages/friends_page.dart
@@ -0,0 +1,262 @@
+import 'package:desktop_drop/desktop_drop.dart';
+import 'package:flutter/material.dart';
+
+import '../gen/pasteferry/v1/daemon.pb.dart';
+import '../i18n.dart';
+import '../icons.dart';
+import '../main.dart';
+import '../theme.dart';
+import '../widgets/avatar.dart';
+import '../widgets/common.dart';
+import '../widgets/friends_dialog.dart';
+import '../widgets/send_dialog.dart';
+import 'send_page.dart';
+
+/// 侧边栏的「好友」:左边是好友列表,右边是选中好友的状态、发送与传输记录。
+/// 底部是「允许这些人给我发文件」和本机显示的名字、头像。
+class FriendsPage extends StatefulWidget {
+ const FriendsPage({super.key});
+
+ @override
+ State<FriendsPage> createState() => _FriendsPageState();
+}
+
+class _FriendsPageState extends State<FriendsPage> {
+ final _search = TextEditingController();
+ String _query = '';
+ String? _selected;
+
+ @override
+ void dispose() {
+ _search.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final state = AppScope.of(context);
+ final l = context.l10n;
+ final p = context.palette;
+ final all = sortedFriends(state);
+ final q = _query.trim().toLowerCase();
+ final friends = q.isEmpty
+ ? all
+ : all
+ .where(
+ (f) => f.displayName.toLowerCase().contains(q) || f.deviceName.toLowerCase().contains(q),
+ )
+ .toList();
+ // 选中的好友被删掉了就选第一个
+ final selected = all.where((f) => f.id == _selected).firstOrNull ?? all.firstOrNull;
+
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ PageHeader(
+ title: l.friendsTitle,
+ subtitle: l.friendsSubtitle,
+ actions: [
+ FilledButton.icon(
+ onPressed: () => showAddFriendDialog(context),
+ icon: Icon(AppIcons.personAdd, size: 16),
+ label: Text(l.addFriend),
+ ),
+ ],
+ ),
+ Expanded(
+ child: all.isEmpty
+ ? EmptyState(
+ icon: AppIcons.people,
+ title: l.friendsEmpty,
+ description: l.friendsEmptyBody,
+ action: FilledButton.icon(
+ onPressed: () => showAddFriendDialog(context),
+ icon: Icon(AppIcons.personAdd, size: 16),
+ label: Text(l.addFriend),
+ ),
+ )
+ : Padding(
+ padding: const EdgeInsets.fromLTRB(Insets.xl, 0, Insets.xl, Insets.lg),
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ SizedBox(
+ width: 248,
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ SearchField(
+ controller: _search,
+ hint: l.friendsSearch,
+ clearTooltip: l.searchClear,
+ onChanged: (v) => setState(() => _query = v),
+ ),
+ const SizedBox(height: Insets.sm),
+ Expanded(
+ child: friends.isEmpty
+ ? Center(child: Text(l.friendsNoMatch, style: context.text.bodySmall))
+ : ListView.builder(
+ itemCount: friends.length,
+ itemBuilder: (_, i) => _FriendListRow(
+ friend: friends[i],
+ selected: friends[i].id == selected?.id,
+ onTap: () => setState(() => _selected = friends[i].id),
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ const SizedBox(width: Insets.lg),
+ Expanded(
+ child: Container(
+ decoration: BoxDecoration(
+ color: p.surface,
+ borderRadius: BorderRadius.circular(Radii.md),
+ border: Border.all(color: p.border),
+ ),
+ padding: const EdgeInsets.fromLTRB(Insets.xl, Insets.lg, Insets.md, Insets.md),
+ child: selected == null
+ ? Center(child: Text(l.friendsPick, style: context.text.bodySmall))
+ : _DropToFriend(
+ friend: selected,
+ child: FriendDetail(key: ValueKey(selected.id), friendId: selected.id),
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ const ReceiveFromBar(trailing: ProfileChip()),
+ ],
+ );
+ }
+}
+
+class _FriendListRow extends StatefulWidget {
+ const _FriendListRow({required this.friend, required this.selected, required this.onTap});
+
+ final Friend friend;
+ final bool selected;
+ final VoidCallback onTap;
+
+ @override
+ State<_FriendListRow> createState() => _FriendListRowState();
+}
+
+class _FriendListRowState extends State<_FriendListRow> {
+ bool _hover = false;
+
+ @override
+ Widget build(BuildContext context) {
+ final state = AppScope.of(context);
+ final l = context.l10n;
+ final p = context.palette;
+ final f = widget.friend;
+ final asking = state.askingIncoming.where((t) => t.deviceId == f.id).length;
+ return MouseRegion(
+ cursor: SystemMouseCursors.click,
+ onEnter: (_) => setState(() => _hover = true),
+ onExit: (_) => setState(() => _hover = false),
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: widget.onTap,
+ onSecondaryTapUp: (d) => showFriendMenu(context, f, d.globalPosition),
+ child: Container(
+ margin: const EdgeInsets.only(bottom: 2),
+ padding: const EdgeInsets.symmetric(horizontal: Insets.sm, vertical: 7),
+ decoration: BoxDecoration(
+ color: widget.selected ? p.selection : (_hover ? p.hover : Colors.transparent),
+ borderRadius: BorderRadius.circular(Radii.sm),
+ ),
+ child: Row(
+ children: [
+ Opacity(
+ opacity: f.online ? 1 : 0.55,
+ child: PersonAvatar(deviceId: f.id, name: f.displayName, hash: f.avatarHash, size: 34),
+ ),
+ const SizedBox(width: Insets.sm),
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ f.displayName,
+ style: context.text.labelLarge?.copyWith(
+ fontWeight: widget.selected ? FontWeight.w600 : FontWeight.w500,
+ ),
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ ),
+ Text(
+ friendStatus(l, state, f),
+ style: context.text.labelSmall,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ ),
+ ],
+ ),
+ ),
+ if (asking > 0)
+ Container(
+ padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 1),
+ decoration: BoxDecoration(color: p.accent, borderRadius: BorderRadius.circular(9)),
+ child: Text('$asking', style: context.text.labelSmall?.copyWith(color: Colors.white)),
+ ),
+ ],
+ ),
+ ),
+ ),
+ );
+ }
+}
+
+/// 把文件拖到好友详情上,直接发给他。
+class _DropToFriend extends StatefulWidget {
+ const _DropToFriend({required this.friend, required this.child});
+
+ final Friend friend;
+ final Widget child;
+
+ @override
+ State<_DropToFriend> createState() => _DropToFriendState();
+}
+
+class _DropToFriendState extends State<_DropToFriend> {
+ bool _dropping = false;
+
+ @override
+ Widget build(BuildContext context) {
+ final l = context.l10n;
+ final p = context.palette;
+ final f = widget.friend;
+ final can = friendCanSend(f);
+ return DropTarget(
+ enable: can,
+ onDragEntered: (_) => setState(() => _dropping = true),
+ onDragExited: (_) => setState(() => _dropping = false),
+ onDragDone: (details) {
+ setState(() => _dropping = false);
+ sendFilesById(context, f.id, f.displayName, droppedPaths(details));
+ },
+ child: Stack(
+ children: [
+ widget.child,
+ if (_dropping)
+ Positioned.fill(
+ child: Container(
+ decoration: BoxDecoration(
+ color: p.accent.withValues(alpha: 0.08),
+ borderRadius: BorderRadius.circular(Radii.md),
+ border: Border.all(color: p.accent, width: 2),
+ ),
+ alignment: Alignment.center,
+ child: Text(l.friendDropHint(f.displayName), style: context.text.titleSmall?.copyWith(color: p.accent)),
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+}
diff --git a/ui/lib/pages/send_page.dart b/ui/lib/pages/send_page.dart
index 357695e..017e392 100644
--- a/ui/lib/pages/send_page.dart
+++ b/ui/lib/pages/send_page.dart
@@ -208,7 +208,7 @@ class _SendPageState extends State<SendPage> with SingleTickerProviderStateMixin
title: l.navSend,
subtitle: l.sendSubtitle,
actions: [
- if (state.profile != null) const _ProfileChip(),
+ if (state.profile != null) const ProfileChip(),
if (state.profile != null)
Tooltip(
message: l.friendsTitle,
@@ -253,7 +253,7 @@ class _SendPageState extends State<SendPage> with SingleTickerProviderStateMixin
],
),
),
- if (state.profile != null) const _ReceiveFromBar(),
+ if (state.profile != null) const ReceiveFromBar(),
],
);
}
@@ -1129,8 +1129,8 @@ class _TransferDetails implements RecordDetails {
// ─────────────────────────── 好友(2.6.0) ───────────────────────────
/// 页面右上角:本机的头像和好友看到的名字。点头像换头像,点名字改名
-class _ProfileChip extends StatelessWidget {
- const _ProfileChip();
+class ProfileChip extends StatelessWidget {
+ const ProfileChip({super.key});
@override
Widget build(BuildContext context) {
@@ -1373,14 +1373,17 @@ class _PersonNodeState extends State<_PersonNode> {
}
/// 页面底部:谁可以给我发文件(均不允许 / 仅限好友 / 所有人)。「所有人」显示还剩几分钟
-class _ReceiveFromBar extends StatefulWidget {
- const _ReceiveFromBar();
+class ReceiveFromBar extends StatefulWidget {
+ const ReceiveFromBar({super.key, this.trailing});
+
+ /// 右边的部件(好友页放「我显示为」)
+ final Widget? trailing;
@override
- State<_ReceiveFromBar> createState() => _ReceiveFromBarState();
+ State<ReceiveFromBar> createState() => _ReceiveFromBarState();
}
-class _ReceiveFromBarState extends State<_ReceiveFromBar> {
+class _ReceiveFromBarState extends State<ReceiveFromBar> {
Timer? _tick;
@override
@@ -1420,6 +1423,7 @@ class _ReceiveFromBarState extends State<_ReceiveFromBar> {
PopupMenuButton<String>(
tooltip: '',
position: PopupMenuPosition.over,
+ constraints: const BoxConstraints(minWidth: 320, maxWidth: 320),
onSelected: (next) async {
try {
await state.setReceiveFrom(next);
@@ -1433,20 +1437,11 @@ class _ReceiveFromBarState extends State<_ReceiveFromBar> {
('friends', l.receiveFromFriends, l.receiveFromFriendsDesc),
('everyone', l.receiveFromEveryone, l.receiveFromEveryoneDesc),
])
- CheckedPopupMenuItem(
+ PopupMenuItem(
value: value,
- checked: v == value,
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- mainAxisSize: MainAxisSize.min,
- children: [
- Text(title),
- SizedBox(
- width: 280,
- child: Text(desc, style: context.text.bodySmall),
- ),
- ],
- ),
+ height: 0,
+ padding: const EdgeInsets.symmetric(horizontal: 10),
+ child: menuChoiceRow(context, title, desc, v == value, width: 280),
),
],
child: Padding(
@@ -1461,6 +1456,7 @@ class _ReceiveFromBarState extends State<_ReceiveFromBar> {
),
),
),
+ if (widget.trailing != null) ...[const Spacer(), widget.trailing!],
],
),
);
diff --git a/ui/lib/widgets/avatar.dart b/ui/lib/widgets/avatar.dart
index 505a83d..3770db5 100644
--- a/ui/lib/widgets/avatar.dart
+++ b/ui/lib/widgets/avatar.dart
@@ -171,9 +171,12 @@ class _SelfAvatarButtonState extends State<SelfAvatarButton> {
_ => _reset(context),
},
itemBuilder: (_) => [
- PopupMenuItem(value: 'choose', child: Text(l.avatarChoose)),
- PopupMenuItem(value: 'paste', child: Text(l.avatarPaste)),
- if (profile?.hasAvatar ?? false) PopupMenuItem(value: 'reset', child: Text(l.avatarReset)),
+ PopupMenuItem(value: 'choose', height: 34, child: Text(l.avatarChoose)),
+ PopupMenuItem(value: 'paste', height: 34, child: Text(l.avatarPaste)),
+ if (profile?.hasAvatar ?? false) ...[
+ const PopupMenuDivider(height: 9),
+ PopupMenuItem(value: 'reset', height: 34, child: Text(l.avatarReset)),
+ ],
],
child: DecoratedBox(
decoration: BoxDecoration(
diff --git a/ui/lib/widgets/common.dart b/ui/lib/widgets/common.dart
index f4a02bd..d235446 100644
--- a/ui/lib/widgets/common.dart
+++ b/ui/lib/widgets/common.dart
@@ -629,3 +629,48 @@ abstract final class PaletteColors {
return c;
}
}
+
+/// 菜单里带勾的一行:勾的位置固定在左边,没选中时留空,文字对齐
+Widget menuCheckRow(BuildContext context, String title, bool checked) => Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ SizedBox(
+ width: 20,
+ child: checked ? Icon(AppIcons.checkmark, size: 13, color: context.palette.accent) : null,
+ ),
+ Text(title),
+ ],
+);
+
+/// 菜单里带说明的选择项:左边是勾,标题下面一行小字说明
+Widget menuChoiceRow(BuildContext context, String title, String description, bool checked, {double width = 280}) =>
+ Padding(
+ padding: const EdgeInsets.symmetric(vertical: 6),
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ SizedBox(
+ width: 20,
+ child: checked
+ ? Padding(
+ padding: const EdgeInsets.only(top: 2),
+ child: Icon(AppIcons.checkmark, size: 13, color: context.palette.accent),
+ )
+ : null,
+ ),
+ SizedBox(
+ width: width,
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Text(title, style: context.text.labelLarge),
+ const SizedBox(height: 2),
+ Text(description, style: context.text.bodySmall?.copyWith(color: context.palette.textDim)),
+ ],
+ ),
+ ),
+ ],
+ ),
+ );
diff --git a/ui/lib/widgets/friends_dialog.dart b/ui/lib/widgets/friends_dialog.dart
index 5511a0d..62f6daa 100644
--- a/ui/lib/widgets/friends_dialog.dart
+++ b/ui/lib/widgets/friends_dialog.dart
@@ -175,7 +175,12 @@ class _FriendRow extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(friendTitle(f), style: context.text.labelLarge, maxLines: 1, overflow: TextOverflow.ellipsis),
- Text(sub, style: context.text.bodySmall?.copyWith(color: p.textDim), maxLines: 1, overflow: TextOverflow.ellipsis),
+ Text(
+ sub,
+ style: context.text.bodySmall?.copyWith(color: p.textDim),
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ ),
],
),
),
@@ -196,51 +201,58 @@ class _FriendRow extends StatelessWidget {
);
}
- Future<void> _menu(BuildContext context, Offset at) async {
- final l = context.l10n;
- final state = AppScope.read(context);
- final overlay = Overlay.of(context).context.findRenderObject() as RenderBox;
- final v = await showMenu<String>(
- context: context,
- position: RelativeRect.fromRect(at & const Size(1, 1), Offset.zero & overlay.size),
- items: [
- PopupMenuItem(value: 'send', child: Text(l.friendSendAction)),
- PopupMenuItem(value: 'history', child: Text(l.friendHistory)),
- CheckedPopupMenuItem(value: 'auto', checked: friend.autoAccept, child: Text(l.friendAutoAccept)),
- const PopupMenuDivider(),
- PopupMenuItem(value: 'remove', child: Text(l.friendRemove, style: TextStyle(color: context.palette.danger))),
- ],
- );
- if (!context.mounted) return;
- try {
- switch (v) {
- case 'send':
- await openFriendSend(context, friend);
- case 'history':
- await showFriendHistory(context, friend);
- case 'auto':
- await state.setFriendAutoAccept(friend.id, !friend.autoAccept);
- case 'remove':
- final ok = await showDialog<bool>(
- context: context,
- builder: (ctx) => AlertDialog(
- title: Text(l.friendRemoveTitle(friend.displayName)),
- content: SizedBox(width: 380, child: Text(l.friendRemoveBody)),
- actions: [
- TextButton(onPressed: () => Navigator.pop(ctx, false), child: Text(l.cancel)),
- FilledButton(
- style: FilledButton.styleFrom(backgroundColor: context.palette.danger),
- onPressed: () => Navigator.pop(ctx, true),
- child: Text(l.friendRemove),
- ),
- ],
- ),
- );
- if (ok == true) await state.removeFriend(friend.id);
- }
- } catch (e) {
- if (context.mounted) showToast(context, AppState.describeError(e), error: true);
+ Future<void> _menu(BuildContext context, Offset at) => showFriendMenu(context, friend, at);
+}
+
+/// 好友的菜单:发送、传输记录、自动接收、删除。detail 为真时(已经在详情里)不列「传输记录」
+Future<void> showFriendMenu(BuildContext context, Friend friend, Offset at, {bool detail = false}) async {
+ final l = context.l10n;
+ final state = AppScope.read(context);
+ final overlay = Overlay.of(context).context.findRenderObject() as RenderBox;
+ final v = await showMenu<String>(
+ context: context,
+ position: RelativeRect.fromRect(at & const Size(1, 1), Offset.zero & overlay.size),
+ items: [
+ PopupMenuItem(value: 'send', height: 34, child: Text(l.friendSendAction)),
+ if (!detail) PopupMenuItem(value: 'history', height: 34, child: Text(l.friendHistory)),
+ PopupMenuItem(value: 'auto', height: 34, child: menuCheckRow(context, l.friendAutoAccept, friend.autoAccept)),
+ const PopupMenuDivider(),
+ PopupMenuItem(
+ value: 'remove',
+ height: 34,
+ child: Text(l.friendRemove, style: TextStyle(color: context.palette.danger)),
+ ),
+ ],
+ );
+ if (!context.mounted) return;
+ try {
+ switch (v) {
+ case 'send':
+ await openFriendSend(context, friend);
+ case 'history':
+ await showFriendHistory(context, friend);
+ case 'auto':
+ await state.setFriendAutoAccept(friend.id, !friend.autoAccept);
+ case 'remove':
+ final ok = await showDialog<bool>(
+ context: context,
+ builder: (ctx) => AlertDialog(
+ title: Text(l.friendRemoveTitle(friend.displayName)),
+ content: SizedBox(width: 380, child: Text(l.friendRemoveBody)),
+ actions: [
+ TextButton(onPressed: () => Navigator.pop(ctx, false), child: Text(l.cancel)),
+ FilledButton(
+ style: FilledButton.styleFrom(backgroundColor: context.palette.danger),
+ onPressed: () => Navigator.pop(ctx, true),
+ child: Text(l.friendRemove),
+ ),
+ ],
+ ),
+ );
+ if (ok == true) await state.removeFriend(friend.id);
}
+ } catch (e) {
+ if (context.mounted) showToast(context, AppState.describeError(e), error: true);
}
}
@@ -402,7 +414,9 @@ class _AddFriendDialogState extends State<AddFriendDialog> {
),
const SizedBox(height: Insets.sm),
if (expired)
- Center(child: TextButton(onPressed: _generate, child: Text(l.retry)))
+ Center(
+ child: TextButton(onPressed: _generate, child: Text(l.retry)),
+ )
else if (left != null)
Text(
l.friendCodeExpires('${left.inMinutes}:${(left.inSeconds % 60).toString().padLeft(2, '0')}'),
@@ -576,7 +590,10 @@ class _FriendConfirmDialogState extends State<FriendConfirmDialog> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
for (final fp in ([r.fingerprint, r.selfFingerprint]..sort()))
- Text(fp, style: TextStyle(fontFamily: monoFamily, fontSize: 18, letterSpacing: 2, color: p.text)),
+ Text(
+ fp,
+ style: TextStyle(fontFamily: monoFamily, fontSize: 18, letterSpacing: 2, color: p.text),
+ ),
const SizedBox(height: Insets.sm),
Text(l.friendSafetyHint, style: context.text.bodySmall),
],
@@ -610,15 +627,34 @@ class _FriendConfirmDialogState extends State<FriendConfirmDialog> {
}
}
-// ─────────────────────────── 传输记录 ───────────────────────────
+// ─────────────────────────── 好友详情 ───────────────────────────
+
+Future<void> showFriendHistory(BuildContext context, Friend f) => showDialog<void>(
+ context: context,
+ builder: (_) => Dialog(
+ child: SizedBox(
+ width: 520,
+ child: Padding(
+ padding: const EdgeInsets.fromLTRB(Insets.xl, Insets.lg, Insets.md, Insets.lg),
+ child: FriendDetail(friendId: f.id, inDialog: true),
+ ),
+ ),
+ ),
+);
-Future<void> showFriendHistory(BuildContext context, Friend f) =>
- showDialog<void>(context: context, builder: (_) => _FriendHistoryDialog(friendId: f.id));
+/// 好友按在线、名字排序
+List<Friend> sortedFriends(AppState state) => [...state.friends]
+ ..sort((a, b) {
+ if (a.online != b.online) return a.online ? -1 : 1;
+ return a.displayName.toLowerCase().compareTo(b.displayName.toLowerCase());
+ });
-class _FriendHistoryDialog extends StatelessWidget {
- const _FriendHistoryDialog({required this.friendId});
+/// 一个好友的状态、发送按钮、自动接收开关和传输记录。在弹窗里时记录列表限高,在好友页里占满剩余高度
+class FriendDetail extends StatelessWidget {
+ const FriendDetail({super.key, required this.friendId, this.inDialog = false});
final String friendId;
+ final bool inDialog;
@override
Widget build(BuildContext context) {
@@ -627,83 +663,88 @@ class _FriendHistoryDialog extends StatelessWidget {
final p = context.palette;
final f = state.friendById(friendId);
if (f == null) {
- WidgetsBinding.instance.addPostFrameCallback((_) {
- if (context.mounted) Navigator.pop(context);
- });
+ if (inDialog) {
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ if (context.mounted) Navigator.pop(context);
+ });
+ }
return const SizedBox.shrink();
}
final list = [
...state.transfers(TransferDirection.TRANSFER_DIRECTION_INCOMING),
...state.transfers(TransferDirection.TRANSFER_DIRECTION_OUTGOING),
- ].where((t) => t.deviceId == friendId).toList()
- ..sort((a, b) => b.createdAtUnix.compareTo(a.createdAtUnix));
- return Dialog(
- child: SizedBox(
- width: 520,
- child: Padding(
- padding: const EdgeInsets.fromLTRB(Insets.xl, Insets.lg, Insets.md, Insets.lg),
- child: Column(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.stretch,
- children: [
- Row(
+ ].where((t) => t.deviceId == friendId).toList()..sort((a, b) => b.createdAtUnix.compareTo(a.createdAtUnix));
+ final records = list.isEmpty
+ ? Padding(
+ padding: const EdgeInsets.all(Insets.xl),
+ child: Text(l.friendHistoryEmpty, textAlign: TextAlign.center, style: context.text.bodySmall),
+ )
+ : ListView.separated(
+ shrinkWrap: inDialog,
+ padding: const EdgeInsets.only(right: Insets.md),
+ itemCount: list.length,
+ separatorBuilder: (_, _) => Divider(height: 1, color: p.separator),
+ itemBuilder: (_, i) => _HistoryRow(transfer: list[i]),
+ );
+ return Column(
+ mainAxisSize: inDialog ? MainAxisSize.min : MainAxisSize.max,
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ Row(
+ children: [
+ PersonAvatar(deviceId: f.id, name: f.displayName, hash: f.avatarHash, size: inDialog ? 44 : 52),
+ const SizedBox(width: Insets.md),
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
children: [
- PersonAvatar(deviceId: f.id, name: f.displayName, hash: f.avatarHash, size: 44),
- const SizedBox(width: Insets.md),
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(friendTitle(f), style: context.text.titleMedium, maxLines: 1, overflow: TextOverflow.ellipsis),
- Text(friendStatus(l, state, f), style: context.text.bodySmall?.copyWith(color: p.textDim)),
- ],
- ),
- ),
- FilledButton(onPressed: () => openFriendSend(context, f), child: Text(l.friendSendAction)),
- const SizedBox(width: Insets.xs),
- IconAction(icon: AppIcons.xmark, tooltip: l.close, onTap: () => Navigator.pop(context)),
+ Text(friendTitle(f), style: context.text.titleMedium, maxLines: 1, overflow: TextOverflow.ellipsis),
+ Text(friendStatus(l, state, f), style: context.text.bodySmall?.copyWith(color: p.textDim)),
],
),
- const SizedBox(height: Insets.md),
- Padding(
- padding: const EdgeInsets.only(right: Insets.md),
- child: Row(
- children: [
- Expanded(child: Text(l.friendAutoAccept, style: context.text.bodyMedium)),
- SmallSwitch(
- value: f.autoAccept,
- onChanged: (v) => state.setFriendAutoAccept(f.id, v).catchError((Object e) {
- if (context.mounted) showToast(context, AppState.describeError(e), error: true);
- }),
- ),
- ],
+ ),
+ FilledButton(onPressed: () => openFriendSend(context, f), child: Text(l.friendSendAction)),
+ const SizedBox(width: Insets.xs),
+ if (inDialog)
+ IconAction(icon: AppIcons.xmark, tooltip: l.close, onTap: () => Navigator.pop(context))
+ else
+ Builder(
+ builder: (bctx) => IconAction(
+ icon: AppIcons.ellipsis,
+ tooltip: l.moreActions,
+ onTap: () {
+ final box = bctx.findRenderObject() as RenderBox;
+ showFriendMenu(context, f, box.localToGlobal(box.size.bottomLeft(Offset.zero)), detail: true);
+ },
),
),
- const SizedBox(height: Insets.md),
- Divider(height: 1, color: p.separator),
- const SizedBox(height: Insets.md),
- Text(l.friendHistory, style: context.text.titleSmall),
- const SizedBox(height: Insets.xs),
- if (list.isEmpty)
- Padding(
- padding: const EdgeInsets.all(Insets.xl),
- child: Text(l.friendHistoryEmpty, textAlign: TextAlign.center, style: context.text.bodySmall),
- )
- else
- ConstrainedBox(
- constraints: const BoxConstraints(maxHeight: 440),
- child: ListView.separated(
- shrinkWrap: true,
- padding: const EdgeInsets.only(right: Insets.md),
- itemCount: list.length,
- separatorBuilder: (_, _) => Divider(height: 1, color: p.separator),
- itemBuilder: (_, i) => _HistoryRow(transfer: list[i]),
- ),
- ),
+ ],
+ ),
+ const SizedBox(height: Insets.md),
+ Padding(
+ padding: const EdgeInsets.only(right: Insets.md),
+ child: Row(
+ children: [
+ Expanded(child: Text(l.friendAutoAccept, style: context.text.bodyMedium)),
+ SmallSwitch(
+ value: f.autoAccept,
+ onChanged: (v) => state.setFriendAutoAccept(f.id, v).catchError((Object e) {
+ if (context.mounted) showToast(context, AppState.describeError(e), error: true);
+ }),
+ ),
],
),
),
- ),
+ const SizedBox(height: Insets.md),
+ Divider(height: 1, color: p.separator),
+ const SizedBox(height: Insets.md),
+ Text(l.friendHistory, style: context.text.titleSmall),
+ const SizedBox(height: Insets.xs),
+ if (inDialog || list.isEmpty)
+ ConstrainedBox(constraints: const BoxConstraints(maxHeight: 440), child: records)
+ else
+ Expanded(child: records),
+ ],
);
}
}
diff --git a/ui/test/friends_test.dart b/ui/test/friends_test.dart
index 7afad43..8c92e75 100644
--- a/ui/test/friends_test.dart
+++ b/ui/test/friends_test.dart
@@ -114,7 +114,7 @@ void main() {
await tester.tap(find.text(l.receiveFromFriends));
await _settle(tester);
- await tester.tap(find.widgetWithText(CheckedPopupMenuItem<String>, l.receiveFromEveryone));
+ await tester.tap(find.widgetWithText(PopupMenuItem<String>, l.receiveFromEveryone));
await _settle(tester);
expect(state.receiveFromCalls, ['everyone']);
});
@@ -235,5 +235,45 @@ void main() {
await tester.pump();
expect(title, findsOneWidget);
});
-}
+ testWidgets('侧边栏的好友页:列表、选中好友看记录、搜索、没有好友时的说明', (tester) async {
+ final out = Transfer(
+ id: 'o1',
+ direction: TransferDirection.TRANSFER_DIRECTION_OUTGOING,
+ deviceId: 'xm',
+ deviceName: '小明',
+ status: 'done',
+ peerRole: 'friend',
+ note: '合同第 3 页要签字',
+ items: [ClipItem(name: '合同扫描件.pdf', size: Int64(18 << 20))],
+ totalBytes: Int64(18 << 20),
+ createdAtUnix: _now(120),
+ );
+ final state = _demo(transfers: [out]);
+ await tester.pumpWidget(PasteFerryApp(state: state));
+ await tester.pump();
+ final l = AppLocalizations.of(tester.element(find.byType(Shell)));
+ await tester.tap(find.text(l.friendsTitle).first);
+ await _settle(tester);
+ expect(find.text(l.friendsSubtitle), findsOneWidget);
+ // 在线的好友排在前面,默认选中第一个,右边是他的记录
+ expect(find.text(l.noteLine('合同第 3 页要签字')), findsOneWidget);
+ await tester.tap(find.text('阿杰').first);
+ await _settle(tester);
+ expect(find.text(l.noteLine('合同第 3 页要签字')), findsNothing);
+ expect(find.text(l.friendHistoryEmpty), findsOneWidget);
+ await tester.enterText(find.byType(TextField).first, '不存在');
+ await _settle(tester);
+ expect(find.text(l.friendsNoMatch), findsOneWidget);
+ // 「允许这些人给我发文件」也在这一页
+ expect(find.text(l.receiveFromFriends), findsOneWidget);
+
+ final empty = _FriendsState()..debugSeed(status: state.status!, config: state.config!, self: state.self!, profile: state.profile);
+ await tester.pumpWidget(PasteFerryApp(key: UniqueKey(), state: empty));
+ await tester.pump();
+ await tester.tap(find.text(l.friendsTitle).first);
+ await _settle(tester);
+ expect(find.text(l.friendsEmpty), findsOneWidget);
+ expect(find.text(l.addFriend), findsNWidgets(2));
+ });
+}
diff --git a/ui/tool/screenshots/screenshots_test.dart b/ui/tool/screenshots/screenshots_test.dart
index 415af80..a1cdadd 100644
--- a/ui/tool/screenshots/screenshots_test.dart
+++ b/ui/tool/screenshots/screenshots_test.dart
@@ -17,7 +17,9 @@ import 'package:pasteferry_ui/main.dart';
import 'package:pasteferry_ui/picker/picker_host.dart';
import 'package:pasteferry_ui/picker/picker_state.dart';
import 'package:pasteferry_ui/picker/picker_view.dart';
+import 'package:pasteferry_ui/icons.dart';
import 'package:pasteferry_ui/theme.dart';
+import 'package:pasteferry_ui/widgets/avatar.dart';
import 'package:pasteferry_ui/widgets/friend_send_dialog.dart';
import 'package:pasteferry_ui/widgets/friends_dialog.dart';
import 'package:pasteferry_ui/widgets/nearby_dialog.dart';
@@ -564,6 +566,29 @@ void main() {
});
});
+ testWidgets('friends-page-dark', (tester) async {
+ await _shoot(tester, 'friends-page-dark', state: _friendsDemo(), section: Section.friends, settle: false,
+ brightness: Brightness.dark, window: const Size(1180, 720));
+ });
+
+ testWidgets('receive-from-menu-dark', (tester) async {
+ await _shoot(tester, 'receive-from-menu-dark', state: _friendsDemo(), section: Section.send, settle: false,
+ brightness: Brightness.dark, window: const Size(1180, 720), arrange: () async {
+ await tester.tap(find.byIcon(AppIcons.chevronDown).last);
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 400));
+ });
+ });
+
+ testWidgets('avatar-menu-dark', (tester) async {
+ await _shoot(tester, 'avatar-menu-dark', state: _friendsDemo(), section: Section.send, settle: false,
+ brightness: Brightness.dark, window: const Size(1180, 720), arrange: () async {
+ await tester.tap(find.byType(SelfAvatarButton).first);
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 400));
+ });
+ });
+
testWidgets('add-friend-dark', (tester) async {
await _shoot(tester, 'add-friend-dark', state: _friendsDemo(), section: Section.send, settle: false,
brightness: Brightness.dark, window: const Size(1180, 720), arrange: () async {