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
refactor: GridCellRequestFocusNotifier only accepts single listener
appflowy6b5126b12ef6
diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_builder.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_builder.dartindex 2049e9583b..8d7ea06c54 100755--- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_builder.dart+++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_builder.dart@@ -57,6 +57,24 @@ abstract class GridCellWidget extends HoverWidget {}class GridCellRequestFocusNotifier extends ChangeNotifier {+ VoidCallback? _listener;++ @override+ void addListener(VoidCallback listener) {+ if (_listener != null) {+ removeListener(_listener!);+ }++ _listener = listener;+ super.addListener(listener);+ }++ void removeAllListener() {+ if (_listener != null) {+ removeListener(_listener!);+ }+ }+void notify() {notifyListeners();}diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/checkbox_cell.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/checkbox_cell.dartindex 99fcd4a26f..c4da2a223f 100644--- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/checkbox_cell.dart+++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/checkbox_cell.dart@@ -57,6 +57,7 @@ class _CheckboxCellState extends State<CheckboxCell> {@overrideFuture<void> dispose() async {+ widget.requestFocus.removeAllListener();_cellBloc.close();super.dispose();}diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/number_cell.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/number_cell.dartindex b45f964bdc..c012db3304 100644--- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/number_cell.dart+++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/number_cell.dart@@ -23,7 +23,6 @@ class _NumberCellState extends State<NumberCell> {late NumberCellBloc _cellBloc;late TextEditingController _controller;late FocusNode _focusNode;- VoidCallback? _focusListener;Timer? _delayOperation;@override@@ -70,9 +69,7 @@ class _NumberCellState extends State<NumberCell> {@overrideFuture<void> dispose() async {- if (_focusListener != null) {- widget.requestFocus.removeListener(_focusListener!);- }+ widget.requestFocus.removeAllListener();_delayOperation?.cancel();_cellBloc.close();_focusNode.dispose();@@ -96,17 +93,10 @@ class _NumberCellState extends State<NumberCell> {}void _listenCellRequestFocus(BuildContext context) {- if (_focusListener != null) {- widget.requestFocus.removeListener(_focusListener!);- }-- focusListener() {+ widget.requestFocus.addListener(() {if (_focusNode.hasFocus == false && _focusNode.canRequestFocus) {FocusScope.of(context).requestFocus(_focusNode);}- }-- _focusListener = focusListener;- widget.requestFocus.addListener(focusListener);+ });}}diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/selection_cell/selection_cell.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/selection_cell/selection_cell.dartindex 01aad63699..73aa583956 100644--- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/selection_cell/selection_cell.dart+++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/selection_cell/selection_cell.dart@@ -157,7 +157,6 @@ class _SelectOptionCell extends StatelessWidget {);}- final cellContext = cellContextBuilder.build() as GridSelectOptionCellContext;return Stack(alignment: AlignmentDirectional.center,fit: StackFit.expand,@@ -166,6 +165,7 @@ class _SelectOptionCell extends StatelessWidget {InkWell(onTap: () {onFocus(true);+ final cellContext = cellContextBuilder.build() as GridSelectOptionCellContext;SelectOptionCellEditor.show(context, cellContext, () => onFocus(false));},),diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/text_cell.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/text_cell.dartindex 2b3a72525f..affcacafd2 100644--- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/text_cell.dart+++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/text_cell.dart@@ -36,7 +36,8 @@ class _GridTextCellState extends State<GridTextCell> {late TextCellBloc _cellBloc;late TextEditingController _controller;late FocusNode _focusNode;- VoidCallback? _focusListener;++ VoidCallback? _focusNodeListener;Timer? _delayOperation;@override@@ -87,32 +88,29 @@ class _GridTextCellState extends State<GridTextCell> {);}- void _listenCellRequestFocus(BuildContext context) {- if (_focusListener != null) {- widget.requestFocus.removeListener(_focusListener!);- }-- focusListener() {- if (_focusNode.hasFocus == false && _focusNode.canRequestFocus) {- FocusScope.of(context).requestFocus(_focusNode);- }- }-- _focusListener = focusListener;- widget.requestFocus.addListener(focusListener);- }-@overrideFuture<void> dispose() async {- if (_focusListener != null) {- widget.requestFocus.removeListener(_focusListener!);- }+ widget.requestFocus.removeAllListener();_delayOperation?.cancel();_cellBloc.close();_focusNode.dispose();super.dispose();}+ @override+ void didUpdateWidget(covariant GridTextCell oldWidget) {+ // TODO: implement didUpdateWidget+ super.didUpdateWidget(oldWidget);+ }++ void _listenCellRequestFocus(BuildContext context) {+ widget.requestFocus.addListener(() {+ if (_focusNode.hasFocus == false && _focusNode.canRequestFocus) {+ FocusScope.of(context).requestFocus(_focusNode);+ }+ });+ }+Future<void> focusChanged() async {if (mounted) {_delayOperation?.cancel();diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/row/grid_row.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/row/grid_row.dartindex 8d8d66fa03..68908f1243 100755--- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/row/grid_row.dart+++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/row/grid_row.dart@@ -153,7 +153,7 @@ class _RowCells extends StatelessWidget {@overrideWidget build(BuildContext context) {return BlocBuilder<RowBloc, RowState>(- buildWhen: (previous, current) => previous.cellDataMap.length != current.cellDataMap.length,+ buildWhen: (previous, current) => previous.cellDataMap != current.cellDataMap,builder: (context, state) {return IntrinsicHeight(child: Row(