Merge pull request #958 from AppFlowy-IO/feat/click_to_edit_card

This commit is contained in:
Nathan.fooo 2022-08-31 18:06:56 +08:00 committed by GitHub
commit 942e966a25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 17 deletions

View File

@ -34,6 +34,14 @@ class EditableRowNotifier {
notifier.resignFirstResponder.notify();
}
}
void dispose() {
for (final notifier in cells.values) {
notifier.resignFirstResponder.notify();
}
cells.clear();
}
}
abstract class EditableCell {

View File

@ -1,6 +1,7 @@
import 'package:app_flowy/plugins/board/application/card/board_text_cell_bloc.dart';
import 'package:app_flowy/plugins/grid/application/cell/cell_service/cell_service.dart';
import 'package:app_flowy/plugins/grid/presentation/widgets/cell/cell_builder.dart';
import 'package:flowy_infra_ui/style_widget/text.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
@ -42,9 +43,17 @@ class _BoardTextCellState extends State<BoardTextCell> {
focusNode.requestFocus();
}
focusNode.addListener(() {
if (!focusNode.hasFocus) {
_cellBloc.add(const BoardTextCellEvent.enableEdit(false));
}
});
widget.editableNotifier?.becomeFirstResponder.addListener(() {
if (!mounted) return;
WidgetsBinding.instance.addPostFrameCallback((_) {
focusNode.requestFocus();
});
_cellBloc.add(const BoardTextCellEvent.enableEdit(true));
});
@ -67,24 +76,38 @@ class _BoardTextCellState extends State<BoardTextCell> {
}
},
child: BlocBuilder<BoardTextCellBloc, BoardTextCellState>(
buildWhen: (previous, current) =>
previous.enableEdit != current.enableEdit,
builder: (context, state) {
return TextField(
// autofocus: true,
// enabled: state.enableEdit,
Widget child;
if (state.enableEdit) {
child = TextField(
controller: _controller,
focusNode: focusNode,
onChanged: (value) => focusChanged(),
onEditingComplete: () => focusNode.unfocus(),
maxLines: 1,
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500),
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
fontFamily: 'Mulish',
),
decoration: const InputDecoration(
contentPadding: EdgeInsets.symmetric(vertical: 6),
// Magic number 4 makes the textField take up the same space as FlowyText
contentPadding: EdgeInsets.symmetric(vertical: 4),
border: InputBorder.none,
isDense: true,
),
);
} else {
child = FlowyText.medium(state.content, fontSize: 14);
}
return Align(
alignment: Alignment.centerLeft,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 6),
child: child,
),
);
},
),
),

View File

@ -122,6 +122,7 @@ class _BoardCardState extends State<BoardCard> {
@override
Future<void> dispose() async {
rowNotifier.dispose();
_cardBloc.close();
super.dispose();
}

View File

@ -250,7 +250,6 @@ class _AFBoardContentState extends State<AFBoardContent> {
builder: (context, value, child) {
final boardColumn = AFBoardColumnWidget(
// key: PageStorageKey<String>(columnData.id),
// key: GlobalObjectKey(columnData.id),
margin: _marginFromIndex(columnIndex),
itemMargin: widget.config.columnItemPadding,
headerBuilder: _buildHeader,