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
chore: handle edit state
appflowy951206db7107
diff --git a/frontend/app_flowy/lib/plugins/board/presentation/card/board_cell.dart b/frontend/app_flowy/lib/plugins/board/presentation/card/board_cell.dartindex e8a0406e0f..77fc4b0f46 100644--- a/frontend/app_flowy/lib/plugins/board/presentation/card/board_cell.dart+++ b/frontend/app_flowy/lib/plugins/board/presentation/card/board_cell.dart@@ -1,5 +1,6 @@import 'package:app_flowy/plugins/grid/application/prelude.dart';import 'package:flowy_infra/notifier.dart';+import 'package:flutter/material.dart';abstract class FocusableBoardCell {set becomeFocus(bool isFocus);@@ -10,7 +11,16 @@ class EditableCellNotifier {final Notifier resignFirstResponder = Notifier();- EditableCellNotifier();+ final ValueNotifier<bool> isCellEditing;++ EditableCellNotifier({bool isEditing = false})+ : isCellEditing = ValueNotifier(isEditing);++ void dispose() {+ becomeFirstResponder.dispose();+ resignFirstResponder.dispose();+ isCellEditing.dispose();+ }}class EditableRowNotifier {@@ -20,6 +30,11 @@ class EditableRowNotifier {GridCellIdentifier cellIdentifier,EditableCellNotifier notifier,) {+ final id = EditableCellId.from(cellIdentifier);+ _cells[id]?.dispose();++ notifier.isCellEditing.addListener(() {});+_cells[EditableCellId.from(cellIdentifier)] = notifier;}@@ -36,6 +51,9 @@ class EditableRowNotifier {}void clear() {+ for (final notifier in _cells.values) {+ notifier.dispose();+ }_cells.clear();}diff --git a/frontend/app_flowy/lib/plugins/board/presentation/card/board_text_cell.dart b/frontend/app_flowy/lib/plugins/board/presentation/card/board_text_cell.dartindex c6a6fb13cc..08068a8e49 100644--- a/frontend/app_flowy/lib/plugins/board/presentation/card/board_text_cell.dart+++ b/frontend/app_flowy/lib/plugins/board/presentation/card/board_text_cell.dart@@ -9,7 +9,6 @@ import 'define.dart';class BoardTextCell extends StatefulWidget with EditableCell {final String groupId;- final bool isFocus;@overridefinal EditableCellNotifier? editableNotifier;final GridCellControllerBuilder cellControllerBuilder;@@ -18,7 +17,6 @@ class BoardTextCell extends StatefulWidget with EditableCell {required this.groupId,required this.cellControllerBuilder,this.editableNotifier,- this.isFocus = false,Key? key,}) : super(key: key);@@ -39,21 +37,16 @@ class _BoardTextCellState extends State<BoardTextCell> {_cellBloc = BoardTextCellBloc(cellController: cellController)..add(const BoardTextCellEvent.initial());_controller = TextEditingController(text: _cellBloc.state.content);- focusWhenInit = widget.isFocus;-- if (widget.isFocus) {+ focusWhenInit = widget.editableNotifier?.isCellEditing.value ?? false;+ if (focusWhenInit) {focusNode.requestFocus();}focusNode.addListener(() {if (!focusNode.hasFocus) {+ focusWhenInit = false;+ widget.editableNotifier?.isCellEditing.value = false;_cellBloc.add(const BoardTextCellEvent.enableEdit(false));-- if (focusWhenInit) {- setState(() {- focusWhenInit = false;- });- }}});_bindEditableNotifier();diff --git a/frontend/app_flowy/lib/plugins/board/presentation/card/card.dart b/frontend/app_flowy/lib/plugins/board/presentation/card/card.dartindex cd088a3d5b..a2fc7ee7f5 100644--- a/frontend/app_flowy/lib/plugins/board/presentation/card/card.dart+++ b/frontend/app_flowy/lib/plugins/board/presentation/card/card.dart@@ -96,17 +96,20 @@ class _BoardCardState extends State<BoardCard> {rowNotifier.clear();cells.asMap().forEach((int index, GridCellIdentifier cellId) {- final cellNotifier = EditableCellNotifier();+ EditableCellNotifier cellNotifier;+ if (index == 0) {+ cellNotifier = EditableCellNotifier(isEditing: widget.isEditing);+ rowNotifier.insertCell(cellId, cellNotifier);+ } else {+ cellNotifier = EditableCellNotifier();+ }+Widget child = widget.cellBuilder.buildCell(widget.groupId,cellId,- index == 0 ? widget.isEditing : false,cellNotifier,);- if (index == 0) {- rowNotifier.insertCell(cellId, cellNotifier);- }child = Padding(key: cellId.key(),padding: const EdgeInsets.only(left: 4, right: 4),diff --git a/frontend/app_flowy/lib/plugins/board/presentation/card/card_cell_builder.dart b/frontend/app_flowy/lib/plugins/board/presentation/card/card_cell_builder.dartindex 99bd3f3b3a..1485bb7bd0 100644--- a/frontend/app_flowy/lib/plugins/board/presentation/card/card_cell_builder.dart+++ b/frontend/app_flowy/lib/plugins/board/presentation/card/card_cell_builder.dart@@ -23,7 +23,6 @@ class BoardCellBuilder {Widget buildCell(String groupId,GridCellIdentifier cellId,- bool isEditing,EditableCellNotifier cellNotifier,) {final cellControllerBuilder = GridCellControllerBuilder(@@ -69,7 +68,6 @@ class BoardCellBuilder {return BoardTextCell(groupId: groupId,cellControllerBuilder: cellControllerBuilder,- isFocus: isEditing,editableNotifier: cellNotifier,key: key,);