pichaflow_dart 0.1.2
pichaflow_dart: ^0.1.2 copied to clipboard
PichaFlow core Dart SDK. Provides zero-egress CDN URL generation, secure signature handshakes, on-device image optimization, and programmatic asset management.
example/pichaflow_dart_example.dart
import 'dart:io';
import 'package:pichaflow_dart/pichaflow_dart.dart';
void main() async {
// 1. Initialize PichaFlowClient
final client = PichaFlowClient(
config: PichaFlowConfig(
apiKey: 'your_api_key_here',
baseUrl: 'http://localhost:8789',
uploadUrl: 'http://localhost:8789',
fetchUrl: 'http://localhost:8789',
),
);
final List<UploadResponse> uploadedImages = [];
print('=== PichaFlow Dart SDK Example ===');
// 2. Perform Image Upload with Alt Description & Metadata
try {
final fileBytes = File('sample.png').readAsBytesSync();
final description = 'Sample upload image description';
print('Uploading image...');
final response = await client.upload(
fileBytes,
'sample.png',
options: UploadOptions(
alt: description,
directory: 'examples/dart',
tags: ['example', 'dart-sdk'],
onProgress: (progress) => print('Upload Progress: ${progress.toStringAsFixed(0)}%'),
),
);
if (response.success) {
uploadedImages.add(response);
print('Uploaded successfully! ID: ${response.id}, URL: ${response.url}, Alt: ${response.alt}');
}
} catch (e) {
print('Upload failed or file not found: $e');
}
// 3. List & Manage Uploaded Images
print('\n--- Uploaded Images List (${uploadedImages.length}) ---');
for (var image in List<UploadResponse>.from(uploadedImages)) {
print('Image ID: ${image.id} | Alt: ${image.alt} | URL: ${image.url}');
// 4. Delete Image from List & Server
print('Deleting image ID: ${image.id}...');
try {
final deleteResult = await client.deleteAsset(image.id);
if (deleteResult.success) {
uploadedImages.removeWhere((img) => img.id == image.id);
print('Successfully deleted asset: ${image.id}');
}
} catch (e) {
print('Failed to delete asset: $e');
}
}
print('\nRemaining Images count: ${uploadedImages.length}');
}