11import 'package:app_flowy/plugins/board/application/card/board_text_cell_bloc.dart' ;
22import 'package:app_flowy/plugins/grid/application/cell/cell_service/cell_service.dart' ;
33import 'package:app_flowy/plugins/grid/presentation/widgets/cell/cell_builder.dart' ;
4+ import 'package:flowy_infra_ui/style_widget/text.dart' ;
45import 'package:flutter/material.dart' ;
56import '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 },
0 commit comments