Skip to content

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.

fix: dispose of resources in time (#4625)

Mathias Mogensen92ceb2cd7d68
diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/bottom_sheet_edit_link_widget.dart b/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/bottom_sheet_edit_link_widget.dart
index 871811c2bf..bed69e1cc4 100644
--- a/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/bottom_sheet_edit_link_widget.dart
+++ b/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/bottom_sheet_edit_link_widget.dart
@@ -44,7 +44,6 @@ class _MobileBottomSheetEditLinkWidgetState
void dispose() {
textController.dispose();
hrefController.dispose();
-
super.dispose();
}
diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/bottom_sheet_rename_widget.dart b/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/bottom_sheet_rename_widget.dart
index 1d40bd6e5d..618e19e53d 100644
--- a/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/bottom_sheet_rename_widget.dart
+++ b/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/bottom_sheet_rename_widget.dart
@@ -27,14 +27,12 @@ class _MobileBottomSheetRenameWidgetState
@override
void initState() {
super.initState();
-
controller = TextEditingController(text: widget.name);
}
@override
void dispose() {
controller.dispose();
-
super.dispose();
}
diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/database/board/mobile_board_content.dart b/frontend/appflowy_flutter/lib/mobile/presentation/database/board/mobile_board_content.dart
index f050945665..c01f3ca048 100644
--- a/frontend/appflowy_flutter/lib/mobile/presentation/database/board/mobile_board_content.dart
+++ b/frontend/appflowy_flutter/lib/mobile/presentation/database/board/mobile_board_content.dart
@@ -38,6 +38,12 @@ class _MobileBoardContentState extends State<MobileBoardContent> {
scrollController = ScrollController();
}
+ @override
+ void dispose() {
+ scrollController.dispose();
+ super.dispose();
+ }
+
@override
Widget build(BuildContext context) {
final screenWidth = MediaQuery.of(context).size.width;
diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/database/board/widgets/mobile_board_trailing.dart b/frontend/appflowy_flutter/lib/mobile/presentation/database/board/widgets/mobile_board_trailing.dart
index 1c6f8090fd..2cc59d73d3 100644
--- a/frontend/appflowy_flutter/lib/mobile/presentation/database/board/widgets/mobile_board_trailing.dart
+++ b/frontend/appflowy_flutter/lib/mobile/presentation/database/board/widgets/mobile_board_trailing.dart
@@ -19,6 +19,12 @@ class _MobileBoardTrailingState extends State<MobileBoardTrailing> {
bool isEditing = false;
+ @override
+ void dispose() {
+ _textController.dispose();
+ super.dispose();
+ }
+
@override
Widget build(BuildContext context) {
final screenSize = MediaQuery.of(context).size;
diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/database/field/mobile_full_field_editor.dart b/frontend/appflowy_flutter/lib/mobile/presentation/database/field/mobile_full_field_editor.dart
index ae4af39007..bea19ff0a4 100644
--- a/frontend/appflowy_flutter/lib/mobile/presentation/database/field/mobile_full_field_editor.dart
+++ b/frontend/appflowy_flutter/lib/mobile/presentation/database/field/mobile_full_field_editor.dart
@@ -196,7 +196,6 @@ class _MobileFieldEditorState extends State<MobileFieldEditor> {
@override
void initState() {
super.initState();
-
values = widget.defaultValues;
controller.text = values.name;
}
@@ -204,7 +203,6 @@ class _MobileFieldEditorState extends State<MobileFieldEditor> {
@override
void dispose() {
controller.dispose();
-
super.dispose();
}
diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/database/view/edit_database_view_screen.dart b/frontend/appflowy_flutter/lib/mobile/presentation/database/view/edit_database_view_screen.dart
index 9603f28803..a612d74e33 100644
--- a/frontend/appflowy_flutter/lib/mobile/presentation/database/view/edit_database_view_screen.dart
+++ b/frontend/appflowy_flutter/lib/mobile/presentation/database/view/edit_database_view_screen.dart
@@ -83,6 +83,12 @@ class _NameAndIconState extends State<_NameAndIcon> {
textEditingController.text = widget.view.name;
}
+ @override
+ void dispose() {
+ textEditingController.dispose();
+ super.dispose();
+ }
+
@override
Widget build(BuildContext context) {
return FlowyOptionTile.textField(
diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/setting/personal_info/edit_username_bottom_sheet.dart b/frontend/appflowy_flutter/lib/mobile/presentation/setting/personal_info/edit_username_bottom_sheet.dart
index d88747ea24..04fe9e9cf7 100644
--- a/frontend/appflowy_flutter/lib/mobile/presentation/setting/personal_info/edit_username_bottom_sheet.dart
+++ b/frontend/appflowy_flutter/lib/mobile/presentation/setting/personal_info/edit_username_bottom_sheet.dart
@@ -23,6 +23,7 @@ class _EditUsernameBottomSheetState extends State<EditUsernameBottomSheet> {
late TextEditingController _textFieldController;
final _formKey = GlobalKey<FormState>();
+
@override
void initState() {
super.initState();
diff --git a/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/checkbox_cell_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/checkbox_cell_bloc.dart
index 0d3b1d37ee..eca21c8ba3 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/checkbox_cell_bloc.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/checkbox_cell_bloc.dart
@@ -16,6 +16,16 @@ class CheckboxCellBloc extends Bloc<CheckboxCellEvent, CheckboxCellState> {
final CheckboxCellController cellController;
void Function()? _onCellChangedFn;
+ @override
+ Future<void> close() async {
+ if (_onCellChangedFn != null) {
+ cellController.removeListener(_onCellChangedFn!);
+ _onCellChangedFn = null;
+ }
+ await cellController.dispose();
+ return super.close();
+ }
+
void _dispatch() {
on<CheckboxCellEvent>(
(event, emit) {
@@ -35,17 +45,6 @@ class CheckboxCellBloc extends Bloc<CheckboxCellEvent, CheckboxCellState> {
);
}
- @override
- Future<void> close() async {
- if (_onCellChangedFn != null) {
- cellController.removeListener(_onCellChangedFn!);
- _onCellChangedFn = null;
- }
-
- await cellController.dispose();
- return super.close();
- }
-
void _startListening() {
_onCellChangedFn = cellController.addListener(
onCellChanged: (cellData) {
diff --git a/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/checklist_cell_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/checklist_cell_bloc.dart
index 50bace5827..f315e8f768 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/checklist_cell_bloc.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/checklist_cell_bloc.dart
@@ -32,6 +32,16 @@ class ChecklistCellBloc extends Bloc<ChecklistCellEvent, ChecklistCellState> {
final ChecklistCellBackendService _checklistCellService;
void Function()? _onCellChangedFn;
+ @override
+ Future<void> close() async {
+ if (_onCellChangedFn != null) {
+ cellController.removeListener(_onCellChangedFn!);
+ _onCellChangedFn = null;
+ }
+ await cellController.dispose();
+ return super.close();
+ }
+
void _dispatch() {
on<ChecklistCellEvent>(
(event, emit) async {
@@ -79,16 +89,6 @@ class ChecklistCellBloc extends Bloc<ChecklistCellEvent, ChecklistCellState> {
);
}
- @override
- Future<void> close() async {
- if (_onCellChangedFn != null) {
- cellController.removeListener(_onCellChangedFn!);
- _onCellChangedFn = null;
- }
- await cellController.dispose();
- return super.close();
- }
-
void _startListening() {
_onCellChangedFn = cellController.addListener(
onCellChanged: (data) {
diff --git a/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/date_cell_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/date_cell_bloc.dart
index 409ae12576..9497f28ff5 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/date_cell_bloc.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/date_cell_bloc.dart
@@ -17,6 +17,16 @@ class DateCellBloc extends Bloc<DateCellEvent, DateCellState> {
final DateCellController cellController;
void Function()? _onCellChangedFn;
+ @override
+ Future<void> close() async {
+ if (_onCellChangedFn != null) {
+ cellController.removeListener(_onCellChangedFn!);
+ _onCellChangedFn = null;
+ }
+ await cellController.dispose();
+ return super.close();
+ }
+
void _dispatch() {
on<DateCellEvent>(
(event, emit) async {
@@ -35,15 +45,6 @@ class DateCellBloc extends Bloc<DateCellEvent, DateCellState> {
);
}
- @override
- Future<void> close() async {
- if (_onCellChangedFn != null) {
- cellController.removeListener(_onCellChangedFn!);
- _onCellChangedFn = null;
- }
- return super.close();
- }
-
void _startListening() {
_onCellChangedFn = cellController.addListener(
onCellChanged: (data) {
diff --git a/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/number_cell_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/number_cell_bloc.dart
index 8b6b95d108..8593c42f1e 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/number_cell_bloc.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/number_cell_bloc.dart
@@ -15,6 +15,16 @@ class NumberCellBloc extends Bloc<NumberCellEvent, NumberCellState> {
final NumberCellController cellController;
void Function()? _onCellChangedFn;
+ @override
+ Future<void> close() async {
+ if (_onCellChangedFn != null) {
+ cellController.removeListener(_onCellChangedFn!);
+ _onCellChangedFn = null;
+ }
+ await cellController.dispose();
+ return super.close();
+ }
+
void _dispatch() {
on<NumberCellEvent>(
(event, emit) async {
@@ -45,16 +55,6 @@ class NumberCellBloc extends Bloc<NumberCellEvent, NumberCellState> {
);
}
- @override
- Future<void> close() async {
- if (_onCellChangedFn != null) {
- cellController.removeListener(_onCellChangedFn!);
- _onCellChangedFn = null;
- }
- await cellController.dispose();
- return super.close();
- }
-
void _startListening() {
_onCellChangedFn = cellController.addListener(
onCellChanged: (cellContent) {
diff --git a/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/select_option_cell_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/select_option_cell_bloc.dart
index 392db0492c..eb1ff69790 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/select_option_cell_bloc.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/select_option_cell_bloc.dart
@@ -17,6 +17,16 @@ class SelectOptionCellBloc
final SelectOptionCellController cellController;
void Function()? _onCellChangedFn;
+ @override
+ Future<void> close() async {
+ if (_onCellChangedFn != null) {
+ cellController.removeListener(_onCellChangedFn!);
+ _onCellChangedFn = null;
+ }
+ await cellController.dispose();
+ return super.close();
+ }
+
void _dispatch() {
on<SelectOptionCellEvent>(
(event, emit) async {
@@ -36,16 +46,6 @@ class SelectOptionCellBloc
);
}
- @override
- Future<void> close() async {
- if (_onCellChangedFn != null) {
- cellController.removeListener(_onCellChangedFn!);
- _onCellChangedFn = null;
- }
- await cellController.dispose();
- return super.close();
- }
-
void _startListening() {
_onCellChangedFn = cellController.addListener(
onCellChanged: (selectOptionCellData) {
diff --git a/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/text_cell_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/text_cell_bloc.dart
index 3c57f04749..3a2371cf4b 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/text_cell_bloc.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/text_cell_bloc.dart
@@ -15,6 +15,16 @@ class TextCellBloc extends Bloc<TextCellEvent, TextCellState> {
final TextCellController cellController;
void Function()? _onCellChangedFn;
+ @override
+ Future<void> close() async {
+ if (_onCellChangedFn != null) {
+ cellController.removeListener(_onCellChangedFn!);
+ _onCellChangedFn = null;
+ }
+ await cellController.dispose();
+ return super.close();
+ }
+
void _dispatch() {
on<TextCellEvent>(
(event, emit) {
@@ -41,16 +51,6 @@ class TextCellBloc extends Bloc<TextCellEvent, TextCellState> {
);
}
- @override
- Future<void> close() async {
- if (_onCellChangedFn != null) {
- cellController.removeListener(_onCellChangedFn!);
- _onCellChangedFn = null;
- }
- await cellController.dispose();
- return super.close();
- }
-
void _startListening() {
_onCellChangedFn = cellController.addListener(
onCellChanged: (cellContent) {
diff --git a/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/timestamp_cell_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/timestamp_cell_bloc.dart
index c757b44efa..240ce7182c 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/timestamp_cell_bloc.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/timestamp_cell_bloc.dart
@@ -17,6 +17,16 @@ class TimestampCellBloc extends Bloc<TimestampCellEvent, TimestampCellState> {
final TimestampCellController cellController;
void Function()? _onCellChangedFn;
+ @override
+ Future<void> close() async {
+ if (_onCellChangedFn != null) {
+ cellController.removeListener(_onCellChangedFn!);
+ _onCellChangedFn = null;
+ }
+ await cellController.dispose();
+ return super.close();
+ }
+
void _dispatch() {
on<TimestampCellEvent>(
(event, emit) async {
@@ -35,16 +45,6 @@ class TimestampCellBloc extends Bloc<TimestampCellEvent, TimestampCellState> {
);
}
- @override
- Future<void> close() async {
- if (_onCellChangedFn != null) {
- cellController.removeListener(_onCellChangedFn!);
- _onCellChangedFn = null;
- }
- await cellController.dispose();
- return super.close();
- }
-
void _startListening() {
_onCellChangedFn = cellController.addListener(
onCellChanged: (data) {
diff --git a/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/url_cell_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/url_cell_bloc.dart
index 6ab0086e26..dbd2258cc1 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/url_cell_bloc.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/url_cell_bloc.dart
@@ -16,6 +16,16 @@ class URLCellBloc extends Bloc<URLCellEvent, URLCellState> {
final URLCellController cellController;
void Function()? _onCellChangedFn;
+ @override
+ Future<void> close() async {
+ if (_onCellChangedFn != null) {
+ cellController.removeListener(_onCellChangedFn!);
+ _onCellChangedFn = null;
+ }
+ await cellController.dispose();
+ return super.close();
+ }
+
void _dispatch() {
on<URLCellEvent>(
(event, emit) async {
@@ -39,16 +49,6 @@ class URLCellBloc extends Bloc<URLCellEvent, URLCellState> {
);
}
- @override
- Future<void> close() async {
- if (_onCellChangedFn != null) {
- cellController.removeListener(_onCellChangedFn!);
- _onCellChangedFn = null;
- }
- await cellController.dispose();
- return super.close();
- }
-
void _startListening() {
_onCellChangedFn = cellController.addListener(
onCellChanged: (cellData) {
diff --git a/frontend/appflowy_flutter/lib/plugins/database/application/layout/layout_listener.dart b/frontend/appflowy_flutter/lib/plugins/database/application/layout/layout_listener.dart
deleted file mode 100644
index 1f3301f5b8..0000000000
--- a/frontend/appflowy_flutter/lib/plugins/database/application/layout/layout_listener.dart
+++ /dev/null
@@ -1,52 +0,0 @@
-import 'dart:typed_data';
-
-import 'package:appflowy/core/notification/grid_notification.dart';
-import 'package:flowy_infra/notifier.dart';
-import 'package:appflowy_backend/protobuf/flowy-error/protobuf.dart';
-import 'package:appflowy_backend/protobuf/flowy-database2/protobuf.dart';
-import 'package:dartz/dartz.dart';
-
-/// Listener for database layout changes.
-class DatabaseLayoutListener {
- DatabaseLayoutListener(this.viewId);
-
- final String viewId;
-
- PublishNotifier<Either<DatabaseLayoutPB, FlowyError>>? _layoutNotifier =
- PublishNotifier();
- DatabaseNotificationListener? _listener;
-
- void start({
- required void Function(Either<DatabaseLayoutPB, FlowyError>)
- onLayoutChanged,
- }) {
- _layoutNotifier?.addPublishListener(onLayoutChanged);
- _listener = DatabaseNotificationListener(
- objectId: viewId,
- handler: _handler,
- );
- }
-
- void _handler(
- DatabaseNotification ty,
- Either<Uint8List, FlowyError> result,
- ) {
- switch (ty) {
- case DatabaseNotification.DidUpdateDatabaseLayout:
- result.fold(
- (payload) => _layoutNotifier?.value =
- left(DatabaseLayoutMetaPB.fromBuffer(payload).layout),
- (error) => _layoutNotifier?.value = right(error),
- );
- break;
- default:
- break;
- }
- }
-
- Future<void> stop() async {
- await _listener?.stop();
- _layoutNotifier?.dispose();
- _layoutNotifier = null;
- }
-}
diff --git a/frontend/appflowy_flutter/lib/plugins/database/application/setting/setting_controller.dart b/frontend/appflowy_flutter/lib/plugins/database/application/setting/setting_controller.dart
deleted file mode 100644
index 2147b4d1de..0000000000
--- a/frontend/appflowy_flutter/lib/plugins/database/application/setting/setting_controller.dart
+++ /dev/null
@@ -1,62 +0,0 @@
-import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
-import 'package:appflowy_backend/protobuf/flowy-database2/setting_entities.pb.dart';
-import 'setting_listener.dart';
-import 'setting_service.dart';
-
-typedef OnError = void Function(FlowyError);
-typedef OnSettingUpdated = void Function(DatabaseViewSettingPB);
-
-class SettingController {
- SettingController({
- required this.viewId,
- }) : _settingBackendSvc = SettingBackendService(viewId: viewId),
- _listener = DatabaseSettingListener(viewId: viewId) {
- // Load setting
- _settingBackendSvc.getSetting().then((result) {
- result.fold(
- (newSetting) => updateSetting(newSetting),
- (err) => _onError?.call(err),
- );
- });
-
- // Listen on the setting changes
- _listener.start(
- onSettingUpdated: (result) {
- result.fold(
- (newSetting) => updateSetting(newSetting),
- (err) => _onError?.call(err),
- );
- },
- );
- }
-
- final String viewId;
- final SettingBackendService _settingBackendSvc;
- final DatabaseSettingListener _listener;
-
- OnSettingUpdated? _onSettingUpdated;
- OnError? _onError;
- DatabaseViewSettingPB? _setting;
- DatabaseViewSettingPB? get setting => _setting;
-
- void startListening({
- required OnSettingUpdated onSettingUpdated,
- required OnError onError,
- }) {
- assert(_onSettingUpdated == null, 'Should call once');
- assert(_onError == null, 'Should call once');
- _onSettingUpdated = onSettingUpdated;
- _onError = onError;
- }
-
- void updateSetting(DatabaseViewSettingPB newSetting) {
- _setting = newSetting;
- _onSettingUpdated?.call(newSetting);
- }
-
- void dispose() {
- _onSettingUpdated = null;
- _onError = null;
- _listener.stop();
- }
-}
diff --git a/frontend/appflowy_flutter/lib/plugins/database/application/tab_bar_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/application/tab_bar_bloc.dart
index 8f7a8b948f..6d5f0b4984 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/application/tab_bar_bloc.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/application/tab_bar_bloc.dart
@@ -131,6 +131,7 @@ class DatabaseTabBarBloc
Future<void> close() async {
for (final tabBar in state.tabBars) {
await state.tabBarControllerByViewId[tabBar.viewId]?.dispose();
+ tabBar.dispose();
}
return super.close();
}
@@ -261,6 +262,10 @@ class DatabaseTabBar extends Equatable {
@override
List<Object?> get props => [view.hashCode];
+
+ void dispose() {
+ _builder.dispose();
+ }
}
typedef OnViewUpdated = void Function(ViewPB newView);
diff --git a/frontend/appflowy_flutter/lib/plugins/database/board/presentation/board_page.dart b/frontend/appflowy_flutter/lib/plugins/database/board/presentation/board_page.dart
index 4503fa2b20..16b2d45f95 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/board/presentation/board_page.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/board/presentation/board_page.dart
@@ -33,7 +33,7 @@ import '../application/board_bloc.dart';
import 'toolbar/board_setting_bar.dart';
import 'widgets/board_hidden_groups.dart';
-class BoardPageTabBarBuilderImpl implements DatabaseTabBarItemBuilder {
+class BoardPageTabBarBuilderImpl extends DatabaseTabBarItemBuilder {
@override
Widget content(
BuildContext context,
diff --git a/frontend/appflowy_flutter/lib/plugins/database/calendar/application/calendar_setting_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/calendar/application/calendar_setting_bloc.dart
index ee4f34586b..5835756887 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/calendar/application/calendar_setting_bloc.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/calendar/application/calendar_setting_bloc.dart
@@ -26,6 +26,12 @@ class CalendarSettingBloc
final DatabaseController _databaseController;
final DatabaseLayoutSettingListener _listener;
+ @override
+ Future<void> close() async {
+ await _listener.stop();
+ return super.close();
+ }
+
void _dispatch() {
on<CalendarSettingEvent>((event, emit) {
event.when(
@@ -108,12 +114,6 @@ class CalendarSettingBloc
},
);
}
-
- @override
- Future<void> close() async {
- await _listener.stop();
- return super.close();
- }
}
@freezed
diff --git a/frontend/appflowy_flutter/lib/plugins/database/calendar/presentation/calendar_page.dart b/frontend/appflowy_flutter/lib/plugins/database/calendar/presentation/calendar_page.dart
index 756c385067..9382ad3de5 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/calendar/presentation/calendar_page.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/calendar/presentation/calendar_page.dart
@@ -30,7 +30,7 @@ import 'calendar_day.dart';
import 'layout/sizes.dart';
import 'toolbar/calendar_setting_bar.dart';
-class CalendarPageTabBarBuilderImpl implements DatabaseTabBarItemBuilder {
+class CalendarPageTabBarBuilderImpl extends DatabaseTabBarItemBuilder {
@override
Widget content(
BuildContext context,
diff --git a/frontend/appflowy_flutter/lib/plugins/database/grid/application/calculations/calculations_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/grid/application/calculations/calculations_bloc.dart
index 0eb60dd3eb..28d8b820e8 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/grid/application/calculations/calculations_bloc.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/grid/application/calculations/calculations_bloc.dart
@@ -29,6 +29,7 @@ class CalculationsBloc extends Bloc<CalculationsEvent, CalculationsState> {
@override
Future<void> close() async {
_fieldController.removeListener(onFieldsListener: _onReceiveFields);
+ await _calculationsListener.stop();
await super.close();
}
diff --git a/frontend/appflowy_flutter/lib/plugins/database/grid/application/filter/filter_menu_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/grid/application/filter/filter_menu_bloc.dart
index 6c98287ad7..08e45305de 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/grid/application/filter/filter_menu_bloc.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/grid/application/filter/filter_menu_bloc.dart
@@ -73,7 +73,7 @@ class GridFilterMenuBloc
}
@override
- Future<void> close() {
+ Future<void> close() async {
if (_onFilterFn != null) {
fieldController.removeListener(onFiltersListener: _onFilterFn!);
_onFilterFn = null;
diff --git a/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/grid_page.dart b/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/grid_page.dart
index 6437be29a2..bca5f06dfb 100755
--- a/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/grid_page.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/grid_page.dart
@@ -45,7 +45,7 @@ class ToggleExtensionNotifier extends ChangeNotifier {
}
}
-class DesktopGridTabBarBuilderImpl implements DatabaseTabBarItemBuilder {
+class DesktopGridTabBarBuilderImpl extends DatabaseTabBarItemBuilder {
final _toggleExtension = ToggleExtensionNotifier();
@override
@@ -86,6 +86,12 @@ class DesktopGridTabBarBuilderImpl implements DatabaseTabBarItemBuilder {
);
}
+ @override
+ void dispose() {
+ _toggleExtension.dispose();
+ super.dispose();
+ }
+
ValueKey _makeValueKey(DatabaseController controller) {
return ValueKey(controller.viewId);
}
diff --git a/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/mobile_grid_page.dart b/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/mobile_grid_page.dart
index dcfa0f724d..23b51c437f 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/mobile_grid_page.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/mobile_grid_page.dart
@@ -29,7 +29,7 @@ import 'widgets/header/mobile_grid_header.dart';
import 'widgets/mobile_fab.dart';
import 'widgets/row/mobile_row.dart';
-class MobileGridTabBarBuilderImpl implements DatabaseTabBarItemBuilder {
+class MobileGridTabBarBuilderImpl extends DatabaseTabBarItemBuilder {
@override
Widget content(
BuildContext context,
diff --git a/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/widgets/filter/filter_menu.dart b/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/widgets/filter/filter_menu.dart
index a59e84dd47..caca16a1ac 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/widgets/filter/filter_menu.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/widgets/filter/filter_menu.dart
@@ -35,7 +35,12 @@ class FilterMenu extends StatelessWidget {
final List<Widget> children = [];
children.addAll(
state.filters
- .map((filterInfo) => FilterMenuItem(filterInfo: filterInfo))
+ .map(
+ (filterInfo) => FilterMenuItem(
+ key: ValueKey(filterInfo.filter.id),
+ filterInfo: filterInfo,
+ ),
+ )
.toList(),
);
diff --git a/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/widgets/row/row.dart b/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/widgets/row/row.dart
index 44a30a3384..3869925b7e 100755
--- a/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/widgets/row/row.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/widgets/row/row.dart
@@ -326,6 +326,12 @@ class _RowEnterRegionState extends State<_RowEnterRegion> {
_rowStateNotifier = RegionStateNotifier();
}
+ @override
+ Future<void> dispose() async {
+ _rowStateNotifier.dispose();
+ super.dispose();
+ }
+
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider.value(
@@ -338,10 +344,4 @@ class _RowEnterRegionState extends State<_RowEnterRegion> {
),
);
}
-
- @override
- Future<void> dispose() async {
- _rowStateNotifier.dispose();
- super.dispose();
- }
}
diff --git a/frontend/appflowy_flutter/lib/plugins/database/tab_bar/tab_bar_view.dart b/frontend/appflowy_flutter/lib/plugins/database/tab_bar/tab_bar_view.dart
index 0da24d9e3d..a047f64de3 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/tab_bar/tab_bar_view.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/tab_bar/tab_bar_view.dart
@@ -41,6 +41,12 @@ abstract class DatabaseTabBarItemBuilder {
BuildContext context,
DatabaseController controller,
);
+
+ /// Should be called in case a builder has resources it
+ /// needs to dispose of.
+ ///
+ // If we add any logic in this method, add @mustCallSuper !
+ void dispose() {}
}
class DatabaseTabBarView extends StatefulWidget {
diff --git a/frontend/appflowy_flutter/lib/plugins/database/widgets/card/card_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/widgets/card/card_bloc.dart
index 51c4ec746d..ba2e8f0e00 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/widgets/card/card_bloc.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/widgets/card/card_bloc.dart
@@ -47,6 +47,16 @@ class CardBloc extends Bloc<CardEvent, CardState> {
VoidCallback? _rowCallback;
+ @override
+ Future<void> close() async {
+ if (_rowCallback != null) {
+ _rowCache.removeRowListener(_rowCallback!);
+ _rowCallback = null;
+ }
+ await _rowListener.stop();
+ return super.close();
+ }
+
void _dispatch() {
on<CardEvent>(
(event, emit) async {
@@ -73,16 +83,6 @@ class CardBloc extends Bloc<CardEvent, CardState> {
);
}
- @override
- Future<void> close() async {
- if (_rowCallback != null) {
- _rowCache.removeRowListener(_rowCallback!);
- _rowCallback = null;
- }
- await _rowListener.stop();
- return super.close();
- }
-
Future<void> _startListening() async {
_rowCallback = _rowCache.addListener(
rowId: rowId,
@@ -113,7 +113,7 @@ List<CellContext> _makeCells(
cellContexts.removeWhere((cellContext) {
final fieldInfo = fieldController.getField(cellContext.fieldId);
return fieldInfo == null ||
- !fieldInfo.fieldSettings!.visibility.isVisibleState() ||
+ !(fieldInfo.fieldSettings?.visibility.isVisibleState() ?? false) ||
(groupFieldId != null && cellContext.fieldId == groupFieldId);
});
return cellContexts.toList();
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.dart
index e49347eeaf..8348232f4a 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
@@ -1,9 +1,13 @@
+import 'package:flutter/material.dart';
+import 'package:flutter/widgets.dart';
+
import 'package:appflowy/plugins/database/application/cell/cell_controller.dart';
-import 'package:appflowy/plugins/database/application/cell/cell_controller_builder.dart';
import 'package:appflowy/plugins/database/application/database_controller.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/protobuf.dart';
-import 'package:flutter/material.dart';
-import 'package:flutter/widgets.dart';
+
+import '../row/accessory/cell_accessory.dart';
+import '../row/accessory/cell_shortcuts.dart';
+import '../row/cells/cell_container.dart';
import 'editable_cell_skeleton/checkbox.dart';
import 'editable_cell_skeleton/checklist.dart';
@@ -13,9 +17,6 @@ import 'editable_cell_skeleton/select_option.dart';
import 'editable_cell_skeleton/text.dart';
import 'editable_cell_skeleton/timestamp.dart';
import 'editable_cell_skeleton/url.dart';
-import '../row/accessory/cell_accessory.dart';
-import '../row/accessory/cell_shortcuts.dart';
-import '../row/cells/cell_container.dart';
enum EditableCellStyle {
desktopGrid,
@@ -113,11 +114,12 @@ class EditableCellBuilder {
CellContext cellContext, {
required EditableCellSkinMap skinMap,
}) {
- final cellController = makeCellController(databaseController, cellContext);
+ final DatabaseController(:fieldController) = databaseController;
+ final fieldType = fieldController.getField(cellContext.fieldId)!.fieldType;
+
final key = ValueKey(
"${databaseController.viewId}${cellContext.fieldId}${cellContext.rowId}",
);
- final fieldType = cellController.fieldType;
assert(skinMap.has(fieldType));
return switch (fieldType) {
FieldType.Checkbox => EditableCheckboxCell(
@@ -239,6 +241,7 @@ abstract class GridCellState<T extends EditableCellWidget> extends State<T> {
@override
void dispose() {
+ widget.requestFocus.removeListener(onRequestFocus);
widget.requestFocus.dispose();
super.dispose();
}
diff --git a/frontend/appflowy_flutter/lib/plugins/database/widgets/cell/editable_cell_skeleton/url.dart b/frontend/appflowy_flutter/lib/plugins/database/widgets/cell/editable_cell_skeleton/url.dart
index 1e0a1af4be..7deb6c85e4 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/widgets/cell/editable_cell_skeleton/url.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/widgets/cell/editable_cell_skeleton/url.dart
@@ -89,6 +89,7 @@ class _GridURLCellState extends GridEditableTextCell<EditableURLCell> {
@override
void dispose() {
+ widget._cellDataNotifier.dispose();
_textEditingController.dispose();
cellBloc.close();
super.dispose();
diff --git a/frontend/appflowy_flutter/lib/plugins/database/widgets/cell/mobile_row_detail/mobile_row_detail_url_cell.dart b/frontend/appflowy_flutter/lib/plugins/database/widgets/cell/mobile_row_detail/mobile_row_detail_url_cell.dart
index 11635ceb7d..e48a82c054 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/widgets/cell/mobile_row_detail/mobile_row_detail_url_cell.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/widgets/cell/mobile_row_detail/mobile_row_detail_url_cell.dart
@@ -78,13 +78,13 @@ class MobileRowDetailURLCellSkin extends IEditableURLCellSkin {
const [];
void _showURLEditor(BuildContext context, URLCellBloc bloc, String content) {
+ final controller = TextEditingController(text: content);
showMobileBottomSheet(
context,
title: LocaleKeys.board_mobile_editURL.tr(),
showHeader: true,
showCloseButton: true,
builder: (_) {
- final controller = TextEditingController(text: content);
return TextField(
controller: controller,
autofocus: true,
@@ -95,6 +95,6 @@ class MobileRowDetailURLCellSkin extends IEditableURLCellSkin {
},
);
},
- );
+ ).then((_) => controller.dispose());
}
}
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.dart
index f368452813..6e69ded8a5 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
@@ -184,6 +184,14 @@ class _ChecklistItemState extends State<ChecklistItem> {
}
}
+ @override
+ void dispose() {
+ _textController.dispose();
+ _focusNode.dispose();
+ _debounceOnChanged?.cancel();
+ super.dispose();
+ }
+
@override
void didUpdateWidget(ChecklistItem oldWidget) {
super.didUpdateWidget(oldWidget);
@@ -300,6 +308,12 @@ class _NewTaskItemState extends State<NewTaskItem> {
}
}
+ @override
+ void dispose() {
+ _textEditingController.dispose();
+ super.dispose();
+ }
+
@override
Widget build(BuildContext context) {
return Container(
diff --git a/frontend/appflowy_flutter/lib/plugins/database/widgets/cell_editor/select_option_editor.dart b/frontend/appflowy_flutter/lib/plugins/database/widgets/cell_editor/select_option_editor.dart
index ced0f94760..f10f83fcc0 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/widgets/cell_editor/select_option_editor.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/widgets/cell_editor/select_option_editor.dart
@@ -37,6 +37,7 @@ class _SelectOptionCellEditorState extends State<SelectOptionCellEditor> {
@override
void dispose() {
popoverMutex.dispose();
+ textEditingController.dispose();
super.dispose();
}
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.dart
index 0e4c8a944a..2879bc8887 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
@@ -162,7 +162,6 @@ class _SelectOptionTextFieldState extends State<SelectOptionTextField> {
},
),
child: SingleChildScrollView(
- controller: ScrollController(),
scrollDirection: Axis.horizontal,
child: Wrap(spacing: 4, children: children),
),
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/find_and_replace/find_and_replace_menu.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/find_and_replace/find_and_replace_menu.dart
index 12a1961446..ce756b9ffd 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/find_and_replace/find_and_replace_menu.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/find_and_replace/find_and_replace_menu.dart
@@ -108,7 +108,8 @@ class _FindMenuState extends State<FindMenu> {
widget.searchService.currentSelectedIndex.removeListener(_setState);
widget.searchService.dispose();
findTextEditingController.removeListener(_searchPattern);
-
+ findTextEditingController.dispose();
+ findTextFieldFocusNode.dispose();
super.dispose();
}
@@ -241,6 +242,12 @@ class _ReplaceMenuState extends State<ReplaceMenu> {
late final FocusNode replaceTextFieldFocusNode;
final replaceTextEditingController = TextEditingController();
+ @override
+ void dispose() {
+ replaceTextEditingController.dispose();
+ super.dispose();
+ }
+
@override
Widget build(BuildContext context) {
return Row(
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/cover_editor.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/cover_editor.dart
index 26b22e97ac..37753b7724 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/cover_editor.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/cover_editor.dart
@@ -351,6 +351,12 @@ class CoverColorPicker extends StatefulWidget {
class _CoverColorPickerState extends State<CoverColorPicker> {
final scrollController = ScrollController();
+ @override
+ void dispose() {
+ scrollController.dispose();
+ super.dispose();
+ }
+
@override
Widget build(BuildContext context) {
return Container(
@@ -375,12 +381,6 @@ class _CoverColorPickerState extends State<CoverColorPicker> {
);
}
- @override
- void dispose() {
- super.dispose();
- scrollController.dispose();
- }
-
Widget _buildColorItems(List<ColorOption> options, String? selectedColor) {
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
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.dart
index 85767a5220..09b0ac3bec 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
@@ -110,9 +110,13 @@ class _NetworkImageUrlInputState extends State<NetworkImageUrlInput> {
@override
void initState() {
super.initState();
- urlController.addListener(() {
- setState(() {});
- });
+ urlController.addListener(() => setState(() {}));
+ }
+
+ @override
+ void dispose() {
+ urlController.dispose();
+ super.dispose();
}
@override
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/inline_math_equation/inline_math_equation.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/inline_math_equation/inline_math_equation.dart
index b76b9a48ad..543cee1207 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/inline_math_equation/inline_math_equation.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/inline_math_equation/inline_math_equation.dart
@@ -120,6 +120,12 @@ class _MathInputTextFieldState extends State<MathInputTextField> {
);
}
+ @override
+ void dispose() {
+ textEditingController.dispose();
+ super.dispose();
+ }
+
@override
Widget build(BuildContext context) {
return SizedBox(
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/math_equation/math_equation_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/math_equation/math_equation_block_component.dart
index 6afe34118c..0040f73df2 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/math_equation/math_equation_block_component.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/math_equation/math_equation_block_component.dart
@@ -187,10 +187,10 @@ class MathEquationBlockComponentWidgetState
}
void showEditingDialog() {
+ final controller = TextEditingController(text: formula);
showDialog(
context: context,
builder: (context) {
- final controller = TextEditingController(text: formula);
return AlertDialog(
backgroundColor: Theme.of(context).canvasColor,
title: Text(
@@ -234,7 +234,7 @@ class MathEquationBlockComponentWidgetState
actionsAlignment: MainAxisAlignment.spaceAround,
);
},
- );
+ ).then((_) => controller.dispose());
}
void updateMathEquation(String mathEquation, BuildContext context) {
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/appflowy_mobile_toolbar.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/appflowy_mobile_toolbar.dart
index b44d1c6053..ba286b7b9f 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/appflowy_mobile_toolbar.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/appflowy_mobile_toolbar.dart
@@ -478,7 +478,6 @@ class _ToolbarItemListViewState extends State<_ToolbarItemListView> {
void dispose() {
widget.editorState.selectionNotifier
.removeListener(_debounceUpdatePilotPosition);
-
super.dispose();
}
diff --git a/frontend/appflowy_flutter/lib/plugins/inline_actions/widgets/inline_actions_handler.dart b/frontend/appflowy_flutter/lib/plugins/inline_actions/widgets/inline_actions_handler.dart
index 03dce860bd..8e44232019 100644
--- a/frontend/appflowy_flutter/lib/plugins/inline_actions/widgets/inline_actions_handler.dart
+++ b/frontend/appflowy_flutter/lib/plugins/inline_actions/widgets/inline_actions_handler.dart
@@ -134,6 +134,13 @@ class _InlineActionsHandlerState extends State<InlineActionsHandler> {
startOffset = widget.editorState.selection?.endIndex ?? 0;
}
+ @override
+ void dispose() {
+ _scrollController.dispose();
+ _focusNode.dispose();
+ super.dispose();
+ }
+
@override
Widget build(BuildContext context) {
return Focus(
diff --git a/frontend/appflowy_flutter/lib/plugins/trash/trash_page.dart b/frontend/appflowy_flutter/lib/plugins/trash/trash_page.dart
index afabb6a57a..b50f95342a 100644
--- a/frontend/appflowy_flutter/lib/plugins/trash/trash_page.dart
+++ b/frontend/appflowy_flutter/lib/plugins/trash/trash_page.dart
@@ -28,6 +28,13 @@ class TrashPage extends StatefulWidget {
class _TrashPageState extends State<TrashPage> {
final ScrollController _scrollController = ScrollController();
+
+ @override
+ void dispose() {
+ _scrollController.dispose();
+ super.dispose();
+ }
+
@override
Widget build(BuildContext context) {
const horizontalPadding = 80.0;
diff --git a/frontend/appflowy_flutter/lib/user/presentation/screens/encrypt_secret_screen.dart b/frontend/appflowy_flutter/lib/user/presentation/screens/encrypt_secret_screen.dart
index 0cefb6e7d8..24fefbfc34 100644
--- a/frontend/appflowy_flutter/lib/user/presentation/screens/encrypt_secret_screen.dart
+++ b/frontend/appflowy_flutter/lib/user/presentation/screens/encrypt_secret_screen.dart
@@ -28,6 +28,13 @@ class EncryptSecretScreen extends StatefulWidget {
class _EncryptSecretScreenState extends State<EncryptSecretScreen> {
final TextEditingController _textEditingController = TextEditingController();
+
+ @override
+ void dispose() {
+ _textEditingController.dispose();
+ super.dispose();
+ }
+
@override
Widget build(BuildContext context) {
return Scaffold(
diff --git a/frontend/appflowy_flutter/lib/user/presentation/screens/workspace_start_screen/mobile_workspace_start_screen.dart b/frontend/appflowy_flutter/lib/user/presentation/screens/workspace_start_screen/mobile_workspace_start_screen.dart
index 6c95d1076c..b3c1f1cd0a 100644
--- a/frontend/appflowy_flutter/lib/user/presentation/screens/workspace_start_screen/mobile_workspace_start_screen.dart
+++ b/frontend/appflowy_flutter/lib/user/presentation/screens/workspace_start_screen/mobile_workspace_start_screen.dart
@@ -24,13 +24,19 @@ class MobileWorkspaceStartScreen extends StatefulWidget {
class _MobileWorkspaceStartScreenState
extends State<MobileWorkspaceStartScreen> {
WorkspacePB? selectedWorkspace;
+ final TextEditingController controller = TextEditingController();
+
+ @override
+ void dispose() {
+ controller.dispose();
+ super.dispose();
+ }
@override
Widget build(BuildContext context) {
final style = Theme.of(context);
final size = MediaQuery.of(context).size;
const double spacing = 16.0;
- final TextEditingController controller = TextEditingController();
final List<DropdownMenuEntry<WorkspacePB>> workspaceEntries =
<DropdownMenuEntry<WorkspacePB>>[];
for (final WorkspacePB workspace in widget.workspaceState.workspaces) {
diff --git a/frontend/appflowy_flutter/lib/workspace/application/tabs/tabs_bloc.dart b/frontend/appflowy_flutter/lib/workspace/application/tabs/tabs_bloc.dart
index 4770822f1a..c36a557c42 100644
--- a/frontend/appflowy_flutter/lib/workspace/application/tabs/tabs_bloc.dart
+++ b/frontend/appflowy_flutter/lib/workspace/application/tabs/tabs_bloc.dart
@@ -22,6 +22,12 @@ class TabsBloc extends Bloc<TabsEvent, TabsState> {
late final MenuSharedState menuSharedState;
+ @override
+ Future<void> close() {
+ state.dispose();
+ return super.close();
+ }
+
void _dispatch() {
on<TabsEvent>(
(event, emit) async {
diff --git a/frontend/appflowy_flutter/lib/workspace/application/tabs/tabs_state.dart b/frontend/appflowy_flutter/lib/workspace/application/tabs/tabs_state.dart
index caa9c8d3b9..dd08e505d6 100644
--- a/frontend/appflowy_flutter/lib/workspace/application/tabs/tabs_state.dart
+++ b/frontend/appflowy_flutter/lib/workspace/application/tabs/tabs_state.dart
@@ -98,4 +98,10 @@ class TabsState {
currentIndex: newIndex ?? currentIndex,
pageManagers: pageManagers ?? _pageManagers,
);
+
+ void dispose() {
+ for (final manager in pageManagers) {
+ manager.dispose();
+ }
+ }
}
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/home_stack.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/home_stack.dart
index d835956cdf..a941c9a284 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/home_stack.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/home_stack.dart
@@ -253,6 +253,10 @@ class PageManager {
),
);
}
+
+ void dispose() {
+ _notifier.dispose();
+ }
}
class HomeTopBar extends StatelessWidget {
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/view/view_item.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/view/view_item.dart
index 53d50f240c..5ce8d54288 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/view/view_item.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/view/view_item.dart
@@ -498,6 +498,7 @@ class _SingleInnerViewItemState extends State<SingleInnerViewItem> {
title: LocaleKeys.disclosureAction_rename.tr(),
autoSelectAllText: true,
value: widget.view.name,
+ maxLength: 256,
confirm: (newValue) {
context.read<ViewBloc>().add(ViewEvent.rename(newValue));
},
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.dart
index e4eb5546c8..f2bdbf4faa 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
@@ -25,6 +25,7 @@ class DefaultEmojiPickerViewState extends State<DefaultEmojiPickerView>
final FocusNode _emojiFocusNode = FocusNode();
EmojiCategoryGroup searchEmojiList =
EmojiCategoryGroup(EmojiCategory.SEARCH, <Emoji>[]);
+ final scrollController = ScrollController();
@override
void initState() {
@@ -70,6 +71,7 @@ class DefaultEmojiPickerViewState extends State<DefaultEmojiPickerView>
_emojiFocusNode.dispose();
_pageController?.dispose();
_tabController?.dispose();
+ scrollController.dispose();
super.dispose();
}
@@ -224,8 +226,6 @@ class DefaultEmojiPickerViewState extends State<DefaultEmojiPickerView>
Widget _buildPage(double emojiSize, EmojiCategoryGroup emojiCategoryGroup) {
// Display notice if recent has no entries yet
- final scrollController = ScrollController();
-
if (emojiCategoryGroup.category == EmojiCategory.RECENT &&
emojiCategoryGroup.emoji.isEmpty) {
return _buildNoRecent();
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/setting_appflowy_cloud.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/setting_appflowy_cloud.dart
index ab9473baac..f84fe9f374 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/setting_appflowy_cloud.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/setting_appflowy_cloud.dart
@@ -277,6 +277,12 @@ class CloudURLInputState extends State<CloudURLInput> {
_controller = TextEditingController(text: widget.url);
}
+ @override
+ void dispose() {
+ _controller.dispose();
+ super.dispose();
+ }
+
@override
Widget build(BuildContext context) {
return TextField(
@@ -306,12 +312,6 @@ class CloudURLInputState extends State<CloudURLInput> {
onChanged: widget.onChanged,
);
}
-
- @override
- void dispose() {
- _controller.dispose();
- super.dispose();
- }
}
class AppFlowyCloudEnableSync extends StatelessWidget {
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/setting_supabase_cloud.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/setting_supabase_cloud.dart
index 56a59aa58d..43e5472ef8 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/setting_supabase_cloud.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/setting_supabase_cloud.dart
@@ -273,6 +273,12 @@ class SupabaseInputState extends State<SupabaseInput> {
_controller = TextEditingController(text: widget.url);
}
+ @override
+ void dispose() {
+ _controller.dispose();
+ super.dispose();
+ }
+
@override
Widget build(BuildContext context) {
return TextField(
@@ -298,12 +304,6 @@ class SupabaseInputState extends State<SupabaseInput> {
onChanged: widget.onChanged,
);
}
-
- @override
- void dispose() {
- _controller.dispose();
- super.dispose();
- }
}
class SupabaseSelfhostTip extends StatelessWidget {
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/settings_customize_shortcuts_view.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/settings_customize_shortcuts_view.dart
index f391ac2ad7..382c3d9833 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/settings_customize_shortcuts_view.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/settings_customize_shortcuts_view.dart
@@ -138,10 +138,10 @@ class ShortcutsListTile extends StatelessWidget {
}
void showKeyListenerDialog(BuildContext widgetContext) {
+ final controller = TextEditingController(text: shortcutEvent.command);
showDialog(
context: widgetContext,
builder: (builderContext) {
- final controller = TextEditingController(text: shortcutEvent.command);
final formKey = GlobalKey<FormState>();
return AlertDialog(
title: Text(LocaleKeys.settings_shortcuts_updateShortcutStep.tr()),
@@ -184,7 +184,7 @@ class ShortcutsListTile extends StatelessWidget {
),
);
},
- );
+ ).then((_) => controller.dispose());
}
String? _validateForConflicts(BuildContext context, String command) {
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/settings_user_view.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/settings_user_view.dart
index d468051820..7ef8ccc1df 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/settings_user_view.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/settings_user_view.dart
@@ -246,6 +246,13 @@ class UserNameInputState extends State<UserNameInput> {
_controller = TextEditingController(text: widget.name);
}
+ @override
+ void dispose() {
+ _controller.dispose();
+ _debounce?.cancel();
+ super.dispose();
+ }
+
@override
Widget build(BuildContext context) {
return TextField(
@@ -277,13 +284,6 @@ class UserNameInputState extends State<UserNameInput> {
},
);
}
-
- @override
- void dispose() {
- _controller.dispose();
- _debounce?.cancel();
- super.dispose();
- }
}
@visibleForTesting
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/widgets/dialogs.dart b/frontend/appflowy_flutter/lib/workspace/presentation/widgets/dialogs.dart
index 24305ad7e3..1b431b58d6 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/widgets/dialogs.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/widgets/dialogs.dart
@@ -19,6 +19,7 @@ class NavigatorTextFieldDialog extends StatefulWidget {
required this.value,
required this.confirm,
this.cancel,
+ this.maxLength,
});
final String value;
@@ -26,6 +27,7 @@ class NavigatorTextFieldDialog extends StatefulWidget {
final void Function()? cancel;
final void Function(String) confirm;
final bool autoSelectAllText;
+ final int? maxLength;
@override
State<NavigatorTextFieldDialog> createState() =>
@@ -38,6 +40,7 @@ class _NavigatorTextFieldDialogState extends State<NavigatorTextFieldDialog> {
@override
void initState() {
+ super.initState();
newValue = widget.value;
controller.text = newValue;
if (widget.autoSelectAllText) {
@@ -46,7 +49,12 @@ class _NavigatorTextFieldDialogState extends State<NavigatorTextFieldDialog> {
extentOffset: newValue.length,
);
}
- super.initState();
+ }
+
+ @override
+ void dispose() {
+ controller.dispose();
+ super.dispose();
}
@override
@@ -63,9 +71,12 @@ class _NavigatorTextFieldDialogState extends State<NavigatorTextFieldDialog> {
FlowyFormTextInput(
hintText: LocaleKeys.dialogCreatePageNameHint.tr(),
controller: controller,
- textStyle: Theme.of(context).textTheme.bodySmall?.copyWith(
- fontSize: FontSizes.s16,
- ),
+ textStyle: Theme.of(context)
+ .textTheme
+ .bodySmall
+ ?.copyWith(fontSize: FontSizes.s16),
+ maxLength: widget.maxLength,
+ showCounter: false,
autoFocus: true,
onChanged: (text) {
newValue = text;
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/widgets/rename_view_popover.dart b/frontend/appflowy_flutter/lib/workspace/presentation/widgets/rename_view_popover.dart
index 0eab4b9284..b12ae6644a 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/widgets/rename_view_popover.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/widgets/rename_view_popover.dart
@@ -65,8 +65,10 @@ class _RenameViewPopoverState extends State<RenameViewPopover> {
width: 220,
child: FlowyTextField(
controller: _controller,
+ maxLength: 256,
onSubmitted: _updateViewName,
onCanceled: () => _updateViewName(_controller.text),
+ showCounter: false,
),
),
],
diff --git a/frontend/appflowy_flutter/packages/flowy_infra/lib/notifier.dart b/frontend/appflowy_flutter/packages/flowy_infra/lib/notifier.dart
index bbb55bf885..41017faafb 100644
--- a/frontend/appflowy_flutter/packages/flowy_infra/lib/notifier.dart
+++ b/frontend/appflowy_flutter/packages/flowy_infra/lib/notifier.dart
@@ -48,9 +48,3 @@ class PublishNotifier<T> extends ChangeNotifier {
);
}
}
-
-class Notifier extends ChangeNotifier {
- void notify() {
- notifyListeners();
- }
-}
diff --git a/frontend/appflowy_flutter/packages/flowy_infra_ui/example/lib/keyboard/keyboard_screen.dart b/frontend/appflowy_flutter/packages/flowy_infra_ui/example/lib/keyboard/keyboard_screen.dart
index fde544365b..d7704366f2 100644
--- a/frontend/appflowy_flutter/packages/flowy_infra_ui/example/lib/keyboard/keyboard_screen.dart
+++ b/frontend/appflowy_flutter/packages/flowy_infra_ui/example/lib/keyboard/keyboard_screen.dart
@@ -30,6 +30,12 @@ class _KeyboardScreenState extends State<KeyboardScreen> {
final TextEditingController _controller =
TextEditingController(text: 'Hello Flowy');
+ @override
+ void dispose() {
+ _controller.dispose();
+ super.dispose();
+ }
+
@override
Widget build(BuildContext context) {
return Scaffold(
diff --git a/frontend/appflowy_flutter/packages/flowy_infra_ui/lib/style_widget/scrolling/styled_scrollview.dart b/frontend/appflowy_flutter/packages/flowy_infra_ui/lib/style_widget/scrolling/styled_scrollview.dart
index ac8bd140b2..d255555ca0 100644
--- a/frontend/appflowy_flutter/packages/flowy_infra_ui/lib/style_widget/scrolling/styled_scrollview.dart
+++ b/frontend/appflowy_flutter/packages/flowy_infra_ui/lib/style_widget/scrolling/styled_scrollview.dart
@@ -45,7 +45,9 @@ class StyledSingleChildScrollViewState
@override
void dispose() {
- // scrollController.dispose();
+ if (widget.controller == null) {
+ scrollController.dispose();
+ }
super.dispose();
}
diff --git a/frontend/appflowy_flutter/packages/flowy_infra_ui/lib/style_widget/text_field.dart b/frontend/appflowy_flutter/packages/flowy_infra_ui/lib/style_widget/text_field.dart
index a6e6ce9a0a..ffedd06bd1 100644
--- a/frontend/appflowy_flutter/packages/flowy_infra_ui/lib/style_widget/text_field.dart
+++ b/frontend/appflowy_flutter/packages/flowy_infra_ui/lib/style_widget/text_field.dart
@@ -79,6 +79,7 @@ class FlowyTextFieldState extends State<FlowyTextField> {
focusNode.addListener(notifyDidEndEditing);
controller = widget.controller ?? TextEditingController();
+
if (widget.text != null) {
controller.text = widget.text!;
}
@@ -95,6 +96,19 @@ class FlowyTextFieldState extends State<FlowyTextField> {
}
}
+ @override
+ void dispose() {
+ focusNode.removeListener(notifyDidEndEditing);
+ if (widget.focusNode == null) {
+ focusNode.dispose();
+ }
+ if (widget.controller == null) {
+ controller.dispose();
+ }
+ _debounceOnChanged?.cancel();
+ super.dispose();
+ }
+
void _debounceOnChangedText(Duration duration, String text) {
_debounceOnChanged?.cancel();
_debounceOnChanged = Timer(duration, () async {
@@ -200,15 +214,6 @@ class FlowyTextFieldState extends State<FlowyTextField> {
);
}
- @override
- void dispose() {
- focusNode.removeListener(notifyDidEndEditing);
- if (widget.focusNode == null) {
- focusNode.dispose();
- }
- super.dispose();
- }
-
void notifyDidEndEditing() {
if (!focusNode.hasFocus) {
if (controller.text.isNotEmpty && widget.submitOnLeave) {
@@ -222,8 +227,7 @@ class FlowyTextFieldState extends State<FlowyTextField> {
String? _suffixText() {
if (widget.maxLength != null) {
return ' ${controller.text.length}/${widget.maxLength}';
- } else {
- return null;
}
+ return null;
}
}
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.dart
index c7e6368aa8..7aad277b11 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
@@ -17,6 +17,8 @@ class FlowyFormTextInput extends StatelessWidget {
final TextStyle? textStyle;
final TextAlign textAlign;
final int? maxLines;
+ final int? maxLength;
+ final bool showCounter;
final TextEditingController? controller;
final TextCapitalization? capitalization;
final Function(String)? onChanged;
@@ -24,23 +26,25 @@ class FlowyFormTextInput extends StatelessWidget {
final Function(bool)? onFocusChanged;
final Function(FocusNode)? onFocusCreated;
- const FlowyFormTextInput(
- {Key? key,
- this.label,
- this.autoFocus,
- this.initialValue,
- this.onChanged,
- this.onEditingComplete,
- this.hintText,
- this.onFocusChanged,
- this.onFocusCreated,
- this.controller,
- this.contentPadding,
- this.capitalization,
- this.textStyle,
- this.textAlign = TextAlign.center,
- this.maxLines})
- : super(key: key);
+ const FlowyFormTextInput({
+ super.key,
+ this.label,
+ this.autoFocus,
+ this.initialValue,
+ this.onChanged,
+ this.onEditingComplete,
+ this.hintText,
+ this.onFocusChanged,
+ this.onFocusCreated,
+ this.controller,
+ this.contentPadding,
+ this.capitalization,
+ this.textStyle,
+ this.textAlign = TextAlign.center,
+ this.maxLines,
+ this.maxLength,
+ this.showCounter = true,
+ });
@override
Widget build(BuildContext context) {
@@ -57,16 +61,17 @@ class FlowyFormTextInput extends StatelessWidget {
onFocusChanged: onFocusChanged,
controller: controller,
maxLines: maxLines,
- inputDecoration: InputDecoration(
- isDense: true,
- contentPadding: contentPadding ?? kDefaultTextInputPadding,
- border: const ThinUnderlineBorder(
- borderSide: BorderSide(width: 5, color: Colors.red)),
- hintStyle: Theme.of(context)
- .textTheme
- .bodyMedium!
- .copyWith(color: Theme.of(context).hintColor.withOpacity(0.7)),
- hintText: hintText,
+ maxLength: maxLength,
+ showCounter: showCounter,
+ contentPadding: contentPadding ?? kDefaultTextInputPadding,
+ hintText: hintText,
+ hintStyle: Theme.of(context)
+ .textTheme
+ .bodyMedium!
+ .copyWith(color: Theme.of(context).hintColor.withOpacity(0.7)),
+ isDense: true,
+ inputBorder: const ThinUnderlineBorder(
+ borderSide: BorderSide(width: 5, color: Colors.red),
),
);
}
@@ -82,6 +87,8 @@ class StyledSearchTextInput extends StatefulWidget {
final IconData? icon;
final String? initialValue;
final int? maxLines;
+ final int? maxLength;
+ final bool showCounter;
final TextEditingController? controller;
final TextCapitalization? capitalization;
final TextInputType? type;
@@ -89,11 +96,14 @@ class StyledSearchTextInput extends StatefulWidget {
final bool? autoValidate;
final bool? enableSuggestions;
final bool? autoCorrect;
+ final bool isDense;
final String? errorText;
final String? hintText;
+ final TextStyle? hintStyle;
final Widget? prefixIcon;
final Widget? suffixIcon;
final InputDecoration? inputDecoration;
+ final InputBorder? inputBorder;
final Function(String)? onChanged;
final Function()? onEditingComplete;
@@ -105,7 +115,7 @@ class StyledSearchTextInput extends StatefulWidget {
final VoidCallback? onTap;
const StyledSearchTextInput({
- Key? key,
+ super.key,
this.label,
this.autoFocus = false,
this.obscureText = false,
@@ -118,6 +128,7 @@ class StyledSearchTextInput extends StatefulWidget {
this.autoValidate = false,
this.enableSuggestions = true,
this.autoCorrect = true,
+ this.isDense = false,
this.errorText,
this.style,
this.contentPadding,
@@ -133,9 +144,13 @@ class StyledSearchTextInput extends StatefulWidget {
this.onSaved,
this.onTap,
this.hintText,
+ this.hintStyle,
this.capitalization,
this.maxLines,
- }) : super(key: key);
+ this.maxLength,
+ this.showCounter = false,
+ this.inputBorder,
+ });
@override
StyledSearchTextInputState createState() => StyledSearchTextInputState();
@@ -175,7 +190,9 @@ class StyledSearchTextInputState extends State<StyledSearchTextInput> {
@override
void dispose() {
- _controller.dispose();
+ if (widget.controller == null) {
+ _controller.dispose();
+ }
_focusNode.dispose();
super.dispose();
}
@@ -208,28 +225,40 @@ class StyledSearchTextInputState extends State<StyledSearchTextInput> {
showCursor: true,
enabled: widget.enabled,
maxLines: widget.maxLines,
+ maxLength: widget.maxLength,
textCapitalization: widget.capitalization ?? TextCapitalization.none,
textAlign: widget.textAlign,
decoration: widget.inputDecoration ??
InputDecoration(
prefixIcon: widget.prefixIcon,
suffixIcon: widget.suffixIcon,
+ counterText: "",
+ suffixText: widget.showCounter ? _suffixText() : "",
contentPadding: widget.contentPadding ?? EdgeInsets.all(Insets.m),
- border: const OutlineInputBorder(borderSide: BorderSide.none),
- isDense: true,
+ border: widget.inputBorder ??
+ const OutlineInputBorder(borderSide: BorderSide.none),
+ isDense: widget.isDense,
icon: widget.icon == null ? null : Icon(widget.icon),
errorText: widget.errorText,
errorMaxLines: 2,
hintText: widget.hintText,
- hintStyle: Theme.of(context)
- .textTheme
- .bodyMedium!
- .copyWith(color: Theme.of(context).hintColor),
+ hintStyle: widget.hintStyle ??
+ Theme.of(context)
+ .textTheme
+ .bodyMedium!
+ .copyWith(color: Theme.of(context).hintColor),
labelText: widget.label,
),
),
);
}
+
+ String? _suffixText() {
+ if (widget.controller != null && widget.maxLength != null) {
+ return ' ${widget.controller!.text.length}/${widget.maxLength}';
+ }
+ return null;
+ }
}
class ThinUnderlineBorder extends InputBorder {