mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
refactor: GridCellRequestFocusNotifier only accepts single listener
This commit is contained in:
parent
371f75343c
commit
6b5126b12e
@ -57,6 +57,24 @@ abstract class GridCellWidget extends HoverWidget {
|
||||
}
|
||||
|
||||
class GridCellRequestFocusNotifier extends ChangeNotifier {
|
||||
VoidCallback? _listener;
|
||||
|
||||
@override
|
||||
void addListener(VoidCallback listener) {
|
||||
if (_listener != null) {
|
||||
removeListener(_listener!);
|
||||
}
|
||||
|
||||
_listener = listener;
|
||||
super.addListener(listener);
|
||||
}
|
||||
|
||||
void removeAllListener() {
|
||||
if (_listener != null) {
|
||||
removeListener(_listener!);
|
||||
}
|
||||
}
|
||||
|
||||
void notify() {
|
||||
notifyListeners();
|
||||
}
|
||||
|
@ -57,6 +57,7 @@ class _CheckboxCellState extends State<CheckboxCell> {
|
||||
|
||||
@override
|
||||
Future<void> dispose() async {
|
||||
widget.requestFocus.removeAllListener();
|
||||
_cellBloc.close();
|
||||
super.dispose();
|
||||
}
|
||||
|
@ -23,7 +23,6 @@ class _NumberCellState extends State<NumberCell> {
|
||||
late NumberCellBloc _cellBloc;
|
||||
late TextEditingController _controller;
|
||||
late FocusNode _focusNode;
|
||||
VoidCallback? _focusListener;
|
||||
Timer? _delayOperation;
|
||||
|
||||
@override
|
||||
@ -70,9 +69,7 @@ class _NumberCellState extends State<NumberCell> {
|
||||
|
||||
@override
|
||||
Future<void> dispose() async {
|
||||
if (_focusListener != null) {
|
||||
widget.requestFocus.removeListener(_focusListener!);
|
||||
}
|
||||
widget.requestFocus.removeAllListener();
|
||||
_delayOperation?.cancel();
|
||||
_cellBloc.close();
|
||||
_focusNode.dispose();
|
||||
@ -96,17 +93,10 @@ class _NumberCellState extends State<NumberCell> {
|
||||
}
|
||||
|
||||
void _listenCellRequestFocus(BuildContext context) {
|
||||
if (_focusListener != null) {
|
||||
widget.requestFocus.removeListener(_focusListener!);
|
||||
}
|
||||
|
||||
focusListener() {
|
||||
widget.requestFocus.addListener(() {
|
||||
if (_focusNode.hasFocus == false && _focusNode.canRequestFocus) {
|
||||
FocusScope.of(context).requestFocus(_focusNode);
|
||||
}
|
||||
}
|
||||
|
||||
_focusListener = focusListener;
|
||||
widget.requestFocus.addListener(focusListener);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -157,7 +157,6 @@ class _SelectOptionCell extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
final cellContext = cellContextBuilder.build() as GridSelectOptionCellContext;
|
||||
return Stack(
|
||||
alignment: AlignmentDirectional.center,
|
||||
fit: StackFit.expand,
|
||||
@ -166,6 +165,7 @@ class _SelectOptionCell extends StatelessWidget {
|
||||
InkWell(
|
||||
onTap: () {
|
||||
onFocus(true);
|
||||
final cellContext = cellContextBuilder.build() as GridSelectOptionCellContext;
|
||||
SelectOptionCellEditor.show(context, cellContext, () => onFocus(false));
|
||||
},
|
||||
),
|
||||
|
@ -36,7 +36,8 @@ class _GridTextCellState extends State<GridTextCell> {
|
||||
late TextCellBloc _cellBloc;
|
||||
late TextEditingController _controller;
|
||||
late FocusNode _focusNode;
|
||||
VoidCallback? _focusListener;
|
||||
|
||||
VoidCallback? _focusNodeListener;
|
||||
Timer? _delayOperation;
|
||||
|
||||
@override
|
||||
@ -87,32 +88,29 @@ class _GridTextCellState extends State<GridTextCell> {
|
||||
);
|
||||
}
|
||||
|
||||
void _listenCellRequestFocus(BuildContext context) {
|
||||
if (_focusListener != null) {
|
||||
widget.requestFocus.removeListener(_focusListener!);
|
||||
}
|
||||
|
||||
focusListener() {
|
||||
if (_focusNode.hasFocus == false && _focusNode.canRequestFocus) {
|
||||
FocusScope.of(context).requestFocus(_focusNode);
|
||||
}
|
||||
}
|
||||
|
||||
_focusListener = focusListener;
|
||||
widget.requestFocus.addListener(focusListener);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> dispose() async {
|
||||
if (_focusListener != null) {
|
||||
widget.requestFocus.removeListener(_focusListener!);
|
||||
}
|
||||
widget.requestFocus.removeAllListener();
|
||||
_delayOperation?.cancel();
|
||||
_cellBloc.close();
|
||||
_focusNode.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant GridTextCell oldWidget) {
|
||||
// TODO: implement didUpdateWidget
|
||||
super.didUpdateWidget(oldWidget);
|
||||
}
|
||||
|
||||
void _listenCellRequestFocus(BuildContext context) {
|
||||
widget.requestFocus.addListener(() {
|
||||
if (_focusNode.hasFocus == false && _focusNode.canRequestFocus) {
|
||||
FocusScope.of(context).requestFocus(_focusNode);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> focusChanged() async {
|
||||
if (mounted) {
|
||||
_delayOperation?.cancel();
|
||||
|
@ -153,7 +153,7 @@ class _RowCells extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<RowBloc, RowState>(
|
||||
buildWhen: (previous, current) => previous.cellDataMap.length != current.cellDataMap.length,
|
||||
buildWhen: (previous, current) => previous.cellDataMap != current.cellDataMap,
|
||||
builder: (context, state) {
|
||||
return IntrinsicHeight(
|
||||
child: Row(
|
||||
|
Loading…
Reference in New Issue
Block a user