A comprehensive Flutter example app showcasing the Appwrite Generator package with a fully-functional to-do list application featuring 5 interconnected database tables.
This example demonstrates how to use the Appwrite Generator to create type-safe, production-ready Dart models from Appwrite database schemas. The app showcases:
- ✅ 5 Database Tables with relationships
- ✅ Enum Types for priority and status
- ✅ DateTime Fields for tracking and due dates
- ✅ Many-to-Many Relationships (todos ↔ tags)
- ✅ One-to-Many Relationships (projects → todos, todos → comments)
- ✅ Type-Safe Attribute Constants
- ✅ Null-Safety based on required flags
Organize todos into workspaces
title(string, required)description(string, optional)color(string, required) - Hex color codeicon(string, optional)status(enum, required) -active,archived,completedcreated_at,updated_at(datetime, required)
Individual task items
title(string, required)description(string, optional)project_id(string, required) - Foreign key to projectspriority(enum, required) -low,medium,high,urgentstatus(enum, required) -todo,in_progress,blocked,donedue_date,completed_at(datetime, optional)estimated_hours(integer, optional)created_at,updated_at(datetime, required)
Labels for categorization
name(string, required, unique)color(string, required) - Hex color codecreated_at(datetime, required)
Many-to-many junction table
todo_id(string, required)tag_id(string, required)created_at(datetime, required)- Unique constraint on (
todo_id,tag_id)
Discussion threads on tasks
todo_id(string, required) - Foreign key to todoscontent(string, required)author_name(string, optional)created_at,updated_at(datetime, required)
The generator creates the following files for each table:
lib/models/
├── models.dart # Barrel export file
├── projects/
│ ├── project.dart # Main model with fromJson, toJson, copyWith
│ ├── project_enums.dart # Status enum
│ └── project_attributes.dart # Type-safe attribute constants
├── todos/
│ ├── todo.dart
│ ├── todo_enums.dart # Priority and Status enums
│ └── todo_attributes.dart
├── tags/
│ ├── tag.dart
│ └── tag_attributes.dart
├── todo_tags/
│ ├── todo_tag.dart
│ └── todo_tag_attributes.dart
└── comments/
├── comment.dart
└── comment_attributes.dart
import 'package:example/models/models.dart';
import 'package:example/models/todos/todo_enums.dart';
final todo = Todo(
title: 'Review Appwrite Documentation',
description: 'Go through all features',
projectId: 'project_123',
priority: Priority.high,
status: Status.todo,
dueDate: DateTime.now().add(Duration(days: 7)),
estimatedHours: 5,
createdAt: DateTime.now(),
updatedAt: DateTime.now(),
);
// Convert to JSON for Appwrite
final json = todo.toJson();
// Parse from Appwrite response
final parsedTodo = Todo.fromJson(json);import 'package:example/models/todos/todo_attributes.dart';
// Use constants instead of magic strings
final query = [
Query.equal(TodoAttributes.status, 'todo'),
Query.lessThan(TodoAttributes.dueDate, DateTime.now().toIso8601String()),
];import 'package:example/models/todos/todo_enums.dart';
// Type-safe enum usage
final priority = Priority.urgent;
print(priority.value); // 'urgent'
// Parse from string (from Appwrite)
final status = Status.fromString('in_progress');
print(status); // Status.inProgress// Use the generated copyWith method
final updatedTodo = todo.copyWith(
status: Status.done,
completedAt: DateTime.now(),
);-
Install dependencies:
flutter pub get
-
Run the app:
flutter run
-
Explore the features:
- Navigate between projects using the drawer
- View tasks with different priorities and statuses
- Check task details including comments
- See overdue indicators
- Browse all tags
If you modify the appwrite.json schema:
# From the example directory
dart run ../bin/appwrite_generator.dart generate --input appwrite.json --output lib/modelsOr use the configuration file approach:
# Create appwrite_generator.yaml
cat > appwrite_generator.yaml << EOF
input: appwrite.json
output: lib/models
clean: true
model_prefix: ''
EOF
# Generate models
dart run ../bin/appwrite_generator.dart generateTo connect this example to an actual Appwrite instance:
-
Update
appwrite.jsonwith your project details:{ "projectId": "your-project-id", "endpoint": "https://cloud.appwrite.io/v1" } -
Initialize the Appwrite client in
main.dart:import 'package:appwrite/appwrite.dart'; final client = Client() .setEndpoint('https://cloud.appwrite.io/v1') .setProject('your-project-id'); final databases = Databases(client);
-
Use the generated models with Appwrite SDK:
// Create a document final response = await databases.createDocument( databaseId: 'todo_db', collectionId: 'todos', documentId: ID.unique(), data: todo.toJson(), ); // Parse the response final savedTodo = Todo.fromJson(response.data);
- Type Safety: All models are strongly typed with null-safety
- Enums: Automatic enum generation for constrained string fields
- Attributes: Constants for all column names to avoid typos
- Relationships: Proper modeling of foreign keys and junction tables
- DateTime Handling: Automatic parsing of ISO 8601 datetime strings
- JSON Serialization: Built-in
fromJsonandtoJsonmethods - Immutability:
copyWithmethod for updating immutable models
- Add authentication (user login/logout)
- Implement real CRUD operations with Appwrite SDK
- Add real-time subscriptions for live updates
- Implement the tag filtering functionality
- Add search and filter capabilities
- Export data to different formats
This example is part of the appwrite_generator package and follows the same license.