Skip to main content

skill3th_core 0.1.2 copy "skill3th_core: ^0.1.2" to clipboard
skill3th_core: ^0.1.2 copied to clipboard

Flutter client for the Skill3 API: verify a site by domain, sign in users with automatic token refresh, and call any endpoint.

skill3th_core #

Flutter client for the Skill3 API: verify a site by its domain, sign users in with automatic token refresh, and call any endpoint.

Install #

dependencies:
  skill3th_core: ^0.1.2

Getting started #

Create one client for the whole app and share it.

import 'package:skill3th_core/skill3th_core.dart';

final skill3 = createSkill3(
  const Skill3Config(
    scope: Skill3Scope.organ,
    environment: Skill3Environment(
      apiUrl: 'https://api.example.com',
      defaultDomain: 'app.example.com',
    ),
  ),
);

await skill3.site.authDomain('app.example.com');

The library does not read .env itself. Read the values in your app and pass them through Skill3Config.

A runnable outline is in example/example.dart.

Sign in #

final user = await skill3.auth.signInWithEmail('a@example.com', 'password');

final stream = await skill3.auth.subscribeUser(); // emits the current value first
stream.listen((user) => print(user == null ? 'signed out' : 'signed in'));

await skill3.auth.updateUser(); // reload the profile
await skill3.auth.signOut();    // clears the local session even when offline

When a token expires, the library renews it and retries the request once.

Calling the API #

final fetch = skill3.custom.fetch;

final Skill3List list = await fetch.get(
  'land/areas',
  query: {'limit': 20},
  include: {'status': true},
);
print('${list.data} / ${list.total}');

final item = await fetch.get('land/areas', single: true, index: 7);

final res = await fetch.post('land/areas', data: {'name': 'a'});
print(res.status);

await fetch.post(
  'land/areas/7/images',
  data: {'userfiles': File(path)},
  file: true,
);

File from dart:io works on mobile and desktop only. On web, use Skill3File, which takes bytes and works on every platform.

final picked = await FilePicker.platform.pickFiles(withData: true); // your app's file_picker package
final file = picked!.files.single;

await fetch.post(
  'land/areas/7/images',
  data: {'userfiles': Skill3File(bytes: file.bytes!, filename: file.name)},
  file: true,
);

Without contentType, the library guesses it from the extension of filename. The whole file stays in memory until the upload finishes.

method result
get Skill3List (data, total, headers)
get with single: true body
post, put, delete Skill3Response (status, headers, body, url)

204 is not an error: you get an empty list, or a null body.

Errors #

try {
  await fetch.get('land/areas');
} on Skill3HttpError catch (err) {
  if (err.status == 0) {
    // no response: NO_CONNECTION, REQUEST_TIMEOUT, SITE_NOT_READY
  }
  print(errorCode(err));
}

Storing the session elsewhere #

Implement StorageProvider (get, set, remove) and pass it through Skill3Config.storage. The default is SharedPreferences, which is not encrypted.

Documentation #

The migration guide from 0.0.x and the architecture notes are in the project repository, at docs/migration/0.0.x-to-0.1.md and docs/ARCHITECTURE.md.

0
likes
160
points
921
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Flutter client for the Skill3 API: verify a site by domain, sign in users with automatic token refresh, and call any endpoint.

Homepage

License

MIT (license)

Dependencies

flutter, http, mime, shared_preferences

More

Packages that depend on skill3th_core