build method

  1. @override
Widget build(
  1. BuildContext context
)
override

Build the widget.

Implementation

@override
Widget build(final BuildContext context) {
  final minValue = min;
  final maxValue = max;
  return PerformableActionsListTile(
    actions: [
      PerformableAction(
        name: 'Increase',
        activator: moveUpShortcut,
        invoke: () {
          final i = value + modifier;
          if (i <= (max ?? i)) {
            onChanged(i);
          }
        },
      ),
      PerformableAction(
        name: 'Decrease',
        activator: moveDownShortcut,
        invoke: () {
          final i = value - modifier;
          if (i >= (min ?? i)) {
            onChanged(i);
          }
        },
      ),
      if (minValue != null)
        PerformableAction(
          name: 'Set minimum',
          activator: moveToStartShortcut,
          invoke: () => onChanged(min ?? value),
        ),
      if (maxValue != null)
        PerformableAction(
          name: 'Set maximum',
          activator: moveToEndShortcut,
          invoke: () => onChanged(max ?? value),
        ),
    ],
    autofocus: autofocus,
    title: Text(title),
    subtitle: Text(subtitle ?? value.toString()),
    onTap: () => context.pushWidgetBuilder(
      (final context) => GetText(
        onDone: (final value) {
          Navigator.pop(context);
          onChanged(int.parse(value));
        },
        labelText: labelText,
        text: value.toString(),
        title: title,
        validator: (final value) {
          if (value == null || value.isEmpty) {
            return 'You must provide a value';
          }
          final i = int.tryParse(value);
          if (i == null) {
            return 'Invalid number';
          }
          if (i < (min ?? i)) {
            return 'You must use a number no less than $min';
          }
          if (i > (max ?? i)) {
            return 'You must use a number no more than $max';
          }
          return null;
        },
      ),
    ),
    onLongPress: onLongPress,
  );
}