refactor: don't use ref in dispose

This commit is contained in:
Benedikt
2026-02-18 08:58:15 +01:00
committed by kolaente
parent ce7e5b9c42
commit 1bca8d01ce
2 changed files with 12 additions and 7 deletions
+7 -5
View File
@@ -33,6 +33,7 @@ class HomePageState extends ConsumerState<HomePage> {
int _selectedDrawerIndex = 0, _previousDrawerIndex = 0;
Widget? drawerItem;
NotificationHandler? _notificationHandler;
List<Widget> widgets = [TaskListPage(), ProjectListPage(), SettingsPage()];
@@ -73,7 +74,7 @@ class HomePageState extends ConsumerState<HomePage> {
@override
void dispose() {
ref.read(notificationProvider)?.removeListener(onNotificationDone);
_notificationHandler?.removeListener(onNotificationDone);
super.dispose();
}
@@ -223,11 +224,12 @@ class HomePageState extends ConsumerState<HomePage> {
Future<void> initNotifications() async {
var notifGranted = await Permission.notification.isGranted;
if (notifGranted) {
NotificationHandler notificationClass = NotificationHandler();
await notificationClass.initNotifications();
notificationClass.addListener(onNotificationDone);
NotificationHandler notificationHandler = NotificationHandler();
await notificationHandler.initNotifications();
notificationHandler.addListener(onNotificationDone);
ref.read(notificationProvider.notifier).set(notificationClass);
ref.read(notificationProvider.notifier).set(notificationHandler);
_notificationHandler = notificationHandler;
}
}
@@ -8,6 +8,7 @@ import 'package:vikunja_app/domain/entities/project.dart';
import 'package:vikunja_app/domain/entities/task.dart';
import 'package:vikunja_app/domain/entities/view_kind.dart';
import 'package:vikunja_app/l10n/gen/app_localizations.dart';
import 'package:vikunja_app/presentation/manager/notifications.dart';
import 'package:vikunja_app/presentation/manager/project_controller.dart';
import 'package:vikunja_app/presentation/pages/error_widget.dart';
import 'package:vikunja_app/presentation/pages/loading_widget.dart';
@@ -27,16 +28,18 @@ class ProjectDetailPage extends ConsumerStatefulWidget {
class ProjectPageState extends ConsumerState<ProjectDetailPage> {
int _viewIndex = 0;
NotificationHandler? _notificationHandler;
@override
void initState() {
ref.read(notificationProvider)?.addListener(onNotificationDone);
_notificationHandler = ref.read(notificationProvider);
_notificationHandler?.addListener(onNotificationDone);
super.initState();
}
@override
void dispose() {
ref.read(notificationProvider)?.removeListener(onNotificationDone);
_notificationHandler?.removeListener(onNotificationDone);
super.dispose();
}