Browse Source

Merge pull request #714 from nextcloud/fix/dispose_state

Fix/dispose state
pull/717/head
Nikolas Rimikis 1 year ago committed by GitHub
parent
commit
65d2389485
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      packages/neon/neon/lib/neon.dart
  2. 1
      packages/neon/neon/lib/src/bloc/bloc.dart
  3. 4
      packages/neon/neon/lib/src/blocs/apps.dart
  4. 2
      packages/neon/neon/lib/src/blocs/login_check_account.dart
  5. 2
      packages/neon/neon/lib/src/blocs/login_check_server_status.dart
  6. 2
      packages/neon/neon/lib/src/blocs/login_flow.dart
  7. 5
      packages/neon/neon/lib/src/models/app_implementation.dart
  8. 14
      packages/neon/neon/lib/src/utils/rename_dialog.dart
  9. 1
      packages/neon/neon/lib/src/widgets/app_bar.dart
  10. 2
      packages/neon/neon_files/lib/blocs/files.dart
  11. 6
      packages/neon/neon_files/lib/dialogs/create_folder.dart
  12. 6
      packages/neon/neon_news/lib/dialogs/add_feed.dart
  13. 6
      packages/neon/neon_news/lib/dialogs/create_folder.dart
  14. 6
      packages/neon/neon_notes/lib/dialogs/create_note.dart
  15. 11
      packages/neon/neon_notes/lib/pages/note.dart

10
packages/neon/neon/lib/neon.dart

@ -67,21 +67,31 @@ Future runNeon({
providers: [
Provider<GlobalOptions>(
create: (final _) => globalOptions,
dispose: (final _, final globalOptions) => globalOptions.dispose(),
),
Provider<AccountsBloc>(
create: (final _) => accountsBloc,
dispose: (final _, final accountsBloc) => accountsBloc.dispose(),
),
Provider<PushNotificationsBloc>(
create: (final _) => pushNotificationsBloc,
dispose: (final _, final pushNotificationsBloc) => pushNotificationsBloc.dispose(),
),
Provider<FirstLaunchBloc>(
create: (final _) => firstLaunchBloc,
dispose: (final _, final firstLaunchBloc) => firstLaunchBloc.dispose(),
),
Provider<NextPushBloc>(
create: (final _) => nextPushBloc,
dispose: (final _, final nextPushBloc) => nextPushBloc.dispose(),
),
Provider<Iterable<AppImplementation>>(
create: (final _) => appImplementations,
dispose: (final _, final appImplementations) {
for (final app in appImplementations) {
app.dispose();
}
},
),
Provider<PackageInfo>(
create: (final _) => packageInfo,

1
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();
}

4
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

2
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

2
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

2
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

5
packages/neon/neon/lib/src/models/app_implementation.dart

@ -105,11 +105,10 @@ abstract class AppImplementation<T extends Bloc, R extends NextcloudAppOptions>
),
);
@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.

14
packages/neon/neon/lib/src/utils/rename_dialog.dart

@ -34,7 +34,19 @@ class _RenameDialog extends StatefulWidget {
class _RenameDialogState extends State<_RenameDialog> {
final formKey = GlobalKey<FormState>();
late final controller = TextEditingController()..text = widget.value;
final controller = TextEditingController();
@override
void initState() {
controller.text = widget.value;
super.initState();
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
void submit() {
if (formKey.currentState!.validate()) {

1
packages/neon/neon/lib/src/widgets/app_bar.dart

@ -55,6 +55,7 @@ class _NeonAppBarState extends State<NeonAppBar> {
@override
void dispose() {
_searchBarFocusNode.dispose();
unawaited(_searchTermSubscription.cancel());
unawaited(_searchTermController.close());
super.dispose();

2
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

6
packages/neon/neon_files/lib/dialogs/create_folder.dart

@ -14,6 +14,12 @@ class _FilesCreateFolderDialogState extends State<FilesCreateFolderDialog> {
final controller = TextEditingController();
@override
void dispose() {
controller.dispose();
super.dispose();
}
void submit() {
if (formKey.currentState!.validate()) {
Navigator.of(context).pop(controller.text.split('/'));

6
packages/neon/neon_news/lib/dialogs/add_feed.dart

@ -42,6 +42,12 @@ class _NewsAddFeedDialogState extends State<NewsAddFeedDialog> {
);
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
@override
Widget build(final BuildContext context) => ResultBuilder<List<NewsFolder>>.behaviorSubject(
stream: widget.bloc.folders,

6
packages/neon/neon_news/lib/dialogs/create_folder.dart

@ -14,6 +14,12 @@ class _NewsCreateFolderDialogState extends State<NewsCreateFolderDialog> {
final controller = TextEditingController();
@override
void dispose() {
controller.dispose();
super.dispose();
}
void submit() {
if (formKey.currentState!.validate()) {
Navigator.of(context).pop(controller.text);

6
packages/neon/neon_notes/lib/dialogs/create_note.dart

@ -19,6 +19,12 @@ class _NotesCreateNoteDialogState extends State<NotesCreateNoteDialog> {
final controller = TextEditingController();
String? selectedCategory;
@override
void dispose() {
controller.dispose();
super.dispose();
}
void submit() {
if (formKey.currentState!.validate()) {
Navigator.of(context).pop((controller.text, widget.category ?? selectedCategory));

11
packages/neon/neon_notes/lib/pages/note.dart

@ -15,8 +15,8 @@ class NotesNotePage extends StatefulWidget {
}
class _NotesNotePageState extends State<NotesNotePage> {
late final _contentController = TextEditingController()..text = widget.bloc.initialContent;
late final _titleController = TextEditingController()..text = widget.bloc.initialTitle;
final _contentController = TextEditingController();
final _titleController = TextEditingController();
final _contentFocusNode = FocusNode();
final _titleFocusNode = FocusNode();
bool _showEditor = false;
@ -36,6 +36,9 @@ class _NotesNotePageState extends State<NotesNotePage> {
handleNotesException(context, error);
});
_contentController.text = widget.bloc.initialContent;
_titleController.text = widget.bloc.initialTitle;
_contentStreamController.stream.debounceTime(const Duration(seconds: 1)).listen(widget.bloc.updateContent);
_titleStreamController.stream.debounceTime(const Duration(seconds: 1)).listen(widget.bloc.updateTitle);
_contentController.addListener(() => _contentStreamController.add(_contentController.text));
@ -56,6 +59,10 @@ class _NotesNotePageState extends State<NotesNotePage> {
@override
void dispose() {
_contentController.dispose();
_titleController.dispose();
_contentFocusNode.dispose();
_titleFocusNode.dispose();
unawaited(_contentStreamController.close());
unawaited(_titleStreamController.close());
super.dispose();

Loading…
Cancel
Save