unruffled_feathersjs 1.11.0 copy "unruffled_feathersjs: ^1.11.0" to clipboard
unruffled_feathersjs: ^1.11.0 copied to clipboard

A FeathersJS client for Flutter based on unruffled

Unruffled x FeathersJS #

unruffled_feathersjs is feathersjs client for Flutter that manages offline by default.

Quick start #

1. Add to pubspec.yaml #

dependencies:
  json_annotation: ^4.5.0
  unruffled_feathersjs: ^1.5.0

dev_dependencies:
  build_runner: any
  json_serializable: ^6.2.0
  unruffled_generator: ^1.2.0

NOTE : Unruffled relies to json_annotation and json_serializable to work as expected, please ensure to add theme in your dependencies.

2. Declare models #

Declare models used by your remote service and generate Unruffled adapters.

@UnruffledFeathersJsData()
@JsonSerializable()
class User extends DataModel<User> {
  @override
  @JsonKey(name: '_id') // e.g MongoDB item has '_id' as unique identifier
  int? id;
  
  String name;
  
  String surname;
  
  int age;

  User({super.key, this.id, required this.name, required this.surname, required this.age});
}

Build your flutter directory to generate a UserAdapter()

flutter pub run build_runner build

NOTE: Your class must construct a String? key and Object? id and pass it to super();

  • id refers to your remote object ID\
  • key refers to your local object ID generated by unruffled

3. Register adapters #

For all platforms except web, use path_provider to generate a directory path.

final dir = await getApplicationSupportDirectory(); // path_provider package
var unruffled = UnruffledFeathersJs(
      baseDirectory: dir,
      defaultBaseUrl: 'http://example.com',
  )
  .registerRepository(UserRepository());

4. Initialize Unruffled #

Before using Unruffled, ensure to initialize it.

await unruffled.init();

🚀 That's it, you're ready to go !

Usage #

unruffled_feathersjs provides default authenticate & refresh token methods, override it if needed.

1. Authenticate #

 final data = {
  "email": "test@test.com",
  "password": "test123",
  "strategy": "local",
};
Map<String, dynamic> result = await unruffled.authenticate(body: data);

By default, unruffled_feathersjs use DefaultTokenStorageImpl() and manage automatically to save access token and pass it in an Authorization header. For more complex cases, you can create mixin on UnruffledFeathersJs or add Dio interceptors.

2. Other #

unruffled_feathersjs extends unruffled, for more documentation check the package unruffled

0
likes
130
points
9
downloads

Publisher

unverified uploader

Weekly Downloads

A FeathersJS client for Flutter based on unruffled

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

dio, flutter, flutter_secure_storage, get_it, json_annotation, meta, socket_io_client, unruffled

More

Packages that depend on unruffled_feathersjs