router property

Expression get router

Get the segment router

Implementation

Expression get router {
  Expression router =
      refer('Router', 'package:spry_router/spry_router.dart').call([]);

  // Add middleware
  if (segmentDocument.middleware != null) {
    router = router.cascade('use').call([middleware!]);
  }

  // Add parameter middleware.
  for (final MapEntry<String, Reference> entry
      in paramterMiddleware.entries) {
    router = router
        .cascade('param')
        .call([literalString(entry.key, raw: true), entry.value]);
  }

  // Add all verb handler.
  if (segmentDocument.handler != null) {
    router =
        router.cascade('all').call([literalString('/', raw: true), handler!]);
  }

  // Add method handlers.
  for (final MapEntry<String, Expression> entry in methodHandlers.entries) {
    router = router.cascade('route').call([
      literalString(entry.key, raw: true),
      literalString('/', raw: true),
      entry.value,
    ]);
  }

  // Add all child routes.
  router = buildChildRoutes(router);

  return router;
}