Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
fix: remove listeners (#6686)
Mathias Mogensen5e41849f69a5
diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/base/mobile_view_page.dart b/frontend/appflowy_flutter/lib/mobile/presentation/base/mobile_view_page.dartindex 7e11764f80..b6c23c3d8c 100644--- a/frontend/appflowy_flutter/lib/mobile/presentation/base/mobile_view_page.dart+++ b/frontend/appflowy_flutter/lib/mobile/presentation/base/mobile_view_page.dart@@ -65,6 +65,7 @@ class _MobileViewPageState extends State<MobileViewPage> {@overridevoid dispose() {_appBarOpacity.dispose();+ _scrollNotificationObserver?.removeListener(_onScrollNotification);_scrollNotificationObserver = null;super.dispose();diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/home/tab/mobile_space_tab.dart b/frontend/appflowy_flutter/lib/mobile/presentation/home/tab/mobile_space_tab.dartindex de9a51b814..12e40cf86c 100644--- a/frontend/appflowy_flutter/lib/mobile/presentation/home/tab/mobile_space_tab.dart+++ b/frontend/appflowy_flutter/lib/mobile/presentation/home/tab/mobile_space_tab.dart@@ -138,11 +138,9 @@ class _MobileSpaceTabState extends State<MobileSpaceTab>if (tabController == null) {return;}- context.read<SpaceOrderBloc>().add(- SpaceOrderEvent.open(- tabController!.index,- ),- );+ context+ .read<SpaceOrderBloc>()+ .add(SpaceOrderEvent.open(tabController!.index));}List<Widget> _buildTabs(SpaceOrderState state) {@@ -174,13 +172,9 @@ class _MobileSpaceTabState extends State<MobileSpaceTab>}// quick create new page when clicking the add button in navigation bar- void _createNewDocument() {- _createNewPage(ViewLayoutPB.Document);- }+ void _createNewDocument() => _createNewPage(ViewLayoutPB.Document);- void _createNewAIChat() {- _createNewPage(ViewLayoutPB.Chat);- }+ void _createNewAIChat() => _createNewPage(ViewLayoutPB.Chat);void _createNewPage(ViewLayoutPB layout) {if (context.read<SpaceBloc>().state.spaces.isNotEmpty) {@@ -206,8 +200,7 @@ class _MobileSpaceTabState extends State<MobileSpaceTab>final workspaceId =context.read<UserWorkspaceBloc>().state.currentWorkspace?.workspaceId;if (workspaceId == null) {- Log.error('Workspace ID is null');- return;+ return Log.error('Workspace ID is null');}context.read<UserWorkspaceBloc>()diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/notifications/mobile_notifications_screen.dart b/frontend/appflowy_flutter/lib/mobile/presentation/notifications/mobile_notifications_screen.dartindex b1219d8e98..54a0b4e782 100644--- a/frontend/appflowy_flutter/lib/mobile/presentation/notifications/mobile_notifications_screen.dart+++ b/frontend/appflowy_flutter/lib/mobile/presentation/notifications/mobile_notifications_screen.dart@@ -61,15 +61,11 @@ class _MobileNotificationsScreenV2State);}- void _onRefresh() {- getIt<ReminderBloc>().add(const ReminderEvent.refresh());- }+ void _onRefresh() => getIt<ReminderBloc>().add(const ReminderEvent.refresh());}class MobileNotificationsTab extends StatefulWidget {- const MobileNotificationsTab({- super.key,- });+ const MobileNotificationsTab({super.key});@overrideState<MobileNotificationsTab> createState() => _MobileNotificationsTabState();@@ -88,17 +84,12 @@ class _MobileNotificationsTabState extends State<MobileNotificationsTab>@overridevoid initState() {super.initState();-- tabController = TabController(- length: 3,- vsync: this,- );+ tabController = TabController(length: 3, vsync: this);}@overridevoid dispose() {tabController.dispose();-super.dispose();}diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/notifications/widgets/mobile_notification_tab_bar.dart b/frontend/appflowy_flutter/lib/mobile/presentation/notifications/widgets/mobile_notification_tab_bar.dartindex 471b456bc0..59bfe61822 100644--- a/frontend/appflowy_flutter/lib/mobile/presentation/notifications/widgets/mobile_notification_tab_bar.dart+++ b/frontend/appflowy_flutter/lib/mobile/presentation/notifications/widgets/mobile_notification_tab_bar.dart@@ -21,6 +21,12 @@ class _MobileNotificationTabBarState extends State<MobileNotificationTabBar> {widget.controller.addListener(_updateState);}+ @override+ void dispose() {+ widget.controller.removeListener(_updateState);+ super.dispose();+ }+void _updateState() => setState(() {});@overridediff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/chat.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/chat.dartindex 3d7c1609ac..d87f691038 100644--- a/frontend/appflowy_flutter/lib/plugins/ai_chat/chat.dart+++ b/frontend/appflowy_flutter/lib/plugins/ai_chat/chat.dart@@ -98,12 +98,7 @@ class AIChatPagePluginWidgetBuilder extends PluginWidgetBuilderrequired bool shrinkWrap,Map<String, dynamic>? data,}) {- notifier.isDeleted.addListener(() {- final deletedView = notifier.isDeleted.value;- if (deletedView != null && deletedView.hasIndex()) {- deletedViewIndex = deletedView.index;- }- });+ notifier.isDeleted.addListener(_onDeleted);if (context.userProfile == null) {Log.error("User profile is null when opening AI Chat plugin");@@ -122,6 +117,13 @@ class AIChatPagePluginWidgetBuilder extends PluginWidgetBuilder);}+ void _onDeleted() {+ final deletedView = notifier.isDeleted.value;+ if (deletedView != null && deletedView.hasIndex()) {+ deletedViewIndex = deletedView.index;+ }+ }+@overrideList<NavigationItem> get navigationItems => [this];diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_input/chat_input.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_input/chat_input.dartindex 3d3aa3fe00..5f7aed9b40 100644--- a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_input/chat_input.dart+++ b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_input/chat_input.dart@@ -86,9 +86,7 @@ class _ChatInputState extends State<ChatInput> {},);- _inputFocusNode.addListener(() {- setState(() {});- });+ _inputFocusNode.addListener(_updateState);_inputActionControl = ChatInputActionControl(chatId: widget.chatId,@@ -101,12 +99,15 @@ class _ChatInputState extends State<ChatInput> {@overridevoid dispose() {+ _inputFocusNode.removeListener(_updateState);_inputFocusNode.dispose();_textController.dispose();_inputActionControl.dispose();super.dispose();}+ void _updateState() => setState(() {});+@overrideWidget build(BuildContext context) {return Padding(diff --git a/frontend/appflowy_flutter/lib/plugins/database/application/database_controller.dart b/frontend/appflowy_flutter/lib/plugins/database/application/database_controller.dartindex 382bf8ab63..5d0bb760fe 100644--- a/frontend/appflowy_flutter/lib/plugins/database/application/database_controller.dart+++ b/frontend/appflowy_flutter/lib/plugins/database/application/database_controller.dart@@ -132,6 +132,24 @@ class DatabaseController {}}+ void removeListener({+ DatabaseCallbacks? onDatabaseChanged,+ DatabaseLayoutSettingCallbacks? onLayoutSettingsChanged,+ GroupCallbacks? onGroupChanged,+ }) {+ if (onDatabaseChanged != null) {+ _databaseCallbacks.remove(onDatabaseChanged);+ }++ if (onLayoutSettingsChanged != null) {+ _layoutCallbacks.remove(onLayoutSettingsChanged);+ }++ if (onGroupChanged != null) {+ _groupCallbacks.remove(onGroupChanged);+ }+ }+Future<FlowyResult<void, FlowyError>> open() async {return _databaseViewBackendSvc.openDatabase().then((result) {return result.fold(diff --git a/frontend/appflowy_flutter/lib/plugins/database/board/application/board_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/board/application/board_bloc.dartindex 2807913ce1..a2c6c89578 100644--- a/frontend/appflowy_flutter/lib/plugins/database/board/application/board_bloc.dart+++ b/frontend/appflowy_flutter/lib/plugins/database/board/application/board_bloc.dart@@ -55,6 +55,10 @@ class BoardBloc extends Bloc<BoardEvent, BoardState> {FieldController get fieldController => databaseController.fieldController;String get viewId => databaseController.viewId;+ DatabaseCallbacks? _databaseCallbacks;+ DatabaseLayoutSettingCallbacks? _layoutSettingsCallback;+ GroupCallbacks? _groupCallbacks;+void _initBoardController(AppFlowyBoardController? controller) {boardController = controller ??AppFlowyBoardController(@@ -330,6 +334,17 @@ class BoardBloc extends Bloc<BoardEvent, BoardState> {for (final controller in groupControllers.values) {await controller.dispose();}++ databaseController.removeListener(+ onDatabaseChanged: _databaseCallbacks,+ onLayoutSettingsChanged: _layoutSettingsCallback,+ onGroupChanged: _groupCallbacks,+ );++ _databaseCallbacks = null;+ _layoutSettingsCallback = null;+ _groupCallbacks = null;+boardController.dispose();return super.close();}@@ -380,7 +395,7 @@ class BoardBloc extends Bloc<BoardEvent, BoardState> {RowCache get rowCache => databaseController.rowCache;void _startListening() {- final onLayoutSettingsChanged = DatabaseLayoutSettingCallbacks(+ _layoutSettingsCallback = DatabaseLayoutSettingCallbacks(onLayoutSettingsChanged: (layoutSettings) {if (isClosed) {return;@@ -403,7 +418,7 @@ class BoardBloc extends Bloc<BoardEvent, BoardState> {add(BoardEvent.didUpdateLayoutSettings(layoutSettings.board));},);- final onGroupChanged = GroupCallbacks(+ _groupCallbacks = GroupCallbacks(onGroupByField: (groups) {if (isClosed) {return;@@ -482,7 +497,7 @@ class BoardBloc extends Bloc<BoardEvent, BoardState> {add(BoardEvent.didReceiveGroups(groupList));},);- final onDatabaseChanged = DatabaseCallbacks(+ _databaseCallbacks = DatabaseCallbacks(onRowsCreated: (rows) {for (final row in rows) {if (!isClosed && row.isHiddenInView) {@@ -493,9 +508,9 @@ class BoardBloc extends Bloc<BoardEvent, BoardState> {);databaseController.addListener(- onDatabaseChanged: onDatabaseChanged,- onLayoutSettingsChanged: onLayoutSettingsChanged,- onGroupChanged: onGroupChanged,+ onDatabaseChanged: _databaseCallbacks,+ onLayoutSettingsChanged: _layoutSettingsCallback,+ onGroupChanged: _groupCallbacks,);}diff --git a/frontend/appflowy_flutter/lib/plugins/database/board/presentation/widgets/board_editable_column_header.dart b/frontend/appflowy_flutter/lib/plugins/database/board/presentation/widgets/board_editable_column_header.dartindex bc07ddf3c1..e6ecca43bc 100644--- a/frontend/appflowy_flutter/lib/plugins/database/board/presentation/widgets/board_editable_column_header.dart+++ b/frontend/appflowy_flutter/lib/plugins/database/board/presentation/widgets/board_editable_column_header.dart@@ -51,17 +51,7 @@ class _EditableColumnHeaderState extends State<EditableColumnHeader> {}return KeyEventResult.ignored;},- )..addListener(() {- if (!focusNode.hasFocus) {- widget.isEditing.value = false;- widget.onSubmitted(textController.text);- } else {- textController.selection = TextSelection(- baseOffset: 0,- extentOffset: textController.text.length,- );- }- });+ )..addListener(onFocusChanged);}@override@@ -74,11 +64,25 @@ class _EditableColumnHeaderState extends State<EditableColumnHeader> {@overridevoid dispose() {- focusNode.dispose();+ focusNode+ ..removeListener(onFocusChanged)+ ..dispose();textController.dispose();super.dispose();}+ void onFocusChanged() {+ if (!focusNode.hasFocus) {+ widget.isEditing.value = false;+ widget.onSubmitted(textController.text);+ } else {+ textController.selection = TextSelection(+ baseOffset: 0,+ extentOffset: textController.text.length,+ );+ }+ }+@overrideWidget build(BuildContext context) {return Row(diff --git a/frontend/appflowy_flutter/lib/plugins/database/calendar/application/calendar_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/calendar/application/calendar_bloc.dartindex 6798bd9934..45157b1a47 100644--- a/frontend/appflowy_flutter/lib/plugins/database/calendar/application/calendar_bloc.dart+++ b/frontend/appflowy_flutter/lib/plugins/database/calendar/application/calendar_bloc.dart@@ -37,6 +37,20 @@ class CalendarBloc extends Bloc<CalendarEvent, CalendarState> {UserProfilePB? _userProfile;UserProfilePB? get userProfile => _userProfile;+ DatabaseCallbacks? _databaseCallbacks;+ DatabaseLayoutSettingCallbacks? _layoutSettingCallbacks;++ @override+ Future<void> close() async {+ databaseController.removeListener(+ onDatabaseChanged: _databaseCallbacks,+ onLayoutSettingsChanged: _layoutSettingCallbacks,+ );+ _databaseCallbacks = null;+ _layoutSettingCallbacks = null;+ await super.close();+ }+void _dispatch() {on<CalendarEvent>((event, emit) async {@@ -300,7 +314,7 @@ class CalendarBloc extends Bloc<CalendarEvent, CalendarState> {}void _startListening() {- final onDatabaseChanged = DatabaseCallbacks(+ _databaseCallbacks = DatabaseCallbacks(onDatabaseChanged: (database) {if (isClosed) return;},@@ -375,13 +389,13 @@ class CalendarBloc extends Bloc<CalendarEvent, CalendarState> {},);- final onLayoutSettingsChanged = DatabaseLayoutSettingCallbacks(+ _layoutSettingCallbacks = DatabaseLayoutSettingCallbacks(onLayoutSettingsChanged: _didReceiveLayoutSetting,);databaseController.addListener(- onDatabaseChanged: onDatabaseChanged,- onLayoutSettingsChanged: onLayoutSettingsChanged,+ onDatabaseChanged: _databaseCallbacks,+ onLayoutSettingsChanged: _layoutSettingCallbacks,);}diff --git a/frontend/appflowy_flutter/lib/plugins/database/calendar/application/unschedule_event_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/calendar/application/unschedule_event_bloc.dartindex 83cce129be..1e67ad9e9d 100644--- a/frontend/appflowy_flutter/lib/plugins/database/calendar/application/unschedule_event_bloc.dart+++ b/frontend/appflowy_flutter/lib/plugins/database/calendar/application/unschedule_event_bloc.dart@@ -29,6 +29,15 @@ class UnscheduleEventsBlocCellMemCache get cellCache => databaseController.rowCache.cellCache;RowCache get rowCache => databaseController.rowCache;+ DatabaseCallbacks? _databaseCallbacks;++ @override+ Future<void> close() async {+ databaseController.removeListener(onDatabaseChanged: _databaseCallbacks);+ _databaseCallbacks = null;+ await super.close();+ }+void _dispatch() {on<UnscheduleEventsEvent>((event, emit) async {@@ -103,7 +112,7 @@ class UnscheduleEventsBloc}void _startListening() {- final onDatabaseChanged = DatabaseCallbacks(+ _databaseCallbacks = DatabaseCallbacks(onRowsCreated: (rows) async {if (isClosed) {return;@@ -135,7 +144,7 @@ class UnscheduleEventsBloc},);- databaseController.addListener(onDatabaseChanged: onDatabaseChanged);+ databaseController.addListener(onDatabaseChanged: _databaseCallbacks);}}diff --git a/frontend/appflowy_flutter/lib/plugins/database/grid/application/filter/filter_editor_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/grid/application/filter/filter_editor_bloc.dartindex a43c1bec47..6a386ff130 100644--- a/frontend/appflowy_flutter/lib/plugins/database/grid/application/filter/filter_editor_bloc.dart+++ b/frontend/appflowy_flutter/lib/plugins/database/grid/application/filter/filter_editor_bloc.dart@@ -80,12 +80,8 @@ class FilterEditorBloc extends Bloc<FilterEditorEvent, FilterEditorState> {};fieldController.addListener(- onFilters: (filters) {- _onFilterFn?.call(filters);- },- onReceiveFields: (fields) {- _onFieldFn?.call(fields);- },+ onFilters: _onFilterFn,+ onReceiveFields: _onFieldFn,);}diff --git a/frontend/appflowy_flutter/lib/plugins/database/grid/application/grid_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/grid/application/grid_bloc.dartindex 12afc9ca50..a9aab132a0 100644--- a/frontend/appflowy_flutter/lib/plugins/database/grid/application/grid_bloc.dart+++ b/frontend/appflowy_flutter/lib/plugins/database/grid/application/grid_bloc.dart@@ -32,6 +32,15 @@ class GridBloc extends Bloc<GridEvent, GridState> {UserProfilePB? _userProfile;UserProfilePB? get userProfile => _userProfile;+ DatabaseCallbacks? _databaseCallbacks;++ @override+ Future<void> close() async {+ databaseController.removeListener(onDatabaseChanged: _databaseCallbacks);+ _databaseCallbacks = null;+ await super.close();+ }+void _dispatch() {on<GridEvent>((event, emit) async {@@ -120,7 +129,7 @@ class GridBloc extends Bloc<GridEvent, GridState> {RowCache get rowCache => databaseController.rowCache;void _startListening() {- final onDatabaseChanged = DatabaseCallbacks(+ _databaseCallbacks = DatabaseCallbacks(onNumOfRowsChanged: (rowInfos, _, reason) {if (!isClosed) {add(GridEvent.didLoadRows(rowInfos, reason));@@ -157,7 +166,7 @@ class GridBloc extends Bloc<GridEvent, GridState> {}},);- databaseController.addListener(onDatabaseChanged: onDatabaseChanged);+ databaseController.addListener(onDatabaseChanged: _databaseCallbacks);}Future<void> _openGrid(Emitter<GridState> emit) async {diff --git a/frontend/appflowy_flutter/lib/plugins/database/grid/application/grid_header_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/grid/application/grid_header_bloc.dartindex b9fa5b7e92..a869b636d2 100644--- a/frontend/appflowy_flutter/lib/plugins/database/grid/application/grid_header_bloc.dart+++ b/frontend/appflowy_flutter/lib/plugins/database/grid/application/grid_header_bloc.dart@@ -20,6 +20,12 @@ class GridHeaderBloc extends Bloc<GridHeaderEvent, GridHeaderState> {final String viewId;final FieldController fieldController;+ @override+ Future<void> close() async {+ fieldController.removeListener(onFieldsListener: _onReceiveFields);+ await super.close();+ }+void _dispatch() {on<GridHeaderEvent>((event, emit) async {@@ -82,11 +88,13 @@ class GridHeaderBloc extends Bloc<GridHeaderEvent, GridHeaderState> {void _startListening() {fieldController.addListener(- onReceiveFields: (fields) =>- add(GridHeaderEvent.didReceiveFieldUpdate(fields)),+ onReceiveFields: _onReceiveFields,listenWhen: () => !isClosed,);}++ void _onReceiveFields(List<FieldInfo> fields) =>+ add(GridHeaderEvent.didReceiveFieldUpdate(fields));}@freezeddiff --git a/frontend/appflowy_flutter/lib/plugins/database/grid/application/row/mobile_row_detail_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/grid/application/row/mobile_row_detail_bloc.dartindex d70dae3804..ec42cd5cac 100644--- a/frontend/appflowy_flutter/lib/plugins/database/grid/application/row/mobile_row_detail_bloc.dart+++ b/frontend/appflowy_flutter/lib/plugins/database/grid/application/row/mobile_row_detail_bloc.dart@@ -24,6 +24,15 @@ class MobileRowDetailBlocUserProfilePB? _userProfile;UserProfilePB? get userProfile => _userProfile;+ DatabaseCallbacks? _databaseCallbacks;++ @override+ Future<void> close() async {+ databaseController.removeListener(onDatabaseChanged: _databaseCallbacks);+ _databaseCallbacks = null;+ await super.close();+ }+void _dispatch() {on<MobileRowDetailEvent>((event, emit) {@@ -67,7 +76,7 @@ class MobileRowDetailBloc}void _startListening() {- final onDatabaseChanged = DatabaseCallbacks(+ _databaseCallbacks = DatabaseCallbacks(onNumOfRowsChanged: (rowInfos, _, reason) {if (!isClosed) {add(MobileRowDetailEvent.didLoadRows(rowInfos));@@ -83,7 +92,7 @@ class MobileRowDetailBloc}},);- databaseController.addListener(onDatabaseChanged: onDatabaseChanged);+ databaseController.addListener(onDatabaseChanged: _databaseCallbacks);}}diff --git a/frontend/appflowy_flutter/lib/plugins/database/grid/application/row/row_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/grid/application/row/row_bloc.dartindex 2267870b02..402ae6e596 100644--- a/frontend/appflowy_flutter/lib/plugins/database/grid/application/row/row_bloc.dart+++ b/frontend/appflowy_flutter/lib/plugins/database/grid/application/row/row_bloc.dart@@ -70,14 +70,13 @@ class RowBloc extends Bloc<RowEvent, RowState> {);}- void _startListening() {- _rowController.addListener(- onRowChanged: (cells, reason) {- if (!isClosed) {- add(RowEvent.didReceiveCells(cells, reason));- }- },- );+ void _startListening() =>+ _rowController.addListener(onRowChanged: _onRowChanged);++ void _onRowChanged(List<CellContext> cells, ChangedReason reason) {+ if (!isClosed) {+ add(RowEvent.didReceiveCells(cells, reason));+ }}void _init() {diff --git a/frontend/appflowy_flutter/lib/plugins/database/widgets/card/card.dart b/frontend/appflowy_flutter/lib/plugins/database/widgets/card/card.dartindex 6c3a0f7544..e7c6150448 100644--- a/frontend/appflowy_flutter/lib/plugins/database/widgets/card/card.dart+++ b/frontend/appflowy_flutter/lib/plugins/database/widgets/card/card.dart@@ -311,6 +311,7 @@ class _CardContentCellState extends State<_CardContentCell> {@overridevoid dispose() {+ cellNotifier?.isCellEditing.removeListener(listener);cellNotifier?.dispose();super.dispose();}diff --git a/frontend/appflowy_flutter/lib/plugins/database/widgets/cell/desktop_row_detail/desktop_row_detail_checklist_cell.dart b/frontend/appflowy_flutter/lib/plugins/database/widgets/cell/desktop_row_detail/desktop_row_detail_checklist_cell.dartindex 48d49f85aa..ac6e722425 100644--- a/frontend/appflowy_flutter/lib/plugins/database/widgets/cell/desktop_row_detail/desktop_row_detail_checklist_cell.dart+++ b/frontend/appflowy_flutter/lib/plugins/database/widgets/cell/desktop_row_detail/desktop_row_detail_checklist_cell.dart@@ -285,28 +285,30 @@ class _PhantomChecklistItemState extends State<PhantomChecklistItem> {@overridevoid initState() {super.initState();- textController.addListener(() {- setState(() {- isComposing = !textController.value.composing.isCollapsed;- });- });- focusNode.addListener(() {- if (!focusNode.hasFocus) {- textController.clear();- Actions.maybeInvoke(- context,- const _CancelCreatingFromPhantomIntent(),- );- }- });- WidgetsBinding.instance.addPostFrameCallback((_) {- focusNode.requestFocus();- });+ textController.addListener(_onTextChanged);+ focusNode.addListener(_onFocusChanged);+ WidgetsBinding.instance+ .addPostFrameCallback((_) => focusNode.requestFocus());+ }++ void _onTextChanged() =>+ setState(() => isComposing = !textController.value.composing.isCollapsed);++ void _onFocusChanged() {+ if (!focusNode.hasFocus) {+ textController.clear();+ Actions.maybeInvoke(+ context,+ const _CancelCreatingFromPhantomIntent(),+ );+ }}@overridevoid dispose() {+ textController.removeListener(_onTextChanged);textController.dispose();+ focusNode.removeListener(_onFocusChanged);focusNode.dispose();super.dispose();}diff --git a/frontend/appflowy_flutter/lib/plugins/database/widgets/cell/editable_cell_builder.dart b/frontend/appflowy_flutter/lib/plugins/database/widgets/cell/editable_cell_builder.dartindex 9e0f334ec8..e7b5d0d79b 100755--- a/frontend/appflowy_flutter/lib/plugins/database/widgets/cell/editable_cell_builder.dart+++ b/frontend/appflowy_flutter/lib/plugins/database/widgets/cell/editable_cell_builder.dart@@ -289,6 +289,7 @@ abstract class GridCellState<T extends EditableCellWidget> extends State<T> {@overridevoid didUpdateWidget(covariant T oldWidget) {if (oldWidget != this) {+ oldWidget.requestFocus.removeListener(onRequestFocus);widget.requestFocus.addListener(onRequestFocus);}super.didUpdateWidget(oldWidget);diff --git a/frontend/appflowy_flutter/lib/plugins/database/widgets/cell_editor/checklist_cell_editor.dart b/frontend/appflowy_flutter/lib/plugins/database/widgets/cell_editor/checklist_cell_editor.dartindex ae924fc3ef..488bd27135 100644--- a/frontend/appflowy_flutter/lib/plugins/database/widgets/cell_editor/checklist_cell_editor.dart+++ b/frontend/appflowy_flutter/lib/plugins/database/widgets/cell_editor/checklist_cell_editor.dart@@ -201,11 +201,7 @@ class _ChecklistItemState extends State<ChecklistItem> {void initState() {super.initState();textController.text = widget.task.data.name;- textController.addListener(() {- setState(() {- isComposing = !textController.value.composing.isCollapsed;- });- });+ textController.addListener(_onTextChanged);if (widget.autofocus) {WidgetsBinding.instance.addPostFrameCallback((_) {focusNode.requestFocus();@@ -214,6 +210,9 @@ class _ChecklistItemState extends State<ChecklistItem> {}}+ void _onTextChanged() =>+ setState(() => isComposing = !textController.value.composing.isCollapsed);+@overridevoid didUpdateWidget(covariant oldWidget) {if (!focusNode.hasFocus &&@@ -227,6 +226,7 @@ class _ChecklistItemState extends State<ChecklistItem> {void dispose() {_debounceOnChanged.dispose();+ textController.removeListener(_onTextChanged);textController.dispose();focusNode.dispose();textFieldFocusNode.dispose();@@ -241,25 +241,14 @@ class _ChecklistItemState extends State<ChecklistItem> {: Colors.transparent;return FocusableActionDetector(focusNode: focusNode,- onShowHoverHighlight: (value) => setState(() {- isHovered = value;- }),- onFocusChange: (value) => setState(() {- isFocused = value;- }),+ onShowHoverHighlight: (value) => setState(() => isHovered = value),+ onFocusChange: (value) => setState(() => isFocused = value),actions: _buildActions(),shortcuts: _buildShortcuts(),child: Container(- constraints: BoxConstraints(- minHeight: GridSize.popoverItemHeight,- ),- decoration: BoxDecoration(- color: color,- borderRadius: Corners.s6Border,- ),- child: _buildChild(- isFocusedOrHovered && !textFieldFocusNode.hasFocus,- ),+ constraints: BoxConstraints(minHeight: GridSize.popoverItemHeight),+ decoration: BoxDecoration(color: color, borderRadius: Corners.s6Border),+ child: _buildChild(isFocusedOrHovered && !textFieldFocusNode.hasFocus),),);}@@ -288,9 +277,7 @@ class _ChecklistItemState extends State<ChecklistItem> {),),),- ChecklistCellCheckIcon(- task: widget.task,- ),+ ChecklistCellCheckIcon(task: widget.task),Expanded(child: ChecklistCellTextfield(textController: textController,@@ -315,9 +302,9 @@ class _ChecklistItemState extends State<ChecklistItem> {),if (showTrash)ChecklistCellDeleteButton(- onPressed: () => context.read<ChecklistCellBloc>().add(- ChecklistCellEvent.deleteTask(widget.task.data.id),- ),+ onPressed: () => context+ .read<ChecklistCellBloc>()+ .add(ChecklistCellEvent.deleteTask(widget.task.data.id)),),],);@@ -366,14 +353,9 @@ class _ChecklistItemState extends State<ChecklistItem> {};}- void _submitUpdateTaskDescription(String description) {- context.read<ChecklistCellBloc>().add(- ChecklistCellEvent.updateTaskName(- widget.task.data,- description,- ),- );- }+ void _submitUpdateTaskDescription(String description) => context+ .read<ChecklistCellBloc>()+ .add(ChecklistCellEvent.updateTaskName(widget.task.data, description));}/// Creates a new task after entering the description and pressing enter.@@ -397,18 +379,18 @@ class _NewTaskItemState extends State<NewTaskItem> {@overridevoid initState() {super.initState();- textController.addListener(() {- setState(() {- isComposing = !textController.value.composing.isCollapsed;- });- });+ textController.addListener(_onTextChanged);if (widget.focusNode.canRequestFocus) {widget.focusNode.requestFocus();}}+ void _onTextChanged() =>+ setState(() => isComposing = !textController.value.composing.isCollapsed);+@overridevoid dispose() {+ textController.removeListener(_onTextChanged);textController.dispose();super.dispose();}@@ -444,7 +426,7 @@ class _NewTaskItemState extends State<NewTaskItem> {hintText: LocaleKeys.grid_checklist_addNew.tr(),),onSubmitted: (_) => _createNewTask(context),- onChanged: (value) => setState(+ onChanged: (_) => setState(() => isCreateButtonEnabled = textController.text.isNotEmpty,),),@@ -464,9 +446,7 @@ class _NewTaskItemState extends State<NewTaskItem> {onPressed: isCreateButtonEnabled? () {context.read<ChecklistCellBloc>().add(- ChecklistCellEvent.createNewTask(- textController.text,- ),+ ChecklistCellEvent.createNewTask(textController.text),);widget.focusNode.requestFocus();textController.clear();diff --git a/frontend/appflowy_flutter/lib/plugins/database/widgets/cell_editor/select_option_text_field.dart b/frontend/appflowy_flutter/lib/plugins/database/widgets/cell_editor/select_option_text_field.dartindex 2a4b8daa37..a03167df9d 100644--- a/frontend/appflowy_flutter/lib/plugins/database/widgets/cell_editor/select_option_text_field.dart+++ b/frontend/appflowy_flutter/lib/plugins/database/widgets/cell_editor/select_option_text_field.dart@@ -60,6 +60,12 @@ class _SelectOptionTextFieldState extends State<SelectOptionTextField> {_scrollToEnd();});}++ if (oldWidget.textController != widget.textController) {+ oldWidget.textController.removeListener(_onChanged);+ widget.textController.addListener(_onChanged);+ }+super.didUpdateWidget(oldWidget);}diff --git a/frontend/appflowy_flutter/lib/plugins/database/widgets/row/row_detail.dart b/frontend/appflowy_flutter/lib/plugins/database/widgets/row/row_detail.dartindex f4e981a8b8..920180ad0f 100644--- a/frontend/appflowy_flutter/lib/plugins/database/widgets/row/row_detail.dart+++ b/frontend/appflowy_flutter/lib/plugins/database/widgets/row/row_detail.dart@@ -42,9 +42,8 @@ class RowDetailPage extends StatefulWidget with FlowyOverlayDelegate {}class _RowDetailPageState extends State<RowDetailPage> {- late final cellBuilder = EditableCellBuilder(- databaseController: widget.databaseController,- );+ late final cellBuilder =+ EditableCellBuilder(databaseController: widget.databaseController);late final ScrollController scrollController;double scrollOffset = 0;@@ -52,9 +51,8 @@ class _RowDetailPageState extends State<RowDetailPage> {@overridevoid initState() {super.initState();- scrollController = ScrollController(- onAttach: (_) => attachScrollListener(),- );+ scrollController =+ ScrollController(onAttach: (_) => attachScrollListener());}void attachScrollListener() => scrollController.addListener(onScrollChanged);@@ -120,9 +118,7 @@ class _RowDetailPageState extends State<RowDetailPage> {state.rowMeta.cover.data.isNotEmpty,),right: 12,- child: Row(- children: actions(context),- ),+ child: Row(children: actions(context)),),],),diff --git a/frontend/appflowy_flutter/lib/plugins/document/application/document_bloc.dart b/frontend/appflowy_flutter/lib/plugins/document/application/document_bloc.dartindex fe4434fa87..dcf1c2e2b7 100644--- a/frontend/appflowy_flutter/lib/plugins/document/application/document_bloc.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/application/document_bloc.dart@@ -116,6 +116,8 @@ class DocumentBloc extends Bloc<DocumentEvent, DocumentState> {_syncTimer?.cancel();_syncTimer = null;+ state.editorState?.selectionNotifier+ .removeListener(_debounceOnSelectionUpdate);state.editorState?.service.keyboardService?.closeKeyboard();state.editorState?.dispose();}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dartindex a23c90a972..2f43c2c0b5 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart@@ -408,7 +408,6 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage>heading1SlashMenuItem,heading2SlashMenuItem,heading3SlashMenuItem,-imageSlashMenuItem,bulletedListSlashMenuItem,numberedListSlashMenuItem,diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/cover_title.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/cover_title.dartindex f5ad854d1c..72c88b9351 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/cover_title.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/cover_title.dart@@ -59,30 +59,9 @@ class _InnerCoverTitleState extends State<_InnerCoverTitle> {titleTextController.text = widget.view.name;titleTextController.addListener(_onViewNameChanged);titleFocusNode.onKeyEvent = _onKeyEvent;- titleFocusNode.addListener(() {- isTitleFocused = titleFocusNode.hasFocus;+ titleFocusNode.addListener(_onTitleFocusChanged);- if (titleFocusNode.hasFocus && editorState.selection != null) {- Log.info('cover title got focus, clear the editor selection');- editorState.selection = null;- }-- if (isTitleFocused) {- Log.info('cover title got focus, disable keyboard service');- editorState.service.keyboardService?.disable();- } else {- Log.info('cover title lost focus, enable keyboard service');- editorState.service.keyboardService?.enable();- }- });-- editorState.selectionNotifier.addListener(() {- // if title is focused and the selection is not null, clear the selection- if (editorState.selection != null && isTitleFocused) {- Log.info('title is focused, clear the editor selection');- editorState.selection = null;- }- });+ editorState.selectionNotifier.addListener(_onSelectionChanged);_requestFocusIfNeeded(widget.view, null);editorContext.coverTitleFocusNode = titleFocusNode;@@ -91,13 +70,41 @@ class _InnerCoverTitleState extends State<_InnerCoverTitle> {@overridevoid dispose() {editorContext.coverTitleFocusNode = null;+ editorState.selectionNotifier.removeListener(_onSelectionChanged);+ titleTextController.removeListener(_onViewNameChanged);titleTextController.dispose();+ titleFocusNode.removeListener(_onTitleFocusChanged);titleFocusNode.dispose();super.dispose();}+ void _onSelectionChanged() {+ // if title is focused and the selection is not null, clear the selection+ if (editorState.selection != null && isTitleFocused) {+ Log.info('title is focused, clear the editor selection');+ editorState.selection = null;+ }+ }++ void _onTitleFocusChanged() {+ isTitleFocused = titleFocusNode.hasFocus;++ if (titleFocusNode.hasFocus && editorState.selection != null) {+ Log.info('cover title got focus, clear the editor selection');+ editorState.selection = null;+ }++ if (isTitleFocused) {+ Log.info('cover title got focus, disable keyboard service');+ editorState.service.keyboardService?.disable();+ } else {+ Log.info('cover title lost focus, enable keyboard service');+ editorState.service.keyboardService?.enable();+ }+ }+@overrideWidget build(BuildContext context) {final fontStyle = Theme.of(context)diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/custom_cover_picker.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/custom_cover_picker.dartindex 087d987262..3f84d04283 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/custom_cover_picker.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/custom_cover_picker.dart@@ -111,11 +111,14 @@ class _NetworkImageUrlInputState extends State<NetworkImageUrlInput> {@overridevoid initState() {super.initState();- urlController.addListener(() => setState(() {}));+ urlController.addListener(_updateState);}+ void _updateState() => setState(() {});+@overridevoid dispose() {+ urlController.removeListener(_updateState);urlController.dispose();super.dispose();}diff --git a/frontend/appflowy_flutter/lib/plugins/shared/share/publish_tab.dart b/frontend/appflowy_flutter/lib/plugins/shared/share/publish_tab.dartindex 493d93cdc2..4a2ab0fe4b 100644--- a/frontend/appflowy_flutter/lib/plugins/shared/share/publish_tab.dart+++ b/frontend/appflowy_flutter/lib/plugins/shared/share/publish_tab.dart@@ -402,18 +402,15 @@ class _PublishUrlState extends State<_PublishUrl> {@overridevoid initState() {super.initState();-- focusNode.addListener(() {- setState(() {- showSaveButton = focusNode.hasFocus;- });- });+ focusNode.addListener(_onFocusChanged);}+ void _onFocusChanged() => setState(() => showSaveButton = focusNode.hasFocus);+@overridevoid dispose() {+ focusNode.removeListener(_onFocusChanged);focusNode.dispose();-super.dispose();}@@ -539,12 +536,7 @@ class _PublishDatabaseSelectorState extends State<_PublishDatabaseSelector> {void initState() {super.initState();- _databaseStatus.addListener(() {- final selectedDatabases =- _databaseStatus.value.where((e) => e.$2).map((e) => e.$1).toList();- widget.onSelected(selectedDatabases);- });-+ _databaseStatus.addListener(_onDatabaseStatusChanged);_databaseStatus.value = context.read<DatabaseTabBarBloc>().state@@ -553,8 +545,15 @@ class _PublishDatabaseSelectorState extends State<_PublishDatabaseSelector> {.toList();}+ void _onDatabaseStatusChanged() {+ final selectedDatabases =+ _databaseStatus.value.where((e) => e.$2).map((e) => e.$1).toList();+ widget.onSelected(selectedDatabases);+ }+@overridevoid dispose() {+ _databaseStatus.removeListener(_onDatabaseStatusChanged);_databaseStatus.dispose();super.dispose();}diff --git a/frontend/appflowy_flutter/lib/shared/popup_menu/appflowy_popup_menu.dart b/frontend/appflowy_flutter/lib/shared/popup_menu/appflowy_popup_menu.dartindex c0501c182c..1e9aa1a3c3 100644--- a/frontend/appflowy_flutter/lib/shared/popup_menu/appflowy_popup_menu.dart+++ b/frontend/appflowy_flutter/lib/shared/popup_menu/appflowy_popup_menu.dart@@ -524,11 +524,15 @@ class _CheckedPopupMenuItemState<T>super.initState();_controller = AnimationController(duration: _fadeDuration, vsync: this)..value = widget.checked ? 1.0 : 0.0- ..addListener(() => setState(() {/* animation changed */}));+ ..addListener(_updateState);}+ // Called when animation changed+ void _updateState() => setState(() {});+@overridevoid dispose() {+ _controller.removeListener(_updateState);_controller.dispose();super.dispose();}diff --git a/frontend/appflowy_flutter/lib/shared/window_title_bar.dart b/frontend/appflowy_flutter/lib/shared/window_title_bar.dartindex 726244b22a..4738be78f3 100644--- a/frontend/appflowy_flutter/lib/shared/window_title_bar.dart+++ b/frontend/appflowy_flutter/lib/shared/window_title_bar.dart@@ -40,28 +40,30 @@ class _WindowTitleBarState extends State<WindowTitleBar> {if (UniversalPlatform.isWindows || UniversalPlatform.isLinux) {windowsButtonListener = WindowsButtonListener();windowManager.addListener(windowsButtonListener!);- windowsButtonListener!.isMaximized.addListener(() {- if (mounted) {- setState(- () => isMaximized = windowsButtonListener!.isMaximized.value,- );- }- });+ windowsButtonListener!.isMaximized.addListener(_isMaximizedChanged);} else {windowsButtonListener = null;}- windowManager.isMaximized().then(- (v) => mounted ? setState(() => isMaximized = v) : null,- );+ windowManager+ .isMaximized()+ .then((v) => mounted ? setState(() => isMaximized = v) : null);+ }++ void _isMaximizedChanged() {+ if (mounted) {+ setState(() => isMaximized = windowsButtonListener!.isMaximized.value);+ }}@overridevoid dispose() {if (windowsButtonListener != null) {windowManager.removeListener(windowsButtonListener!);+ windowsButtonListener!.isMaximized.removeListener(_isMaximizedChanged);windowsButtonListener?.dispose();}+super.dispose();}diff --git a/frontend/appflowy_flutter/lib/startup/tasks/windows.dart b/frontend/appflowy_flutter/lib/startup/tasks/windows.dartindex 4bf4ad5190..20b8b0b56e 100644--- a/frontend/appflowy_flutter/lib/startup/tasks/windows.dart+++ b/frontend/appflowy_flutter/lib/startup/tasks/windows.dart@@ -129,5 +129,7 @@ class InitAppWindowTask extends LaunchTask with WindowListener {}@override- Future<void> dispose() async {}+ Future<void> dispose() async {+ windowManager.removeListener(this);+ }}diff --git a/frontend/appflowy_flutter/lib/workspace/application/settings/ai/local_ai_on_boarding_bloc.dart b/frontend/appflowy_flutter/lib/workspace/application/settings/ai/local_ai_on_boarding_bloc.dartindex 902cb948b8..39a02b0964 100644--- a/frontend/appflowy_flutter/lib/workspace/application/settings/ai/local_ai_on_boarding_bloc.dart+++ b/frontend/appflowy_flutter/lib/workspace/application/settings/ai/local_ai_on_boarding_bloc.dart@@ -15,11 +15,8 @@ part 'local_ai_on_boarding_bloc.freezed.dart';class LocalAIOnBoardingBlocextends Bloc<LocalAIOnBoardingEvent, LocalAIOnBoardingState> {- LocalAIOnBoardingBloc(- this.userProfile,- this.member,- this.workspaceId,- ) : super(const LocalAIOnBoardingState()) {+ LocalAIOnBoardingBloc(this.userProfile, this.member, this.workspaceId)+ : super(const LocalAIOnBoardingState()) {_userService = UserBackendService(userId: userProfile.id);_successListenable = getIt<SubscriptionSuccessListenable>();_successListenable.addListener(_onPaymentSuccessful);@@ -44,6 +41,12 @@ class LocalAIOnBoardingBloclate final IUserBackendService _userService;late final SubscriptionSuccessListenable _successListenable;+ @override+ Future<void> close() async {+ _successListenable.removeListener(_onPaymentSuccessful);+ await super.close();+ }+void _dispatch() {on<LocalAIOnBoardingEvent>((event, emit) {event.when(diff --git a/frontend/appflowy_flutter/lib/workspace/application/sidebar/billing/sidebar_plan_bloc.dart b/frontend/appflowy_flutter/lib/workspace/application/sidebar/billing/sidebar_plan_bloc.dartindex feb4afe7e8..64aa425117 100644--- a/frontend/appflowy_flutter/lib/workspace/application/sidebar/billing/sidebar_plan_bloc.dart+++ b/frontend/appflowy_flutter/lib/workspace/application/sidebar/billing/sidebar_plan_bloc.dart@@ -17,37 +17,8 @@ part 'sidebar_plan_bloc.freezed.dart';class SidebarPlanBloc extends Bloc<SidebarPlanEvent, SidebarPlanState> {SidebarPlanBloc() : super(const SidebarPlanState()) {// 1. Listen to user subscription payment callback. After user client 'Open AppFlowy', this listenable will be triggered.- final subscriptionListener = getIt<SubscriptionSuccessListenable>();- subscriptionListener.addListener(() {- final plan = subscriptionListener.subscribedPlan;- Log.info("Subscription success listenable triggered: $plan");-- if (!isClosed) {- // Notify the user that they have switched to a new plan. It would be better if we use websocket to- // notify the client when plan switching.- if (state.workspaceId != null) {- final payload = SuccessWorkspaceSubscriptionPB(- workspaceId: state.workspaceId,- );-- if (plan != null) {- payload.plan = plan;- }-- UserEventNotifyDidSwitchPlan(payload).send().then((result) {- result.fold(- // After the user has switched to a new plan, we need to refresh the workspace usage.- (_) => _checkWorkspaceUsage(),- (error) => Log.error("NotifyDidSwitchPlan failed: $error"),- );- });- } else {- Log.error(- "Unexpected empty workspace id when subscription success listenable triggered. It should not happen. If happens, it must be a bug",- );- }- }- });+ _subscriptionListener = getIt<SubscriptionSuccessListenable>();+ _subscriptionListener.addListener(_onPaymentSuccessful);// 2. Listen to the storage notification_storageListener = StoreageNotificationListener(@@ -77,16 +48,49 @@ class SidebarPlanBloc extends Bloc<SidebarPlanEvent, SidebarPlanState> {on<SidebarPlanEvent>(_handleEvent);}+ void _onPaymentSuccessful() {+ final plan = _subscriptionListener.subscribedPlan;+ Log.info("Subscription success listenable triggered: $plan");++ if (!isClosed) {+ // Notify the user that they have switched to a new plan. It would be better if we use websocket to+ // notify the client when plan switching.+ if (state.workspaceId != null) {+ final payload = SuccessWorkspaceSubscriptionPB(+ workspaceId: state.workspaceId,+ );++ if (plan != null) {+ payload.plan = plan;+ }++ UserEventNotifyDidSwitchPlan(payload).send().then((result) {+ result.fold(+ // After the user has switched to a new plan, we need to refresh the workspace usage.+ (_) => _checkWorkspaceUsage(),+ (error) => Log.error("NotifyDidSwitchPlan failed: $error"),+ );+ });+ } else {+ Log.error(+ "Unexpected empty workspace id when subscription success listenable triggered. It should not happen. If happens, it must be a bug",+ );+ }+ }+ }+Future<void> dispose() async {if (_globalErrorListener != null) {GlobalErrorCodeNotifier.remove(_globalErrorListener!);}+ _subscriptionListener.removeListener(_onPaymentSuccessful);await _storageListener?.stop();_storageListener = null;}ErrorListener? _globalErrorListener;StoreageNotificationListener? _storageListener;+ late final SubscriptionSuccessListenable _subscriptionListener;Future<void> _handleEvent(SidebarPlanEvent event,diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/space_icon_popup.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/space_icon_popup.dartindex de2c601e2c..95cb8111f5 100644--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/space_icon_popup.dart+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/space_icon_popup.dart@@ -224,18 +224,24 @@ class _SpaceIconPickerState extends State<SpaceIconPicker> {widget.onIconChanged(selectedIcon.value, selectedColor.value);}- selectedColor.addListener(() {- widget.onIconChanged(selectedIcon.value, selectedColor.value);- });+ selectedColor.addListener(_onColorChanged);+ selectedIcon.addListener(_onIconChanged);+ }- selectedIcon.addListener(() {- widget.onIconChanged(selectedIcon.value, selectedColor.value);- });+ void _onColorChanged() {+ widget.onIconChanged(selectedIcon.value, selectedColor.value);+ }++ void _onIconChanged() {+ widget.onIconChanged(selectedIcon.value, selectedColor.value);}@overridevoid dispose() {+ selectedColor.removeListener(_onColorChanged);selectedColor.dispose();++ selectedIcon.removeListener(_onIconChanged);selectedIcon.dispose();super.dispose();}@@ -253,9 +259,7 @@ class _SpaceIconPickerState extends State<SpaceIconPicker> {const VSpace(10.0),_Colors(selectedColor: selectedColor.value,- onColorSelected: (color) {- selectedColor.value = color;- },+ onColorSelected: (color) => selectedColor.value = color,),const VSpace(12.0),FlowyText.regular(@@ -268,9 +272,7 @@ class _SpaceIconPickerState extends State<SpaceIconPicker> {builder: (_, value, ___) => _Icons(selectedColor: value,selectedIcon: selectedIcon.value,- onIconSelected: (icon) {- selectedIcon.value = icon;- },+ onIconSelected: (icon) => selectedIcon.value = icon,),),],@@ -303,9 +305,7 @@ class _ColorsState extends State<_Colors> {children: builtInSpaceColors.map((color) {return GestureDetector(onTap: () {- setState(() {- selectedColor = color;- });+ setState(() => selectedColor = color);widget.onColorSelected(color);},@@ -365,9 +365,7 @@ class _IconsState extends State<_Icons> {children: builtInSpaceIcons.map((icon) {return GestureDetector(onTap: () {- setState(() {- selectedIcon = icon;- });+ setState(() => selectedIcon = icon);widget.onIconSelected(icon);},diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/sites/domain/domain_settings_dialog.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/sites/domain/domain_settings_dialog.dartindex d3b987ab4a..6555494144 100644--- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/sites/domain/domain_settings_dialog.dart+++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/sites/domain/domain_settings_dialog.dart@@ -36,17 +36,17 @@ class _DomainSettingsDialogState extends State<DomainSettingsDialog> {super.initState();controller.text = widget.namespace;- controller.addListener(() {- controllerText.value = controller.text;- });+ controller.addListener(_onTextChanged);}+ void _onTextChanged() => controllerText.value = controller.text;+@overridevoid dispose() {focusNode.dispose();+ controller.removeListener(_onTextChanged);controller.dispose();controllerText.dispose();-super.dispose();}@@ -200,9 +200,9 @@ class _DomainSettingsDialogState extends State<DomainSettingsDialog> {void _onSave() {// listen on the result- context.read<SettingsSitesBloc>().add(- SettingsSitesEvent.updateNamespace(controller.text),- );+ context+ .read<SettingsSitesBloc>()+ .add(SettingsSitesEvent.updateNamespace(controller.text));}void _onListener(BuildContext context, SettingsSitesState state) {diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/emoji_picker/src/default_emoji_picker_view.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/emoji_picker/src/default_emoji_picker_view.dartindex 53ef37cea9..9a4690f240 100644--- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/emoji_picker/src/default_emoji_picker_view.dart+++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/emoji_picker/src/default_emoji_picker_view.dart@@ -46,27 +46,12 @@ class DefaultEmojiPickerViewState extends State<DefaultEmojiPickerView>);_pageController = PageController(initialPage: initCategory);_emojiFocusNode.requestFocus();- _emojiController.addListener(() {- final String query = _emojiController.text.toLowerCase();- if (query.isEmpty) {- searchEmojiList.emoji.clear();- _pageController!.jumpToPage(_tabController!.index);- } else {- searchEmojiList.emoji.clear();- for (final element in widget.state.emojiCategoryGroupList) {- searchEmojiList.emoji.addAll(- element.emoji- .where((item) => item.name.toLowerCase().contains(query))- .toList(),- );- }- }- setState(() {});- });+ _emojiController.addListener(_onEmojiChanged);}@overridevoid dispose() {+ _emojiController.removeListener(_onEmojiChanged);_emojiController.dispose();_emojiFocusNode.dispose();_pageController?.dispose();@@ -75,6 +60,24 @@ class DefaultEmojiPickerViewState extends State<DefaultEmojiPickerView>super.dispose();}+ void _onEmojiChanged() {+ final String query = _emojiController.text.toLowerCase();+ if (query.isEmpty) {+ searchEmojiList.emoji.clear();+ _pageController!.jumpToPage(_tabController!.index);+ } else {+ searchEmojiList.emoji.clear();+ for (final element in widget.state.emojiCategoryGroupList) {+ searchEmojiList.emoji.addAll(+ element.emoji+ .where((item) => item.name.toLowerCase().contains(query))+ .toList(),+ );+ }+ }+ setState(() {});+ }+Widget _buildBackspaceButton() {if (widget.state.onBackspacePressed != null) {return Material(diff --git a/frontend/appflowy_flutter/packages/flowy_infra_ui/lib/style_widget/text_input.dart b/frontend/appflowy_flutter/packages/flowy_infra_ui/lib/style_widget/text_input.dartindex 7e9b7b12ad..d5e6282f2e 100644--- a/frontend/appflowy_flutter/packages/flowy_infra_ui/lib/style_widget/text_input.dart+++ b/frontend/appflowy_flutter/packages/flowy_infra_ui/lib/style_widget/text_input.dart@@ -178,19 +178,21 @@ class StyledSearchTextInputState extends State<StyledSearchTextInput> {},);// Listen for focus out events- _focusNode- .addListener(() => widget.onFocusChanged?.call(_focusNode.hasFocus));+ _focusNode.addListener(_onFocusChanged);widget.onFocusCreated?.call(_focusNode);if (widget.autoFocus ?? false) {scheduleMicrotask(() => _focusNode.requestFocus());}}+ void _onFocusChanged() => widget.onFocusChanged?.call(_focusNode.hasFocus);+@overridevoid dispose() {if (widget.controller == null) {_controller.dispose();}+ _focusNode.removeListener(_onFocusChanged);_focusNode.dispose();super.dispose();}diff --git a/frontend/appflowy_flutter/packages/flowy_infra_ui/lib/widget/buttons/base_styled_button.dart b/frontend/appflowy_flutter/packages/flowy_infra_ui/lib/widget/buttons/base_styled_button.dartindex ee51d400c9..8087c712fe 100644--- a/frontend/appflowy_flutter/packages/flowy_infra_ui/lib/widget/buttons/base_styled_button.dart+++ b/frontend/appflowy_flutter/packages/flowy_infra_ui/lib/widget/buttons/base_styled_button.dart@@ -53,16 +53,19 @@ class BaseStyledBtnState extends State<BaseStyledButton> {void initState() {super.initState();_focusNode = FocusNode(debugLabel: '', canRequestFocus: true);- _focusNode.addListener(() {- if (_focusNode.hasFocus != _isFocused) {- setState(() => _isFocused = _focusNode.hasFocus);- widget.onFocusChanged?.call(_isFocused);- }- });+ _focusNode.addListener(_onFocusChanged);+ }++ void _onFocusChanged() {+ if (_focusNode.hasFocus != _isFocused) {+ setState(() => _isFocused = _focusNode.hasFocus);+ widget.onFocusChanged?.call(_isFocused);+ }}@overridevoid dispose() {+ _focusNode.removeListener(_onFocusChanged);_focusNode.dispose();super.dispose();}