rook_users 0.1.0 rook_users: ^0.1.0 copied to clipboard
Register your users in our API solutions.
Rook Users package #
This package allows clients to register their Users in ROOK server.
Features #
- Register users in Health Connect
Installation #
flutter pub add rook_users
This package requires flutter 3.3.0
or higher.
Getting started #
To get authorization to use this package, you'll need to install and configure the rook-auth package.
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 logging 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:
- A Context
- An apiURL without HTTPS.
- A clientUUID
- A clientPassword
final RookUsersManager manager = RookUsersManager(
'api.rook-connect.dev',
clientUUID,
clientPassword,
);
Registering users #
To register a user call registerRookUser
providing 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 use UserType.HEALTH_CONNECT
:
void register() async {
try {
await Future.delayed(const Duration(seconds: 1));
final user = await manager.registerRookUser(
clientUUID,
userID,
UserType.healthConnect,
);
// Success
} 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.