diff --git a/packages/neon/neon/lib/neon.dart b/packages/neon/neon/lib/neon.dart index 62d4e126..2df80d53 100644 --- a/packages/neon/neon/lib/neon.dart +++ b/packages/neon/neon/lib/neon.dart @@ -67,21 +67,31 @@ Future runNeon({ providers: [ Provider( create: (final _) => globalOptions, + dispose: (final _, final globalOptions) => globalOptions.dispose(), ), Provider( create: (final _) => accountsBloc, + dispose: (final _, final accountsBloc) => accountsBloc.dispose(), ), Provider( create: (final _) => pushNotificationsBloc, + dispose: (final _, final pushNotificationsBloc) => pushNotificationsBloc.dispose(), ), Provider( create: (final _) => firstLaunchBloc, + dispose: (final _, final firstLaunchBloc) => firstLaunchBloc.dispose(), ), Provider( create: (final _) => nextPushBloc, + dispose: (final _, final nextPushBloc) => nextPushBloc.dispose(), ), Provider>( create: (final _) => appImplementations, + dispose: (final _, final appImplementations) { + for (final app in appImplementations) { + app.dispose(); + } + }, ), Provider( create: (final _) => packageInfo, diff --git a/packages/neon/neon/lib/src/bloc/bloc.dart b/packages/neon/neon/lib/src/bloc/bloc.dart index d1e9b2bf..96263e4c 100644 --- a/packages/neon/neon/lib/src/bloc/bloc.dart +++ b/packages/neon/neon/lib/src/bloc/bloc.dart @@ -4,6 +4,7 @@ import 'package:flutter/foundation.dart'; import 'package:neon/src/utils/request_manager.dart'; abstract class Bloc { + @mustCallSuper void dispose(); } diff --git a/packages/neon/neon/lib/src/blocs/apps.dart b/packages/neon/neon/lib/src/blocs/apps.dart index 6f35a3ec..5b40c9b2 100644 --- a/packages/neon/neon/lib/src/blocs/apps.dart +++ b/packages/neon/neon/lib/src/blocs/apps.dart @@ -164,9 +164,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates unawaited(openNotifications.close()); unawaited(appVersions.close()); - for (final app in _allAppImplementations) { - app.dispose(); - } + super.dispose(); } @override diff --git a/packages/neon/neon/lib/src/blocs/login_check_account.dart b/packages/neon/neon/lib/src/blocs/login_check_account.dart index 380ef064..f7b97561 100644 --- a/packages/neon/neon/lib/src/blocs/login_check_account.dart +++ b/packages/neon/neon/lib/src/blocs/login_check_account.dart @@ -32,6 +32,8 @@ class LoginCheckAccountBloc extends InteractiveBloc @override void dispose() { unawaited(state.close()); + + super.dispose(); } @override diff --git a/packages/neon/neon/lib/src/blocs/login_check_server_status.dart b/packages/neon/neon/lib/src/blocs/login_check_server_status.dart index 65b8526e..a92529f1 100644 --- a/packages/neon/neon/lib/src/blocs/login_check_server_status.dart +++ b/packages/neon/neon/lib/src/blocs/login_check_server_status.dart @@ -25,6 +25,8 @@ class LoginCheckServerStatusBloc extends InteractiveBloc @override void dispose() { unawaited(state.close()); + + super.dispose(); } @override diff --git a/packages/neon/neon/lib/src/blocs/login_flow.dart b/packages/neon/neon/lib/src/blocs/login_flow.dart index 3a25c087..ee6cfc10 100644 --- a/packages/neon/neon/lib/src/blocs/login_flow.dart +++ b/packages/neon/neon/lib/src/blocs/login_flow.dart @@ -34,6 +34,8 @@ class LoginFlowBloc extends InteractiveBloc implements LoginFlowBlocEvents, Logi _cancelPollTimer(); unawaited(init.close()); unawaited(_resultController.close()); + + super.dispose(); } @override diff --git a/packages/neon/neon/lib/src/models/app_implementation.dart b/packages/neon/neon/lib/src/models/app_implementation.dart index b8f184ed..5051d0e6 100644 --- a/packages/neon/neon/lib/src/models/app_implementation.dart +++ b/packages/neon/neon/lib/src/models/app_implementation.dart @@ -105,11 +105,10 @@ abstract class AppImplementation ), ); + @mustCallSuper void dispose() { options.dispose(); - for (final bloc in _blocs.values) { - bloc.dispose(); - } + _blocs.disposeAll(); } /// A custom theme that will be injected into the widget tree. diff --git a/packages/neon/neon_files/lib/blocs/files.dart b/packages/neon/neon_files/lib/blocs/files.dart index 608b82ec..855f1b0c 100644 --- a/packages/neon/neon_files/lib/blocs/files.dart +++ b/packages/neon/neon_files/lib/blocs/files.dart @@ -48,6 +48,8 @@ class FilesBloc extends InteractiveBloc implements FilesBlocEvents, FilesBlocSta options.uploadQueueParallelism.removeListener(_uploadParallelismListener); options.downloadQueueParallelism.removeListener(_downloadParallelismListener); + + super.dispose(); } @override