rook_users 0.5.2
rook_users: ^0.5.2 copied to clipboard
Register Health Connect and Apple Health users in ROOK servers.
example/README.md
Example with a dedicated widget #
rook_user_status.dart #
import 'package:flutter/material.dart';
import 'package:rook_users/rook_users.dart';
class RookUserStatus extends StatefulWidget {
const RookUserStatus({Key? key}) : super(key: key);
@override
State<RookUserStatus> createState() => _RookUserStatusState();
}
class _RookUserStatusState extends State<RookUserStatus> {
final RookUsersManager manager = RookUsersManager(
Secrets.rookUrl,
Secrets.clientUUID,
Secrets.secretKey,
);
bool loading = false;
bool registered = false;
RookUser? rookUser;
String? error;
@override
void initState() {
initialize();
super.initState();
}
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(10),
alignment: Alignment.center,
child: loading
? const CircularProgressIndicator()
: Column(
children: [
if (registered)
Row(
children: [
const Icon(Icons.verified_rounded),
const SizedBox(width: 10),
Expanded(
child: Text(
'${rookUser?.type.name.toUpperCase()} USER: ${rookUser?.id} is registered!',
),
),
],
),
if (!registered) Text('Error: $error'),
if (!registered) const SizedBox(height: 20),
if (!registered)
ElevatedButton(
onPressed: initialize,
child: const Text('Try again'),
),
],
),
);
}
void initialize() async {
setState(() => loading = true);
try {
await Future.delayed(const Duration(seconds: 1));
final user = await manager.registerRookUser(
Secrets.userID,
UserType.healthConnect,
);
setState(() {
loading = false;
registered = true;
rookUser = user;
error = null;
});
} catch (e) {
setState(() {
loading = false;
registered = false;
error = 'Error: $e';
});
}
}
}
Example with demo app #
-
Download the project from our repository.
-
In the lib folder create a secrets.dart file with a Secrets class and add the following constants:
class Secrets {
static String rookAuthUrl = 'rookAuthUrl';
static String userID = 'userID';
static String clientUUID = 'clientUUID';
static String secretKey = 'secretKey';
static String rookUrl = 'rookUrl';
}
userIDis defined by you, so feel free to use the same ID your app uses to identify it's users.
- Run
flutter pub get