|
@@ -7,7 +7,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
|
|
import 'cell_builder.dart';
|
|
|
|
|
|
-class NumberCell extends StatefulWidget with GridCellWidget {
|
|
|
+class NumberCell extends GridCellWidget {
|
|
|
final GridCellContextBuilder cellContextBuilder;
|
|
|
|
|
|
NumberCell({
|
|
@@ -16,13 +16,12 @@ class NumberCell extends StatefulWidget with GridCellWidget {
|
|
|
}) : super(key: key);
|
|
|
|
|
|
@override
|
|
|
- State<NumberCell> createState() => _NumberCellState();
|
|
|
+ GridFocusNodeCellState<NumberCell> createState() => _NumberCellState();
|
|
|
}
|
|
|
|
|
|
-class _NumberCellState extends State<NumberCell> {
|
|
|
+class _NumberCellState extends GridFocusNodeCellState<NumberCell> {
|
|
|
late NumberCellBloc _cellBloc;
|
|
|
late TextEditingController _controller;
|
|
|
- late SingleListenrFocusNode _focusNode;
|
|
|
Timer? _delayOperation;
|
|
|
|
|
|
@override
|
|
@@ -30,14 +29,11 @@ class _NumberCellState extends State<NumberCell> {
|
|
|
final cellContext = widget.cellContextBuilder.build();
|
|
|
_cellBloc = getIt<NumberCellBloc>(param1: cellContext)..add(const NumberCellEvent.initial());
|
|
|
_controller = TextEditingController(text: contentFromState(_cellBloc.state));
|
|
|
- _focusNode = SingleListenrFocusNode();
|
|
|
- _listenOnFocusNodeChanged();
|
|
|
super.initState();
|
|
|
}
|
|
|
|
|
|
@override
|
|
|
Widget build(BuildContext context) {
|
|
|
- _handleCellRequestFocus(context);
|
|
|
return BlocProvider.value(
|
|
|
value: _cellBloc,
|
|
|
child: MultiBlocListener(
|
|
@@ -49,8 +45,8 @@ class _NumberCellState extends State<NumberCell> {
|
|
|
],
|
|
|
child: TextField(
|
|
|
controller: _controller,
|
|
|
- focusNode: _focusNode,
|
|
|
- onEditingComplete: () => _focusNode.unfocus(),
|
|
|
+ focusNode: focusNode,
|
|
|
+ onEditingComplete: () => focusNode.unfocus(),
|
|
|
maxLines: null,
|
|
|
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500),
|
|
|
decoration: const InputDecoration(
|
|
@@ -65,20 +61,12 @@ class _NumberCellState extends State<NumberCell> {
|
|
|
|
|
|
@override
|
|
|
Future<void> dispose() async {
|
|
|
- widget.requestBeginFocus.removeAllListener();
|
|
|
_delayOperation?.cancel();
|
|
|
_cellBloc.close();
|
|
|
- _focusNode.removeAllListener();
|
|
|
- _focusNode.dispose();
|
|
|
super.dispose();
|
|
|
}
|
|
|
|
|
|
@override
|
|
|
- void didUpdateWidget(covariant NumberCell oldWidget) {
|
|
|
- _listenOnFocusNodeChanged();
|
|
|
- super.didUpdateWidget(oldWidget);
|
|
|
- }
|
|
|
-
|
|
|
Future<void> focusChanged() async {
|
|
|
if (mounted) {
|
|
|
_delayOperation?.cancel();
|
|
@@ -90,22 +78,6 @@ class _NumberCellState extends State<NumberCell> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- void _listenOnFocusNodeChanged() {
|
|
|
- widget.isFocus.value = _focusNode.hasFocus;
|
|
|
- _focusNode.setListener(() {
|
|
|
- widget.isFocus.value = _focusNode.hasFocus;
|
|
|
- focusChanged();
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- void _handleCellRequestFocus(BuildContext context) {
|
|
|
- widget.requestBeginFocus.setListener(() {
|
|
|
- if (_focusNode.hasFocus == false && _focusNode.canRequestFocus) {
|
|
|
- FocusScope.of(context).requestFocus(_focusNode);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
String contentFromState(NumberCellState state) {
|
|
|
return state.content.fold((l) => l, (r) => "");
|
|
|
}
|