pichaflow_dart 0.1.0 copy "pichaflow_dart: ^0.1.0" to clipboard
pichaflow_dart: ^0.1.0 copied to clipboard

PichaFlow SDK for Dart

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}');
}
1
likes
0
points
267
downloads

Publisher

verified publisherpichaflow.com

Weekly Downloads

PichaFlow SDK for Dart

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

crypto, http, image

More

Packages that depend on pichaflow_dart