🐛 Fix app bar buttons clicking event got absorb by indicators

This commit is contained in:
LittleSheep 2025-01-21 14:47:13 +08:00
parent bb7b731602
commit 9b34f385d5
2 changed files with 78 additions and 69 deletions

View File

@ -18,45 +18,49 @@ class ConnectionIndicator extends StatelessWidget {
listenable: ws, listenable: ws,
builder: (context, _) { builder: (context, _) {
final ua = context.read<UserProvider>(); final ua = context.read<UserProvider>();
final show = (ws.isBusy || !ws.isConnected) && ua.isAuthorized;
return GestureDetector( return IgnorePointer(
child: Material( ignoring: !show,
elevation: 2, child: GestureDetector(
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(16))), child: Material(
color: Theme.of(context).colorScheme.secondaryContainer, elevation: 2,
child: ua.isAuthorized shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(16))),
? Row( color: Theme.of(context).colorScheme.secondaryContainer,
mainAxisAlignment: MainAxisAlignment.center, child: ua.isAuthorized
crossAxisAlignment: CrossAxisAlignment.center, ? Row(
children: [ mainAxisAlignment: MainAxisAlignment.center,
if (ws.isBusy) crossAxisAlignment: CrossAxisAlignment.center,
Text('serverConnecting').tr().textColor(Theme.of(context).colorScheme.onSecondaryContainer) children: [
else if (!ws.isConnected) if (ws.isBusy)
Text('serverDisconnected').tr().textColor(Theme.of(context).colorScheme.onSecondaryContainer) Text('serverConnecting').tr().textColor(Theme.of(context).colorScheme.onSecondaryContainer)
else else if (!ws.isConnected)
Text('serverConnected').tr().textColor(Theme.of(context).colorScheme.onSecondaryContainer), Text('serverDisconnected').tr().textColor(Theme.of(context).colorScheme.onSecondaryContainer)
const Gap(8), else
if (ws.isBusy) Text('serverConnected').tr().textColor(Theme.of(context).colorScheme.onSecondaryContainer),
const CircularProgressIndicator(strokeWidth: 2.5) const Gap(8),
.width(12) if (ws.isBusy)
.height(12) const CircularProgressIndicator(strokeWidth: 2.5)
.padding(horizontal: 4, right: 4) .width(12)
else if (!ws.isConnected) .height(12)
const Icon(Symbols.power_off, size: 18) .padding(horizontal: 4, right: 4)
else else if (!ws.isConnected)
const Icon(Symbols.power, size: 18), const Icon(Symbols.power_off, size: 18)
], else
).padding(horizontal: 8, vertical: 4) const Icon(Symbols.power, size: 18),
: const SizedBox.shrink(), ],
).opacity((ws.isBusy || !ws.isConnected) && ua.isAuthorized ? 1 : 0, animate: true).animate( ).padding(horizontal: 8, vertical: 4)
const Duration(milliseconds: 300), : const SizedBox.shrink(),
Curves.easeInOut, ).opacity(show ? 1 : 0, animate: true).animate(
), const Duration(milliseconds: 300),
onTap: () { Curves.easeInOut,
if (!ws.isConnected && !ws.isBusy) { ),
ws.connect(); onTap: () {
} if (!ws.isConnected && !ws.isBusy) {
}, ws.connect();
}
},
),
); );
}, },
); );

View File

@ -15,43 +15,48 @@ class NotifyIndicator extends StatelessWidget {
final ua = context.read<UserProvider>(); final ua = context.read<UserProvider>();
final nty = context.watch<NotificationProvider>(); final nty = context.watch<NotificationProvider>();
final show = nty.notifications.isNotEmpty && ua.isAuthorized;
return ListenableBuilder( return ListenableBuilder(
listenable: nty, listenable: nty,
builder: (context, _) { builder: (context, _) {
return GestureDetector( return IgnorePointer(
child: Material( ignoring: !show,
elevation: 2, child: GestureDetector(
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(16))), child: Material(
color: Theme.of(context).colorScheme.secondaryContainer, elevation: 2,
child: ua.isAuthorized shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(16))),
? Row( color: Theme.of(context).colorScheme.secondaryContainer,
mainAxisAlignment: MainAxisAlignment.center, child: ua.isAuthorized
crossAxisAlignment: CrossAxisAlignment.center, ? Row(
children: [ mainAxisAlignment: MainAxisAlignment.center,
Text( crossAxisAlignment: CrossAxisAlignment.center,
nty.notifications.lastOrNull?.title ?? children: [
'notificationUnreadCount'.plural(nty.notifications.length),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
if (nty.notifications.lastOrNull?.body != null)
Text( Text(
nty.notifications.lastOrNull!.body, nty.notifications.lastOrNull?.title ??
'notificationUnreadCount'.plural(nty.notifications.length),
maxLines: 1, maxLines: 1,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
).padding(left: 4), ),
const Gap(8), if (nty.notifications.lastOrNull?.body != null)
const Icon(Symbols.notifications_unread, size: 18), Text(
], nty.notifications.lastOrNull!.body,
).padding(horizontal: 8, vertical: 4) maxLines: 1,
: const SizedBox.shrink(), overflow: TextOverflow.ellipsis,
).opacity(nty.notifications.isNotEmpty && ua.isAuthorized ? 1 : 0, animate: true).animate( ).padding(left: 4),
const Duration(milliseconds: 300), const Gap(8),
Curves.easeInOut, const Icon(Symbols.notifications_unread, size: 18),
), ],
onTap: () { ).padding(horizontal: 8, vertical: 4)
nty.clear(); : const SizedBox.shrink(),
}, ).opacity(show ? 1 : 0, animate: true).animate(
const Duration(milliseconds: 300),
Curves.easeInOut,
),
onTap: () {
nty.clear();
},
),
); );
}); });
} }