push method

Future<void> push(
  1. CarTemplate template
)

Shows template on top of the current screen, closing the alert if one is open.

Throws a StateError when there is no root yet or the stack is full (see CarLimits.maxStackDepth), and an ArgumentError when a screen with the same id is already shown.

Implementation

Future<void> push(CarTemplate template) => _serial(() {
      if (_stack.isEmpty) throw StateError('Call setRoot before push.');
      final depth = _stack.length + 1;
      if (depth > CarLimits.maxStackDepth) {
        throw StateError(
            'Cannot push "${template.title}": the car allows at most '
            '${CarLimits.maxStackDepth} screens. Pop first.');
      }
      if (depth == CarLimits.maxStackDepth && template is! CarInfoTemplate) {
        throw StateError(
            'Cannot push "${template.title}": the 5th screen must be a '
            'CarInfoTemplate, because Android Auto ends a task there.');
      }
      final encoded = encodeTemplate(template);
      if (_indexOf(encoded.id) != -1) {
        throw ArgumentError('A screen with id "${encoded.id}" is already '
            'shown. Use update to change it.');
      }
      return _change(
        () {
          _stack.add(_Shown(template, encoded));
          _alert = null;
        },
        () => _platform.push(encoded.map),
      );
    });