dartrosa_openrosa

pub package pub points CI License: Apache-2.0

An OpenRosa server client for DartRosa (ODK Central, KoboToolbox and other OpenRosa servers). A port of ODK Collect's open-rosa module and its OpenRosa instance uploader, over package:http, so it works on the VM, in Flutter and on the web.

  • OpenRosaClient: form list, manifests, form and media downloads, entity list integrity checks.
  • OpenRosaInstanceUploader: multipart/form-data submission with xml_submission_file, split to respect the server's X-OpenRosa-Accept-Content-Length.
  • HttpClientConnection: Collect's headers and Digest/Basic authentication; WebCredentialsUtils chooses the credentials.
  • InstanceUpload.forForm turns a FormSession submission into an upload, encrypting it (with dartrosa_encryption) when the form asks.

Install

dart pub add dartrosa_openrosa

Example

import 'package:dartrosa_openrosa/dartrosa_openrosa.dart';
import 'package:http/http.dart' as http;

Future<void> main() async {
  const serverUrl = 'https://central.example.org/v1/key/TOKEN/projects/1';
  final connection = HttpClientConnection(
    client: http.Client(),
    fileToContentTypeMapper: CollectThenSystemContentTypeMapper(),
    userAgent: 'my-app/1.0',
  );
  final credentials = WebCredentialsUtils(
    InMemoryServerCredentialsSettings(serverUrl: serverUrl),
  );
  final client = OpenRosaClient(
    serverUrl,
    connection,
    credentials,
    deviceId: 'my-app:device-1',
  );
  for (final form in await client.fetchFormList()) {
    print('${form.formId} ${form.version}: ${form.downloadUrl}');
  }

  // Uploading a finalized FormSession submission:
  // final uploader = OpenRosaInstanceUploader(connection, credentials);
  // await uploader.uploadOneSubmission(
  //   InstanceUpload.forForm(definition.formDef, submission),
  //   serverUrl: serverUrl,
  //   deviceId: 'my-app:device-1',
  // );
}

example/example.dart runs the form-list fetch against a mock server.

Documentation

License

Apache License 2.0 (see LICENSE). Ports ODK Collect's open-rosa module and uploader (Apache-2.0); see the licensing notes.

Libraries

dartrosa_openrosa
An OpenRosa server client for DartRosa.