@@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
66import 'package:flutter_bloc/flutter_bloc.dart' ;
77
88import 'board_cell.dart' ;
9+ import 'define.dart' ;
910
1011class BoardTextCell extends StatefulWidget with EditableCell {
1112 final String groupId;
@@ -29,6 +30,7 @@ class BoardTextCell extends StatefulWidget with EditableCell {
2930class _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