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: [ providers: [
Provider<GlobalOptions>( Provider<GlobalOptions>(
create: (final _) => globalOptions, create: (final _) => globalOptions,
dispose: (final _, final globalOptions) => globalOptions.dispose(),
), ),
Provider<AccountsBloc>( Provider<AccountsBloc>(
create: (final _) => accountsBloc, create: (final _) => accountsBloc,
dispose: (final _, final accountsBloc) => accountsBloc.dispose(),
), ),
Provider<PushNotificationsBloc>( Provider<PushNotificationsBloc>(
create: (final _) => pushNotificationsBloc, create: (final _) => pushNotificationsBloc,
dispose: (final _, final pushNotificationsBloc) => pushNotificationsBloc.dispose(),
), ),
Provider<FirstLaunchBloc>( Provider<FirstLaunchBloc>(
create: (final _) => firstLaunchBloc, create: (final _) => firstLaunchBloc,
dispose: (final _, final firstLaunchBloc) => firstLaunchBloc.dispose(),
), ),
Provider<NextPushBloc>( Provider<NextPushBloc>(
create: (final _) => nextPushBloc, create: (final _) => nextPushBloc,
dispose: (final _, final nextPushBloc) => nextPushBloc.dispose(),
), ),
Provider<Iterable<AppImplementation>>( Provider<Iterable<AppImplementation>>(
create: (final _) => appImplementations, create: (final _) => appImplementations,
dispose: (final _, final appImplementations) {
for (final app in appImplementations) {
app.dispose();
}
},
), ),
Provider<PackageInfo>( Provider<PackageInfo>(
create: (final _) => 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'; import 'package:neon/src/utils/request_manager.dart';
abstract class Bloc { abstract class Bloc {
@mustCallSuper
void dispose(); 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(openNotifications.close());
unawaited(appVersions.close()); unawaited(appVersions.close());
for (final app in _allAppImplementations) { super.dispose();
app.dispose();
}
} }
@override @override

2
packages/neon/neon/lib/src/blocs/login_check_account.dart

@ -32,6 +32,8 @@ class LoginCheckAccountBloc extends InteractiveBloc
@override @override
void dispose() { void dispose() {
unawaited(state.close()); unawaited(state.close());
super.dispose();
} }
@override @override

2
packages/neon/neon/lib/src/blocs/login_check_server_status.dart

@ -25,6 +25,8 @@ class LoginCheckServerStatusBloc extends InteractiveBloc
@override @override
void dispose() { void dispose() {
unawaited(state.close()); unawaited(state.close());
super.dispose();
} }
@override @override

2
packages/neon/neon/lib/src/blocs/login_flow.dart

@ -34,6 +34,8 @@ class LoginFlowBloc extends InteractiveBloc implements LoginFlowBlocEvents, Logi
_cancelPollTimer(); _cancelPollTimer();
unawaited(init.close()); unawaited(init.close());
unawaited(_resultController.close()); unawaited(_resultController.close());
super.dispose();
} }
@override @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() { void dispose() {
options.dispose(); options.dispose();
for (final bloc in _blocs.values) { _blocs.disposeAll();
bloc.dispose();
}
} }
/// A custom theme that will be injected into the widget tree. /// 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> { class _RenameDialogState extends State<_RenameDialog> {
final formKey = GlobalKey<FormState>(); 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() { void submit() {
if (formKey.currentState!.validate()) { if (formKey.currentState!.validate()) {

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

@ -55,6 +55,7 @@ class _NeonAppBarState extends State<NeonAppBar> {
@override @override
void dispose() { void dispose() {
_searchBarFocusNode.dispose();
unawaited(_searchTermSubscription.cancel()); unawaited(_searchTermSubscription.cancel());
unawaited(_searchTermController.close()); unawaited(_searchTermController.close());
super.dispose(); 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.uploadQueueParallelism.removeListener(_uploadParallelismListener);
options.downloadQueueParallelism.removeListener(_downloadParallelismListener); options.downloadQueueParallelism.removeListener(_downloadParallelismListener);
super.dispose();
} }
@override @override

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

@ -14,6 +14,12 @@ class _FilesCreateFolderDialogState extends State<FilesCreateFolderDialog> {
final controller = TextEditingController(); final controller = TextEditingController();
@override
void dispose() {
controller.dispose();
super.dispose();
}
void submit() { void submit() {
if (formKey.currentState!.validate()) { if (formKey.currentState!.validate()) {
Navigator.of(context).pop(controller.text.split('/')); 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 @override
Widget build(final BuildContext context) => ResultBuilder<List<NewsFolder>>.behaviorSubject( Widget build(final BuildContext context) => ResultBuilder<List<NewsFolder>>.behaviorSubject(
stream: widget.bloc.folders, 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(); final controller = TextEditingController();
@override
void dispose() {
controller.dispose();
super.dispose();
}
void submit() { void submit() {
if (formKey.currentState!.validate()) { if (formKey.currentState!.validate()) {
Navigator.of(context).pop(controller.text); 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(); final controller = TextEditingController();
String? selectedCategory; String? selectedCategory;
@override
void dispose() {
controller.dispose();
super.dispose();
}
void submit() { void submit() {
if (formKey.currentState!.validate()) { if (formKey.currentState!.validate()) {
Navigator.of(context).pop((controller.text, widget.category ?? selectedCategory)); 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> { class _NotesNotePageState extends State<NotesNotePage> {
late final _contentController = TextEditingController()..text = widget.bloc.initialContent; final _contentController = TextEditingController();
late final _titleController = TextEditingController()..text = widget.bloc.initialTitle; final _titleController = TextEditingController();
final _contentFocusNode = FocusNode(); final _contentFocusNode = FocusNode();
final _titleFocusNode = FocusNode(); final _titleFocusNode = FocusNode();
bool _showEditor = false; bool _showEditor = false;
@ -36,6 +36,9 @@ class _NotesNotePageState extends State<NotesNotePage> {
handleNotesException(context, error); handleNotesException(context, error);
}); });
_contentController.text = widget.bloc.initialContent;
_titleController.text = widget.bloc.initialTitle;
_contentStreamController.stream.debounceTime(const Duration(seconds: 1)).listen(widget.bloc.updateContent); _contentStreamController.stream.debounceTime(const Duration(seconds: 1)).listen(widget.bloc.updateContent);
_titleStreamController.stream.debounceTime(const Duration(seconds: 1)).listen(widget.bloc.updateTitle); _titleStreamController.stream.debounceTime(const Duration(seconds: 1)).listen(widget.bloc.updateTitle);
_contentController.addListener(() => _contentStreamController.add(_contentController.text)); _contentController.addListener(() => _contentStreamController.add(_contentController.text));
@ -56,6 +59,10 @@ class _NotesNotePageState extends State<NotesNotePage> {
@override @override
void dispose() { void dispose() {
_contentController.dispose();
_titleController.dispose();
_contentFocusNode.dispose();
_titleFocusNode.dispose();
unawaited(_contentStreamController.close()); unawaited(_contentStreamController.close());
unawaited(_titleStreamController.close()); unawaited(_titleStreamController.close());
super.dispose(); super.dispose();

Loading…
Cancel
Save