Skip to content

Commit c9d5753

Browse files
committed
chore: edit card directly by clicking edit button
1 parent cb06722 commit c9d5753

File tree

4 files changed

+48
-17
lines changed

4 files changed

+48
-17
lines changed

frontend/app_flowy/lib/plugins/board/presentation/card/board_cell.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ class EditableRowNotifier {
3434
notifier.resignFirstResponder.notify();
3535
}
3636
}
37+
38+
void dispose() {
39+
for (final notifier in cells.values) {
40+
notifier.resignFirstResponder.notify();
41+
}
42+
43+
cells.clear();
44+
}
3745
}
3846

3947
abstract class EditableCell {

frontend/app_flowy/lib/plugins/board/presentation/card/board_text_cell.dart

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:app_flowy/plugins/board/application/card/board_text_cell_bloc.dart';
22
import 'package:app_flowy/plugins/grid/application/cell/cell_service/cell_service.dart';
33
import 'package:app_flowy/plugins/grid/presentation/widgets/cell/cell_builder.dart';
4+
import 'package:flowy_infra_ui/style_widget/text.dart';
45
import 'package:flutter/material.dart';
56
import 'package:flutter_bloc/flutter_bloc.dart';
67

@@ -42,9 +43,17 @@ class _BoardTextCellState extends State<BoardTextCell> {
4243
focusNode.requestFocus();
4344
}
4445

46+
focusNode.addListener(() {
47+
if (!focusNode.hasFocus) {
48+
_cellBloc.add(const BoardTextCellEvent.enableEdit(false));
49+
}
50+
});
51+
4552
widget.editableNotifier?.becomeFirstResponder.addListener(() {
4653
if (!mounted) return;
47-
focusNode.requestFocus();
54+
WidgetsBinding.instance.addPostFrameCallback((_) {
55+
focusNode.requestFocus();
56+
});
4857
_cellBloc.add(const BoardTextCellEvent.enableEdit(true));
4958
});
5059

@@ -67,22 +76,36 @@ class _BoardTextCellState extends State<BoardTextCell> {
6776
}
6877
},
6978
child: BlocBuilder<BoardTextCellBloc, BoardTextCellState>(
70-
buildWhen: (previous, current) =>
71-
previous.enableEdit != current.enableEdit,
7279
builder: (context, state) {
73-
return TextField(
74-
// autofocus: true,
75-
// enabled: state.enableEdit,
76-
controller: _controller,
77-
focusNode: focusNode,
78-
onChanged: (value) => focusChanged(),
79-
onEditingComplete: () => focusNode.unfocus(),
80-
maxLines: 1,
81-
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500),
82-
decoration: const InputDecoration(
83-
contentPadding: EdgeInsets.symmetric(vertical: 6),
84-
border: InputBorder.none,
85-
isDense: true,
80+
Widget child;
81+
if (state.enableEdit) {
82+
child = TextField(
83+
controller: _controller,
84+
focusNode: focusNode,
85+
onChanged: (value) => focusChanged(),
86+
onEditingComplete: () => focusNode.unfocus(),
87+
maxLines: 1,
88+
style: const TextStyle(
89+
fontSize: 14,
90+
fontWeight: FontWeight.w500,
91+
fontFamily: 'Mulish',
92+
),
93+
decoration: const InputDecoration(
94+
// Magic number 4 makes the textField take up the same space as FlowyText
95+
contentPadding: EdgeInsets.symmetric(vertical: 4),
96+
border: InputBorder.none,
97+
isDense: true,
98+
),
99+
);
100+
} else {
101+
child = FlowyText.medium(state.content, fontSize: 14);
102+
}
103+
104+
return Align(
105+
alignment: Alignment.centerLeft,
106+
child: Padding(
107+
padding: const EdgeInsets.symmetric(vertical: 6),
108+
child: child,
86109
),
87110
);
88111
},

frontend/app_flowy/lib/plugins/board/presentation/card/card.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class _BoardCardState extends State<BoardCard> {
122122

123123
@override
124124
Future<void> dispose() async {
125+
rowNotifier.dispose();
125126
_cardBloc.close();
126127
super.dispose();
127128
}

frontend/app_flowy/packages/appflowy_board/lib/src/widgets/board.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ class _AFBoardContentState extends State<AFBoardContent> {
250250
builder: (context, value, child) {
251251
final boardColumn = AFBoardColumnWidget(
252252
// key: PageStorageKey<String>(columnData.id),
253-
// key: GlobalObjectKey(columnData.id),
254253
margin: _marginFromIndex(columnIndex),
255254
itemMargin: widget.config.columnItemPadding,
256255
headerBuilder: _buildHeader,

0 commit comments

Comments
 (0)