I am trying to recreate the navigational function from excel in Flutter Paginated table which allows you to move down multiple rows by holding enter. The table below:
Each cell has a button that when clicked replaces the button cell with either a TextFormField or a DropdownMenuButton as seen in the code below. I also change the focus node to the next column when a selection is made:
@override
Widget build(BuildContext context) {
RegisterProvider registerProvider = Provider.of<RegisterProvider>(context);
LineItem item = widget.item;
int index = item.index!;
// Show the dropdown if this index is selected and return the dropdown button:
if (registerProvider.selectedIndex == index &&
registerProvider.selectedColumn == RegisterProvider.typeColumn) {
// Get the focus node for the corresponding cell:
FocusNode node =
registerProvider.focusNodes[RegisterProvider.typeColumn]![index];
// Returns the dropdown to selected the type:
return DropdownButton<String>(
focusNode: node,
value: item.type,
items: LineItem.types.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
onChanged: (newType) {
// print("Changed type");
// bool res = registerProvider.changeIsDisabled();
if (newType != null) {
// Update the selected type:
item.type = newType;
// The list of possible charges for the selected type:
List<String> chargeSelection =
LineItem.correspondingcharges[newType]!;
// Set the charge as the first charge:
item.charge = chargeSelection.first;
// Set the pressure test:
item.setWorkingPressure();
// Determine if the new charge selection has only one value there is no need to move to the charge column:
if (chargeSelection.length == 1) {
// Update the selected column:
registerProvider.selectedColumn = RegisterProvider.signageColumn;
// This puts the cursor in the next dropdown button:
registerProvider.focusNodes[registerProvider.selectedColumn]
?[index]
.requestFocus();
registerProvider.refresh();
} else {
// Update the selected column:
registerProvider.selectedColumn = RegisterProvider.chargeColumn;
registerProvider.refresh();
// This puts the cursor in the next dropdownbutton input:
registerProvider.focusNodes[RegisterProvider.chargeColumn]![index]
.requestFocus();
}
}
},
);
}
return InkWell(
child: Padding(
padding: const EdgeInsets.all(8.0),
// Space to make the selection bigger:
child: Text(
item.type ?? 'Choose Type',
style: TextStyle(color: item.type == null ? Colors.red : null),
),
),
onTap: () {
// Update the selected index:
registerProvider.selectedIndex = index;
// Update the selected column:
registerProvider.selectedColumn = RegisterProvider.typeColumn;
// Refresh the page:
registerProvider.refresh();
// This puts the cursor in the text field input:
registerProvider.focusNodes[RegisterProvider.typeColumn]?[index]
.requestFocus();
},
);
}
I am trying to recreate the excel feature that allows the user to move down multiple rows by holding enter. When I try to hold enter I get this error:
══╡ EXCEPTION CAUGHT BY SERVICES LIBRARY ╞══════════════════════════════════════════════════════════ The following assertion was thrown while processing the key message handler: Assertion failed: file:///C:/src/flutter/packages/flutter/lib/src/material/dropdown.dart:1339:12 _dropdownRoute == null is not true
When the exception was thrown, this was the stack: dart-sdk/lib/internal/js_dev_runtime/private/ddc_runtime/errors.dart 294:3 throw dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 35:3 assertFailed packages/flutter/src/material/dropdown.dart 1339:27 [_handleTap] packages/flutter/src/material/ink_well.dart 845:21
activateOnIntent packages/flutter/src/widgets/actions.dart 597:39
invoke packages/flutter/src/widgets/actions.dart 338:16
[_invoke] packages/flutter/src/widgets/actions.dart 666:27
invokeActionIfEnabled packages/flutter/src/widgets/shortcuts.dart 851:81 handleKeypress packages/flutter/src/widgets/shortcuts.dart 1042:20
[_handleOnKey] ...
How can I prevent the dropdown from being selected if enter is held down?
