SDKs

Dart / Flutter

Idiomatic Dart patterns for Flutter apps and Dart server

Use the http package for simple cases or dio for interceptors and retries. http shown below — it ships with the Dart SDK out of the box for Flutter.

pubspec.yaml

dependencies:
  http: ^1.2.2

Configure

import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart' as http;

const api = 'https://openapi.thunderbit.com/openapi/v1';
final headers = <String, String>{
  'Authorization': 'Bearer ${Platform.environment['THUNDERBIT_API_KEY']}',
  'Content-Type': 'application/json',
};

Distill a page

Future<String> distill(String url) async {
  final res = await http.post(
    Uri.parse('$api/distill'),
    headers: headers,
    body: jsonEncode({'url': url}),
  );
  if (res.statusCode >= 400) throw Exception(res.body);
  final body = jsonDecode(res.body) as Map<String, dynamic>;
  return body['data']['markdown'] as String;
}

Extract structured data

Future<Map<String, dynamic>> extract(String url) async {
  final res = await http.post(
    Uri.parse('$api/extract'),
    headers: headers,
    body: jsonEncode({
      'url': url,
      'schema': {
        'type': 'object',
        'properties': {
          'name':  {'type': 'string'},
          'price': {'type': 'number'},
        },
        'required': ['name', 'price'],
      },
    }),
  );
  return (jsonDecode(res.body) as Map<String, dynamic>)['data'];
}

Flutter UI tip

Wrap calls in a FutureBuilder so the UI doesn't block — and let your Dart server (not the Flutter app) own the API key for production.

For batch jobs, submit then let your server-side webhook handler do the work. See Webhooks.

An official Dart SDK is in development — check back soon.