mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: dispose of resources in time (#4625)
* fix: limit length when renaming views * chore: clean up database listeners * fix: dispose of controllers properly * fix: dispose of resources properly * fix: deleting filters with same name * chore: extend DatabaseTabBarItemBuilder * fix: null check on null value
This commit is contained in:
@ -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();
|
||||
|
@ -1,10 +1,14 @@
|
||||
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 'package:appflowy/plugins/database/application/cell/cell_controller.dart';
|
||||
import 'package:appflowy/plugins/database/application/database_controller.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-database2/protobuf.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';
|
||||
import 'editable_cell_skeleton/date.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();
|
||||
}
|
||||
|
@ -89,6 +89,7 @@ class _GridURLCellState extends GridEditableTextCell<EditableURLCell> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
widget._cellDataNotifier.dispose();
|
||||
_textEditingController.dispose();
|
||||
cellBloc.close();
|
||||
super.dispose();
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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(
|
||||
|
@ -37,6 +37,7 @@ class _SelectOptionCellEditorState extends State<SelectOptionCellEditor> {
|
||||
@override
|
||||
void dispose() {
|
||||
popoverMutex.dispose();
|
||||
textEditingController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
@ -162,7 +162,6 @@ class _SelectOptionTextFieldState extends State<SelectOptionTextField> {
|
||||
},
|
||||
),
|
||||
child: SingleChildScrollView(
|
||||
controller: ScrollController(),
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Wrap(spacing: 4, children: children),
|
||||
),
|
||||
|
Reference in New Issue
Block a user