build method

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

Build a widget.

Implementation

@override
Widget build(final BuildContext context) {
  final arrowKeys = <LogicalKeyboardKey, Point<int>>{
    LogicalKeyboardKey.arrowDown: const Point(0, -1),
    LogicalKeyboardKey.arrowUp: const Point(0, 1),
    LogicalKeyboardKey.arrowLeft: const Point(-1, 0),
    LogicalKeyboardKey.arrowRight: const Point(1, 0),
  };
  final numberRow = <LogicalKeyboardKey, String>{
    LogicalKeyboardKey.digit0: '0',
    LogicalKeyboardKey.digit1: '1',
    LogicalKeyboardKey.digit2: '2',
    LogicalKeyboardKey.digit3: '3',
    LogicalKeyboardKey.digit4: '4',
    LogicalKeyboardKey.digit5: '5',
    LogicalKeyboardKey.digit6: '6',
    LogicalKeyboardKey.digit7: '7',
    LogicalKeyboardKey.digit8: '8',
    LogicalKeyboardKey.digit9: '9',
  };
  return CallbackShortcuts(
    bindings: {
      const SingleActivator(LogicalKeyboardKey.pageDown): () {
        setState(() {
          modifier = max(1, modifier - 1);
        });
      },
      const SingleActivator(LogicalKeyboardKey.pageUp): () {
        setState(() {
          modifier++;
        });
      },
      for (final MapEntry(
            key: key,
            value: adjustment,
          ) in arrowKeys.entries)
        SingleActivator(key): () {
          final x = adjustment.x * modifier;
          final y = adjustment.y * modifier;
          adjustPoint(x, y);
        },
      const SingleActivator(LogicalKeyboardKey.escape): () =>
          Navigator.pop(context),
      for (final MapEntry(key: key, value: string) in numberRow.entries)
        SingleActivator(key): () {
          if (numberString == '0' && string == '0') {
            return; // No leading zeros.
          }
          numberString = '$numberString$string';
          final number = int.parse(numberString);
          final minValue = switch (editPointPoint) {
            EditPointPoint.x => widget.minValue?.x ?? number,
            EditPointPoint.y => widget.minValue?.y ?? number,
          };
          final maxValue = switch (editPointPoint) {
            EditPointPoint.x => widget.maxValue?.x ?? number,
            EditPointPoint.y => widget.maxValue?.y ?? number,
          };
          final value = number.clamp(minValue, maxValue);
          final int x;
          final int y;
          switch (editPointPoint) {
            case EditPointPoint.x:
              x = value;
              y = point.y;
            case EditPointPoint.y:
              x = point.x;
              y = value;
          }
          point = Point(x, y);
          adjustPoint(0, 0);
        },
      const CharacterActivator('x'): () {
        numberString = '';
        editPointPoint = EditPointPoint.x;
        setState(() {});
      },
      const CharacterActivator('y'): () {
        numberString = '';
        editPointPoint = EditPointPoint.y;
        setState(() {});
      },
      const CharacterActivator(','): () {
        numberString = '';
        editPointPoint = EditPointPoint.y;
        setState(() {});
      },
    },
    child: SimpleScaffold(
      title: widget.title,
      body: ListView(
        shrinkWrap: true,
        children: [
          ListTile(
            autofocus: true,
            title: Text(widget.editorTitle),
            subtitle: Text('${point.x}, ${point.y}'),
            onTap: () {},
          ),
          ListTile(
            title: const Text('Modifier'),
            subtitle: Text('$modifier'),
            onTap: () {},
          ),
          ListTile(
            title: const Text('Number row will edit'),
            subtitle: Text(editPointPoint.name),
            onTap: () {},
          ),
        ],
      ),
    ),
  );
}