Flutter
Uses the standard http package — add it to your pubspec.yaml:
dependencies: http: ^1.2.0VoltaClient
Section titled “VoltaClient”import 'dart:convert';import 'package:http/http.dart' as http;
class VoltaClient { final String apiUrl; final String apiKey; final String layoutId; String? _token;
VoltaClient({ required this.apiUrl, required this.apiKey, required this.layoutId, });
Map<String, String> get _keyHeaders => { 'x-api-key': apiKey, 'Content-Type': 'application/json', };
Map<String, String> get _tokenHeaders => { 'Authorization': 'Bearer $_token', 'Content-Type': 'application/json', };
// Step 1: Discover controls Future<Map<String, dynamic>> getLayoutInfo() async { final res = await http.get( Uri.parse('$apiUrl/layout/$layoutId'), headers: {'x-api-key': apiKey}, ); if (res.statusCode != 200) throw Exception('HTTP ${res.statusCode}'); return jsonDecode(res.body); }
// Step 2: Get a token Future<void> connect() async { final res = await http.post( Uri.parse('$apiUrl/token'), headers: _keyHeaders, body: jsonEncode({'layoutId': layoutId}), ); if (res.statusCode != 200) throw Exception('HTTP ${res.statusCode}'); _token = jsonDecode(res.body)['token']; }
// Step 3: Send actions Future<void> sendAction(int lid, String type, [dynamic value]) async { await http.post( Uri.parse('$apiUrl/action'), headers: _tokenHeaders, body: jsonEncode({ 'layoutId': layoutId, 'lid': lid, 'type': type, if (value != null) 'value': value, }), ); }
Future<void> sendButton(int lid) => sendAction(lid, 'Button'); Future<void> sendSlider(int lid, double value) => sendAction(lid, 'Slider', value); Future<void> sendToggle(int lid, bool value) => sendAction(lid, 'Toggle', value); Future<void> sendIndex(int lid, int value) => sendAction(lid, 'Index', value);}final client = VoltaClient( apiUrl: 'https://your-api-url.execute-api.eu-west-2.amazonaws.com', apiKey: 'your-api-key', layoutId: 'your-layout-id',);
await client.connect();final layout = await client.getLayoutInfo();
// Send interactionsawait client.sendButton(1);await client.sendSlider(2, 0.75);await client.sendIndex(3, 1);