afrihex 0.1.0
afrihex: ^0.1.0 copied to clipboard
The AfriHex API for Dart and Flutter: GhanaPostGPS codes, landmark directions, routing, delivery tracking, cash on delivery and pricing for Ghana.
example/example.dart
// Run: AFRIHEX_API_KEY=afx_test_… dart run example/example.dart
import 'dart:io';
import 'package:afrihex/afrihex.dart';
Future<void> main() async {
final afx = AfriHex(apiKey: Platform.environment['AFRIHEX_API_KEY']!);
// A GhanaPostGPS code, typed any way.
final home = await afx.addresses.lookup('ga1838164');
print('${home.gpsName}: ${home.street}, ${home.area}');
// Directions a rider can follow, for any point.
final shop = await afx.addresses.reverse(5.6319, -0.1400, descriptors: true);
print(shop.directions); // Opposite Nick Petroleum filling station, Gbatsuna
// The way customers really give addresses.
final found = await afx.addresses.suggest('adjacent goil filling station, madina zongo junction');
final address = await afx.addresses.complete(found.first.address);
print('${address.label} → ${address.gpsCode}, ${address.directions}');
// Price the delivery from your fee rulebook (server side, with your secret key).
final quote = await afx.delivery.quote(DeliveryQuoteRequest(
pickup: RouteEndpoint(point: shop.point),
dropoff: RouteEndpoint(point: address.point),
));
print('Delivery fee: ${quote.currency} ${quote.amount}');
afx.close();
}