feature top-level property

FeatureDescriptor feature
final

Implementation

final feature = FeatureDescriptor(
  name: 'system',
  title: 'System',
  description: 'The core building blocks of the framework',
  icon: Icons.hub,
  init: () async {
    vyuh.di.register(ThemeService());
    vyuh.di.register(BreakpointService());
  },
  routes: () => [
    GoRoute(
      path: '/__system_error__',
      pageBuilder: (context, state) {
        final exception = state.extra as (dynamic, StackTrace);

        return MaterialPage(
          child: vyuh.widgetBuilder.routeErrorView(
            context,
            title: 'System error',
            error: exception.$1.toString(),
            stackTrace: exception.$2,
          ),
        );
      },
    ),
    GoRoute(
      path: '/__system_navigate__',
      pageBuilder: (context, state) {
        switch (state.extra) {
          case Uri():
            return MaterialPage(child: WebView(uri: state.extra as Uri));
        }

        return const MaterialPage(
          child: Scaffold(body: Center(child: Text('No route'))),
        );
      },
    ),
  ],
  extensions: [
    ContentExtensionDescriptor(
      contents: [
        RouteDescriptor(routeTypes: [
          PageRouteType.typeDescriptor,
          DialogRouteType.typeDescriptor,
        ], layouts: [
          DefaultRouteLayout.typeDescriptor,
          TabsRouteLayout.typeDescriptor,
          SingleItemLayout.typeDescriptor,
          RouteConditionalLayout.typeDescriptor,
        ]),
        CardDescriptor(layouts: [
          DefaultCardLayout.typeDescriptor,
          ListItemCardLayout.typeDescriptor,
          ButtonCardLayout.typeDescriptor,
          CardConditionalLayout.typeDescriptor,
        ]),
        GroupDescriptor(layouts: [
          CarouselGroupLayout.typeDescriptor,
          GridGroupLayout.typeDescriptor,
          ListGroupLayout.typeDescriptor,
          GroupConditionalLayout.typeDescriptor,
        ]),
        ConditionalDescriptor(),
        ConditionalRouteDescriptor(),
        UnknownDescriptor(),
        EmptyDescriptor(),
        PortableTextDescriptor(
          markDefs: [
            MarkDefDescriptor(
              schemaType: 'invokeAction',
              fromJson: InvokeActionMarkDef.fromJson,
              styleBuilder: (context, def, style) {
                final theme = Theme.of(context);

                return style.apply(
                  decorationColor: theme.colorScheme.primary,
                  decorationStyle: TextDecorationStyle.solid,
                  decoration: TextDecoration.underline,
                  fontWeightDelta: 2,
                  shadows: [
                    Shadow(
                      color: theme.colorScheme.primary,
                      offset: const Offset(0, -2),
                    ),
                  ],
                  color: Colors.transparent,
                );
              },
              spanBuilder: (context, def, text, style) {
                return WidgetSpan(
                  child: GestureDetector(
                    onTap: () {
                      (def as InvokeActionMarkDef).action.execute(context);
                    },
                    child: Wrap(
                      crossAxisAlignment: WrapCrossAlignment.center,
                      direction: Axis.horizontal,
                      alignment: WrapAlignment.start,
                      children: [
                        Text(
                          text,
                          style: style,
                          softWrap: false,
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                          textAlign: TextAlign.left,
                        ),
                      ],
                    ),
                  ),
                );
              },
            )
          ],
          blocks: [
            BlockItemDescriptor(
              schemaType: Unknown.schemaName,
              fromJson: Unknown.fromJson,
              builder: (context, content) =>
                  vyuh.content.buildContent(context, content as Unknown),
            ),
            BlockItemDescriptor(
              schemaType: TextBlockItem.schemaName,
              fromJson: TextBlockItem.fromJson,
              builder: (_, content) =>
                  PortableTextBlock(model: content as TextBlockItem),
            ),
            BlockItemDescriptor(
              schemaType: Card.schemaName,
              fromJson: Card.fromJson,
              builder: (context, content) =>
                  vyuh.content.buildContent(context, content as Card),
            ),
            BlockItemDescriptor(
              schemaType: Group.schemaName,
              fromJson: Group.fromJson,
              builder: (context, content) =>
                  vyuh.content.buildContent(context, content as Group),
            ),
            BlockItemDescriptor(
              schemaType: Divider.schemaName,
              fromJson: Divider.fromJson,
              builder: (context, content) =>
                  vyuh.content.buildContent(context, content as Divider),
            ),
          ],
        ),
        DividerDescriptor(),
        APIContentDescriptor(
          configurations: [JsonPathApiConfiguration.typeDescriptor],
        ),
        DocumentViewDescriptor(
          layouts: [
            DocumentViewConditionalLayout.typeDescriptor,
          ],
        ),
        DocumentSectionViewDescriptor(
          layouts: [
            DocumentSectionViewConditionalLayout.typeDescriptor,
          ],
        ),
        DocumentListViewDescriptor(
          layouts: [
            DocumentListViewConditionalLayout.typeDescriptor,
          ],
        ),
      ],
      contentBuilders: [
        Route.contentBuilder,
        Card.contentBuilder,
        Group.contentBuilder,
        Conditional.contentBuilder,
        ConditionalRoute.contentBuilder,
        UnknownContentBuilder(),
        Empty.contentBuilder,
        PortableTextContent.contentBuilder,
        Divider.contentBuilder,
        Accordion.contentBuilder,
        APIContent.contentBuilder,
        VideoPlayerItem.contentBuilder,
        DocumentView.contentBuilder,
        DocumentSectionView.contentBuilder,
        DocumentListView.contentBuilder,
      ],
      conditions: [
        BooleanCondition.typeDescriptor,
        FeatureFlagCondition.typeDescriptor,
        UserAuthenticated.typeDescriptor,
        CurrentThemeMode.typeDescriptor,
        ScreenSize.typeDescriptor,
        CurrentPlatform.typeDescriptor,
      ],
      actions: [
        NavigationAction.typeDescriptor,
        NavigateBack.typeDescriptor,
        OpenUrlAction.typeDescriptor,
        OpenInDialogAction.typeDescriptor,
        ConditionalAction.typeDescriptor,
        RouteRefreshAction.typeDescriptor,
        ToggleThemeAction.typeDescriptor,
        RestartApplicationAction.typeDescriptor,
        ShowSnackBarAction.typeDescriptor,
        HideSnackBarAction.typeDescriptor,
        DrawerAction.typeDescriptor,
        ShowAlertAction.typeDescriptor,
        DelayAction.typeDescriptor,
      ],
    ),
  ],
  extensionBuilders: [
    ContentExtensionBuilder(),
  ],
);