|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
import 'dart:async'; |
|
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
|
import 'package:go_router/go_router.dart'; |
|
|
|
|
import 'package:meta/meta.dart'; |
|
|
|
|
import 'package:neon/l10n/localizations.dart'; |
|
|
|
|
import 'package:neon/src/bloc/result_builder.dart'; |
|
|
|
@ -100,7 +101,6 @@ class NotificationIconButton extends StatefulWidget {
|
|
|
|
|
class _NotificationIconButtonState extends State<NotificationIconButton> { |
|
|
|
|
late AccountsBloc _accountsBloc; |
|
|
|
|
late AppsBloc _appsBloc; |
|
|
|
|
late List<Account> _accounts; |
|
|
|
|
late Account _account; |
|
|
|
|
late StreamSubscription notificationSubscription; |
|
|
|
|
|
|
|
|
@ -109,13 +109,12 @@ class _NotificationIconButtonState extends State<NotificationIconButton> {
|
|
|
|
|
super.initState(); |
|
|
|
|
_accountsBloc = Provider.of<AccountsBloc>(context, listen: false); |
|
|
|
|
_appsBloc = _accountsBloc.activeAppsBloc; |
|
|
|
|
_accounts = _accountsBloc.accounts.value; |
|
|
|
|
_account = _accountsBloc.activeAccount.value!; |
|
|
|
|
|
|
|
|
|
notificationSubscription = _appsBloc.openNotifications.listen((final _) async { |
|
|
|
|
notificationSubscription = _appsBloc.openNotifications.listen((final _) { |
|
|
|
|
final notificationsAppImplementation = _appsBloc.notificationsAppImplementation.valueOrNull; |
|
|
|
|
if (notificationsAppImplementation != null && notificationsAppImplementation.hasData) { |
|
|
|
|
await _openNotifications(notificationsAppImplementation.data!); |
|
|
|
|
_openNotifications(notificationsAppImplementation.data!); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
@ -127,37 +126,8 @@ class _NotificationIconButtonState extends State<NotificationIconButton> {
|
|
|
|
|
super.dispose(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// TODO: migrate to go_router with a separate page |
|
|
|
|
Future<void> _openNotifications( |
|
|
|
|
final NotificationsAppInterface app, |
|
|
|
|
) async { |
|
|
|
|
final page = Scaffold( |
|
|
|
|
resizeToAvoidBottomInset: false, |
|
|
|
|
appBar: AppBar( |
|
|
|
|
title: Column( |
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
|
children: [ |
|
|
|
|
Text(app.name(context)), |
|
|
|
|
if (_accounts.length > 1) ...[ |
|
|
|
|
Text( |
|
|
|
|
_account.humanReadableID, |
|
|
|
|
style: Theme.of(context).textTheme.bodySmall, |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
body: app.page, |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
await Navigator.of(context).push( |
|
|
|
|
MaterialPageRoute( |
|
|
|
|
builder: (final context) => Provider<NotificationsBlocInterface>( |
|
|
|
|
create: (final context) => app.getBloc(_account), |
|
|
|
|
child: page, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
void _openNotifications(final NotificationsAppInterface app) { |
|
|
|
|
GoRouter.of(context).go(app.initialPath); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@ -177,8 +147,8 @@ class _NotificationIconButtonState extends State<NotificationIconButton> {
|
|
|
|
|
final unreadCount = unreadCounterSnapshot.data ?? 0; |
|
|
|
|
return IconButton( |
|
|
|
|
key: Key('app-${notificationsImplementationData.id}'), |
|
|
|
|
onPressed: () async { |
|
|
|
|
await _openNotifications(notificationsImplementationData); |
|
|
|
|
onPressed: () { |
|
|
|
|
_openNotifications(notificationsImplementationData); |
|
|
|
|
}, |
|
|
|
|
tooltip: AppLocalizations.of(context).appImplementationName(notificationsImplementationData.id), |
|
|
|
|
icon: NeonAppImplementationIcon( |
|
|
|
|