moveFocus method
Implementation
void moveFocus(BuildContext context, bool forward) {
// FocusNode? currentFocus = FocusManager.instance.primaryFocus;
int currentIndex = -1;
_indexes.forEach((key, val) {
if (key.hasFocus) {
currentIndex = val;
}
});
if (currentIndex != -1) {
List<int> allVal = _indexes.values.toList();
if (allVal.isEmpty) return;
allVal.sort((a, b) => a.compareTo(b));
int nextVal = -1;
bool finded = false;
for (var val in allVal) {
if (currentIndex != val && max(currentIndex, val) == val && !finded) {
finded = true;
nextVal = val;
}
}
if (finded == false) {
nextVal = allVal.first;
}
FocusNode? nextFocus;
_indexes.forEach((key, val) => val == nextVal ? nextFocus = key : null);
if (nextFocus != null) {
// if (mainFocus != null) {
// mainFocus!.requestFocus(nextFocus);
// } else {
nextFocus!.requestFocus();
FocusScope.of(context).requestFocus(nextFocus);
//}
}
}
// FocusNode? secondCurrentFocus = FocusManager.instance.primaryFocus;
// var s = 3;
}