fix: simplify paired device status display

This commit is contained in:
Haitao Pan 2026-03-13 15:30:58 +08:00
parent 3bf965ddfa
commit e7dabe2905

View File

@ -1538,10 +1538,13 @@ class _SettingsPageState extends State<SettingsPage> {
style: theme.textTheme.bodySmall,
)
else
...item.tokens.map(
(token) => Padding(
padding: const EdgeInsets.only(top: 10),
child: _buildTokenRow(context, controller, item, token),
Padding(
padding: const EdgeInsets.only(top: 10),
child: _buildTokenRow(
context,
controller,
item,
_latestDeviceToken(item.tokens),
),
),
],
@ -1550,6 +1553,26 @@ class _SettingsPageState extends State<SettingsPage> {
);
}
GatewayDeviceTokenSummary _latestDeviceToken(
List<GatewayDeviceTokenSummary> tokens,
) {
final sorted = List<GatewayDeviceTokenSummary>.from(tokens)
..sort((left, right) {
final rightTime = _deviceTokenStatusTime(right);
final leftTime = _deviceTokenStatusTime(left);
return rightTime.compareTo(leftTime);
});
return sorted.first;
}
int _deviceTokenStatusTime(GatewayDeviceTokenSummary token) {
return token.lastUsedAtMs ??
token.rotatedAtMs ??
token.revokedAtMs ??
token.createdAtMs ??
0;
}
Widget _buildTokenRow(
BuildContext context,
AppController controller,
@ -1560,9 +1583,7 @@ class _SettingsPageState extends State<SettingsPage> {
final details = <String>[
token.revoked ? appText('已撤销', 'revoked') : appText('有效', 'active'),
if (token.scopes.isNotEmpty) token.scopes.join(', '),
_relativeTime(
token.rotatedAtMs ?? token.createdAtMs ?? token.lastUsedAtMs,
),
_relativeTime(_deviceTokenStatusTime(token)),
];
return DecoratedBox(
decoration: BoxDecoration(