run method
num
run({
- required void render(
- FrameContext ctx,
- num value,
- double ratio
- KeyBindings? extraBindings,
- bool useNumberKeys = false,
- int numberKeyMax = 9,
Runs the value prompt with custom rendering.
Implementation
num run({
required void Function(FrameContext ctx, num value, double ratio) render,
KeyBindings? extraBindings,
bool useNumberKeys = false,
int numberKeyMax = 9,
}) {
_initState();
_bindings = KeyBindings.horizontalNavigation(
onLeft: () => _value = math.max(min, _value - step),
onRight: () => _value = math.min(max, _value + step),
);
if (useNumberKeys) {
_bindings = _bindings +
KeyBindings.numbers(
onNumber: (n) {
if (n >= 1 && n <= numberKeyMax) {
final normalized = (n - 1) / (numberKeyMax - 1);
_value = min + normalized * (max - min);
}
},
max: numberKeyMax,
hintLabel: '1–$numberKeyMax',
hintDescription: 'set value',
);
}
_bindings =
_bindings + KeyBindings.prompt(onCancel: () => _cancelled = true);
if (extraBindings != null) {
_bindings = _bindings + extraBindings;
}
final frame = FrameView(
title: title,
theme: theme,
bindings: _bindings,
);
void renderFrame(RenderOutput out) {
frame.render(out, (ctx) {
render(ctx, _value, ratio);
});
}
final runner = PromptRunner(hideCursor: true);
final result = runner.runWithBindings(
render: renderFrame,
bindings: _bindings,
);
return (result == PromptResult.cancelled || _cancelled) ? initial : _value;
}