rook_users 0.0.1 copy "rook_users: ^0.0.1" to clipboard
rook_users: ^0.0.1 copied to clipboard

Register your users in our API solutions.

Rook Users #

This package allows apps to register their users in our API solutions.

Features #

  • Register users in Health Connect

Getting started #

To get permission of usage you'll need to install and configure the rook-auth package.

This package requires flutter 3.3.0 or higher.

Android configuration #

In your build.gradle (app) set your min and target sdk version like below:

minSdk 26
targetSdk 33

Logging #

If you want to see the logs generated by this package

Install the logger package:

logging: ">=1.0.0 <2.0.0"

Add the following snippet in your main() function:

void main() {
  Logger.root.level = Level.ALL;
  Logger.root.onRecord.listen((record) {
    if (kDebugMode) {
      print('${record.level.name}: ${record.time}: ${record.message}');
    }
  });

  runApp(RookApp());
}

Usage #

Import rook_users:

import 'package:rook_users/rook_users.dart';

Create an instance of RookUsersManager providing an apiUrl


final RookUsersManager manager = RookUsersManager(
  'API_URL',
);

Registering users #

To register a user call registerRookUser providing your clientUUID, a userID and a userType. It will return an instance of RookUser. After a successful registration it will store a RookUser instance in preferences so the next time you call registerRookUser the local value will be returned. Unless you provide a different userID, in that case it will behave like the first time.

The userID is defined by you, so feel free to use the same ID your app uses to identify it's users. If you provide an ID which is already exists in the server it will only store it in preferences.

The userType determines where the user will be created. E.g. if you want to create a user for Health Connect pass UserType.healthConnect:

void register() async {
  try {
    await Future.delayed(const Duration(seconds: 1));

    final user = await manager.registerRookUser(
      clientUUID,
      userID,
      UserType.healthConnect,
    );

    // Manage RookUser instance.
  } catch (e) {
    // Manage error
  }
}
  • Before calling registerRookUser we recommend to wait somewhere in between 1 - 3 seconds, so the package loads all necessary resources.

Removing registered users from preferences #

This package already manages the case were you need to register a different userID (the new userID will replace the previous one in preferences).

If you want to manually remove a userID call removeUserFromPreferences and provide the type of user you want to remove it will return a boolean indicating if the operation was successful.

void remove() async {
  try {
    final success = await manager.removeUserFromPreferences(UserType.healthConnect);
  } catch (e) {
    // Manage error
  }
}
  • removeUserFromPreferences will only delete from local storage, the user will remain registered on server.

Additional information #

The first time your users use this package they MUST have an active internet connection otherwise the request will fail and the userID won't be registered or stored.

RookUser instances are stored in device's shared preferences, if your app is also using shared preferences keep in mind that calling clear on the SharedPreferences instance will also delete this package registries.

0
likes
0
pub points
21%
popularity

Publisher

verified publisherrook-connect.com

Register your users in our API solutions.

Homepage

License

unknown (LICENSE)

Dependencies

flutter, http, logging, rook_auth, shared_preferences

More

Packages that depend on rook_users