dart_desk_annotation 0.1.0
dart_desk_annotation: ^0.1.0 copied to clipboard
Annotations and field definitions for the Dart Desk CMS framework.
dart_desk_annotation #
Annotations and field definitions for the Dart Desk CMS framework.
This package provides the core annotations and field configuration classes used to define CMS document types, fields, and validators. It is designed to have minimal dependencies and is suitable as a compile-time dependency.
Installation #
dart pub add dart_desk_annotation
Usage #
Annotating a CMS configuration class #
Use @CmsConfig to mark a class as a CMS configuration. This annotation is picked up by dart_desk_generator to generate CMS UI and data models.
import 'package:dart_desk_annotation/dart_desk_annotation.dart';
@CmsConfig(
title: 'Blog Post',
description: 'A blog post document type',
)
class BlogPostConfig {
// Fields are defined via CmsDocumentType
}
Defining a document type with fields #
Use CmsDocumentType to define the schema for a content type, including its fields and a preview builder.
import 'package:dart_desk_annotation/dart_desk_annotation.dart';
import 'package:flutter/widgets.dart';
final blogPostType = CmsDocumentType<BlogPost>(
name: 'blogPost',
title: 'Blog Post',
description: 'A blog post with title, body, and cover image.',
fields: [
CmsStringField(
name: 'title',
title: 'Title',
description: 'The title of the blog post',
option: CmsStringOption(),
),
CmsTextField(
name: 'body',
title: 'Body',
option: CmsTextOption(),
),
CmsImageField(
name: 'coverImage',
title: 'Cover Image',
option: CmsImageOption(),
),
CmsBooleanField(
name: 'published',
title: 'Published',
option: CmsBooleanOption(),
),
],
builder: (data) => Text(data['title'] as String? ?? ''),
);
Using validators #
CmsValidator and RequiredValidator can be attached to fields to enforce input constraints.
final validator = RequiredValidator<String>();
// validator('Title', null) returns 'Title is required'
Field types #
Primitive #
CmsStringField/CmsStringFieldConfigCmsTextField/CmsTextFieldConfigCmsNumberField/CmsNumberFieldConfigCmsBooleanField/CmsBooleanFieldConfigCmsCheckboxField/CmsCheckboxFieldConfigCmsDateField/CmsDateFieldConfigCmsDatetimeField/CmsDatetimeFieldConfigCmsUrlField/CmsUrlFieldConfig
Complex #
CmsArrayField/CmsArrayFieldConfigCmsBlockField/CmsBlockFieldConfigCmsDropdownField/CmsDropdownFieldConfigCmsGeopointField/CmsGeopointFieldConfigCmsObjectField/CmsObjectFieldConfig
Media #
CmsImageField/CmsImageFieldConfigCmsFileField/CmsFileFieldConfigCmsColorField/CmsColorFieldConfig
License #
BSD 3-Clause — see LICENSE