In Syncfusion Flutter DataGrid how can I listen to keyboard events in mobile

232 Views Asked by At

I want to move to next cell on same row while editing inside a SfDataGrid, so I follow How to move to next cell example here.

So I define my own EditorGridSelectionManager like this:

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:logging/logging.dart';
import 'package:syncfusion_flutter_datagrid/datagrid.dart';
import 'package:flutter/foundation.dart';

class EditorGridSelectionManager extends RowSelectionManager {
  final DataGridController dataGridController;
  Logger _logger=Logger('EditorGridSelectionManager');
  
  EditorGridSelectionManager({this.dataGridController});
  
  @override
  void handleKeyEvent(RawKeyEvent keyEvent) async {
    if (keyEvent.logicalKey == LogicalKeyboardKey.tab) {
      WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
        dataGridController.beginEdit(dataGridController.currentCell);
      });
    }
    if(keyEvent.logicalKey == LogicalKeyboardKey.f2){
      WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
        dataGridController.beginEdit(dataGridController.currentCell);
      });
    }
    if(defaultTargetPlatform==TargetPlatform.android || defaultTargetPlatform==TargetPlatform.iOS){
      _logger.info('Estoy en Mobile');
      if(keyEvent.logicalKey == LogicalKeyboardKey.arrowDown){
        _logger.info('Presione Next');
        WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
          dataGridController.beginEdit(dataGridController.currentCell);
        });
      }
    }
    super.handleKeyEvent(keyEvent);
  }
}

And I also activate the next button on virtual keyboard for mobile by defining textInputAction, you can see a snipped of the textField code below:

   return TextField(
        controller: controller,
        onChanged: this.onValueChanged,
        onSubmitted: this.onSubmitted,
        maxLength: length,
        keyboardType: this.textInputType,
        textCapitalization: TextCapitalization.sentences,
        textInputAction: TextInputAction.next,
        inputFormatters: _buildInputFormatter(),
       focusNode: this._focusNode,
        decoration: InputDecoration(
          border: InputBorder.none,
          contentPadding: EdgeInsets.only(top: 14.0),
          errorText: snapshot.error,
          errorStyle: TextStyle(color: Colors.red, fontWeight: FontWeight.bold),
          //hintText: textHint!=null ? textHint : 'Inform '+label
        ),
       );

I also did what the example tells about setting the RowSelectionManager on the definition of the SfDataGrid and returning the editing widget from the DataSource. The question is that everything works fine on Web, when I press tab key it moves to editing next cell. But on mobile it doesn't work at all, I mean when I press next button of the virtual keyboard on my phone it do nothing, and it seems never gets into the EditorGridSelectionManger.handlerKeyEvent at all.

Any ideas of what I am doing wrong?

0

There are 0 best solutions below