onKey method
Implementation
@override
bool onKey(KeyEvent event, RenderContext ctx) {
// We don't know viewport size here; use a generous default that gets
// clamped on render. Storage is intentionally a count, not pixel.
const page = 10;
switch (event.key) {
case NamedKey.arrowDown:
state.offsetY += 1;
return true;
case NamedKey.arrowUp:
if (state.offsetY > 0) state.offsetY -= 1;
return true;
case NamedKey.pageDown:
state.offsetY += page;
return true;
case NamedKey.pageUp:
state.offsetY = (state.offsetY - page).clamp(0, contentHeight);
return true;
case NamedKey.home:
state.offsetY = 0;
if (horizontal) state.offsetX = 0;
return true;
case NamedKey.end:
state.offsetY = contentHeight;
return true;
case NamedKey.arrowLeft:
if (horizontal && state.offsetX > 0) state.offsetX -= 1;
return horizontal;
case NamedKey.arrowRight:
if (horizontal) state.offsetX += 1;
return horizontal;
default:
return false;
}
}