Getting Started
This guide will help you get started with DRFT and create your first resource stack.
Add DRFT to Your Project
Add DRFT to your pubspec.yaml:
dependencies:
drft: ^0.1.0
Then install dependencies:
dart pub get
1. Create a Stack
import 'package:drft/drft.dart';
void main() async {
final stack = DrftStack(
name: 'my-first-stack',
providers: [
MockProvider(), // For testing
],
resources: [
// We'll add resources here
],
);
}
2. Define a Resource
For now, let's use a simple test resource. In a real scenario, you'd use resources from providers like Firebase, AWS, etc.
final stack = DrftStack(
name: 'my-first-stack',
providers: [MockProvider()],
resources: [
TestResource(
id: 'my-resource',
name: 'Hello DRFT',
),
],
);
3. Plan Changes
Before applying changes, always plan first to see what will happen:
final plan = await stack.plan();
print(plan.summary);
This will show you what operations DRFT will perform (create, update, or delete).
4. Apply Changes
Once you're happy with the plan, apply it:
final result = await stack.apply(plan);
print(result.summary);
Understanding the Workflow
DRFT follows a simple workflow:
- Define your desired resources in code
- Plan to see what changes will be made
- Apply to execute the changes
- State is automatically tracked
Next Steps
- Check out Examples for more complex scenarios
- Learn about Resources and Providers
- Read the Architecture guide to understand how DRFT works
View Current State
final state = await stack.stateManager.load();
print('Current resources: ${state.resources.length}');
Destroy Resources
To remove all resources:
final plan = await stack.plan();
// Filter for delete operations if needed
await stack.apply(plan);
State File Not Found
If you see errors about state files, DRFT will create them automatically. Make sure you have write permissions in your project directory.
Provider Not Found
Ensure you've added the correct provider to your stack and that it's properly configured.
Resources Not Updating
Check that your resource definitions match the actual state. Use refresh() to sync state.
Getting Help
- Check the Examples for common patterns
- Review the Architecture documentation
- Open an issue on GitHub