Skip to content

Commit b2db454

Browse files
authored
Merge pull request #962 from AppFlowy-IO/fix/board_ui_bugs
fix: board ui bugs
2 parents bd482d0 + bc69cb5 commit b2db454

File tree

2 files changed

+73
-46
lines changed

2 files changed

+73
-46
lines changed

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

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -80,23 +80,7 @@ class _BoardContentState extends State<BoardContent> {
8080
@override
8181
Widget build(BuildContext context) {
8282
return BlocListener<BoardBloc, BoardState>(
83-
listener: (context, state) {
84-
state.editingRow.fold(
85-
() => null,
86-
(editingRow) {
87-
WidgetsBinding.instance.addPostFrameCallback((_) {
88-
if (editingRow.index != null) {
89-
} else {
90-
scrollManager.scrollToBottom(editingRow.columnId, () {
91-
context
92-
.read<BoardBloc>()
93-
.add(BoardEvent.endEditRow(editingRow.row.id));
94-
});
95-
}
96-
});
97-
},
98-
);
99-
},
83+
listener: (context, state) => _handleEditState(state, context),
10084
child: BlocBuilder<BoardBloc, BoardState>(
10185
buildWhen: (previous, current) =>
10286
previous.groupIds.length != current.groupIds.length,
@@ -137,6 +121,27 @@ class _BoardContentState extends State<BoardContent> {
137121
);
138122
}
139123

124+
void _handleEditState(BoardState state, BuildContext context) {
125+
state.editingRow.fold(
126+
() => null,
127+
(editingRow) {
128+
WidgetsBinding.instance.addPostFrameCallback((_) {
129+
if (editingRow.index != null) {
130+
context
131+
.read<BoardBloc>()
132+
.add(BoardEvent.endEditRow(editingRow.row.id));
133+
} else {
134+
scrollManager.scrollToBottom(editingRow.columnId, () {
135+
context
136+
.read<BoardBloc>()
137+
.add(BoardEvent.endEditRow(editingRow.row.id));
138+
});
139+
}
140+
});
141+
},
142+
);
143+
}
144+
140145
@override
141146
void dispose() {
142147
scrollController.dispose();

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

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
66
import 'package:flutter_bloc/flutter_bloc.dart';
77

88
import 'board_cell.dart';
9+
import 'define.dart';
910

1011
class BoardTextCell extends StatefulWidget with EditableCell {
1112
final String groupId;
@@ -29,6 +30,7 @@ class BoardTextCell extends StatefulWidget with EditableCell {
2930
class _BoardTextCellState extends State<BoardTextCell> {
3031
late BoardTextCellBloc _cellBloc;
3132
late TextEditingController _controller;
33+
bool focusWhenInit = false;
3234
SingleListenerFocusNode focusNode = SingleListenerFocusNode();
3335

3436
@override
@@ -38,6 +40,7 @@ class _BoardTextCellState extends State<BoardTextCell> {
3840
_cellBloc = BoardTextCellBloc(cellController: cellController)
3941
..add(const BoardTextCellEvent.initial());
4042
_controller = TextEditingController(text: _cellBloc.state.content);
43+
focusWhenInit = widget.isFocus;
4144

4245
if (widget.isFocus) {
4346
focusNode.requestFocus();
@@ -46,6 +49,12 @@ class _BoardTextCellState extends State<BoardTextCell> {
4649
focusNode.addListener(() {
4750
if (!focusNode.hasFocus) {
4851
_cellBloc.add(const BoardTextCellEvent.enableEdit(false));
52+
53+
if (focusWhenInit) {
54+
setState(() {
55+
focusWhenInit = false;
56+
});
57+
}
4958
}
5059
});
5160

@@ -77,38 +86,19 @@ class _BoardTextCellState extends State<BoardTextCell> {
7786
},
7887
child: BlocBuilder<BoardTextCellBloc, BoardTextCellState>(
7988
builder: (context, state) {
89+
if (state.content.isEmpty &&
90+
state.enableEdit == false &&
91+
focusWhenInit == false) {
92+
return const SizedBox();
93+
}
94+
95+
//
8096
Widget child;
81-
if (state.content.isEmpty && state.enableEdit == false) {
82-
child = const SizedBox();
97+
if (state.enableEdit || focusWhenInit) {
98+
child = _buildTextField();
8399
} else {
84-
if (state.enableEdit) {
85-
child = TextField(
86-
controller: _controller,
87-
focusNode: focusNode,
88-
onChanged: (value) => focusChanged(),
89-
onEditingComplete: () => focusNode.unfocus(),
90-
maxLines: 1,
91-
style: const TextStyle(
92-
fontSize: 14,
93-
fontWeight: FontWeight.w500,
94-
fontFamily: 'Mulish',
95-
),
96-
decoration: const InputDecoration(
97-
// Magic number 4 makes the textField take up the same space as FlowyText
98-
contentPadding: EdgeInsets.symmetric(vertical: 4),
99-
border: InputBorder.none,
100-
isDense: true,
101-
),
102-
);
103-
} else {
104-
child = FlowyText.medium(state.content, fontSize: 14);
105-
child = Padding(
106-
padding: const EdgeInsets.symmetric(vertical: 6),
107-
child: child,
108-
);
109-
}
100+
child = _buildText(state);
110101
}
111-
112102
return Align(alignment: Alignment.centerLeft, child: child);
113103
},
114104
),
@@ -127,4 +117,36 @@ class _BoardTextCellState extends State<BoardTextCell> {
127117
focusNode.dispose();
128118
super.dispose();
129119
}
120+
121+
Widget _buildText(BoardTextCellState state) {
122+
return Padding(
123+
padding: EdgeInsets.symmetric(
124+
vertical: BoardSizes.cardCellVPadding,
125+
),
126+
child: FlowyText.medium(state.content, fontSize: 14),
127+
);
128+
}
129+
130+
Widget _buildTextField() {
131+
return TextField(
132+
controller: _controller,
133+
focusNode: focusNode,
134+
onChanged: (value) => focusChanged(),
135+
onEditingComplete: () => focusNode.unfocus(),
136+
maxLines: 1,
137+
style: const TextStyle(
138+
fontSize: 14,
139+
fontWeight: FontWeight.w500,
140+
fontFamily: 'Mulish',
141+
),
142+
decoration: InputDecoration(
143+
// Magic number 4 makes the textField take up the same space as FlowyText
144+
contentPadding: EdgeInsets.symmetric(
145+
vertical: BoardSizes.cardCellVPadding + 4,
146+
),
147+
border: InputBorder.none,
148+
isDense: true,
149+
),
150+
);
151+
}
130152
}

0 commit comments

Comments
 (0)