bursa_de_cereale_sdk 1.0.9 copy "bursa_de_cereale_sdk: ^1.0.9" to clipboard
bursa_de_cereale_sdk: ^1.0.9 copied to clipboard

SDK for BursaDeCereale.com API

example/lib/main.dart

// main.dart
import 'package:bursa_de_cereale_sdk/cereale_sdk.dart';

void main() async {
 final client = CerealeClient();
 try {

    // register new account
    final registerResponse = await client.register(
      phone: "+40722131559",
      userType: "buyer",
      firstName: "John",
      lastName: "Doe",
      notificationType: "sms",
    );
    print('Register response: $registerResponse');
    
    // Step 2: Verify
    final verifyResponse = await client.verify("+40722131559", code: "0000");
    print('Verify response: $verifyResponse');

   final auth = await client.login(
      '+40722111227',
      verificationCode: '0000',
      notificationType: 'whatsapp'
    );
   
   print('Token: ${auth['access_token']}');


   // upload image
   final response = await client.uploadImage('./avatar.png', 'avatar.jpg');
   final imageId = response['image_id'] as int;
   print('Uploaded image ID: $imageId');


   // Create listing
  var newListing = await client.createListing({
     'title': 'Grau Premium 2024',
     'description': 'Grau de calitate superioara, productie 2024',
     'price': 1.25,
     'quantity': 5000,
     'category': 'grau',
     'location': 'Cluj-Napoca',
     'delivery_type': 'pickup',
     'moisture': 13.5,
     'protein': 12.8,
     'hectoliter_mass': 78.0,
     'image_ids': [imageId],
     'document_ids': <int>[]
  });

  print('Created listing: ${newListing}');
  if (newListing['id'] != null) {
     final listing = await client.getListing(newListing['id']);
     print('\nListing details:');
     print(listing);
  }
   
  final listings = await client.getListings(
    search: "Premium",
    limit: 5,
    filters: {
      'category': 'grau'
    }
  );

   print('\nListings:');
   print(listings);

    // upload new document
    final doc = await client.uploadDocument('./contract.pdf', 'contract.pdf');
    print('Uploaded document:');
    print('ID: ${doc['id']}');
    print('Filename: ${doc['filename']}');
    print('URL: ${doc['url']}');

    // get my documents
    final docs = await client.getMyDocuments();
    print('\nAll documents:');
    for (var d in docs) {
      print('- ${d['filename']} (ID: ${d['id']})');
      print('  Type: ${d['file_type']}');
      print('  URL: ${d['url']}');
      print('  Created: ${d['created_at']}');
    }

    // delete document id
    await client.deleteDocument(doc['id']);
    print('\nDocument ${doc['id']} deleted');



   // Send offer to first listing
   final offerData = {
     'listing_id': listings[0]['id'],
     'quantity': 1000.0,
     'price_per_unit': listings[0]['price'] * 0.9, // 90% of listing price
     'delivery_method': 'pickup',
     'valid_until': DateTime.now().add(Duration(days: 7)).toIso8601String()
   };
   final offer = await client.createOffer(offerData);
   print('Created offer: ${offer['id']}');

   // Create order for second listing
   final orderData = {
     'listing_id': listings[1]['id'],
     'quantity': 500.0,
     'quantity_unit': 'kg',
     'delivery_method': 'pickup'
   };
   final order = await client.createOrder(orderData);
   print('Created order: ${order['id']}');


   final listings = await client.getListings(limit: 5);
   for (var listing in listings) {
     if (listing['is_favorite'] == false) {
       print('\nFound unfavorited listing ${listing["id"]}');
       
       await client.addToFavorites(listing['id']);
       print('Added to favorites');
       
       var favorites = await client.getFavorites();
       print('Favorites after adding: ${favorites.map((f) => f["id"]).toList()}');

       await client.removeFromFavorites(listing['id']);
       print('Removed from favorites');
       
       favorites = await client.getFavorites();
       print('Favorites after removing: ${favorites.map((f) => f["id"]).toList()}');
     }
   }
 } catch (e) {
   print('Error: $e');
 }
}
0
likes
115
points
292
downloads

Publisher

unverified uploader

Weekly Downloads

SDK for BursaDeCereale.com API

Homepage

Documentation

API reference

License

unknown (license)

Dependencies

flutter_secure_storage, http, http_parser, image

More

Packages that depend on bursa_de_cereale_sdk