registerUserToKruzr method
Registers a new user with the Kruzr platform.
Creates a new user account in the Kruzr system with the provided details. This is typically the first step after SDK initialization for new users.
Parameters:
driverId: Unique identifier for the driver (required)name: Full name of the user (optional)countryCode: Country code for phone number (optional, e.g., "+1")phoneNumber: User's phone number (optional)email: User's email address (optional)dateOfBirth: User's date of birth in string format (optional)
Returns:
int: The newly created user ID from the Kruzr system
Usage:
try {
final userId = await communicator.registerUserToKruzr(
driverId: 'unique_driver_123',
name: 'John Doe',
countryCode: '+1',
phoneNumber: '1234567890',
email: 'john.doe@example.com',
dateOfBirth: '1990-01-01',
);
print('User registered with ID: $userId');
} catch (e) {
print('Registration failed: $e');
}
Throws:
Future.error("Unable to register user"): When registration fails
Important Notes:
driverIdmust be unique across your application- Company name is automatically included from the constructor
- Optional fields can be updated later through other methods
Implementation
Future<int> registerUserToKruzr({
required String driverId,
String? name,
String? countryCode,
String? phoneNumber,
String? email,
String? dateOfBirth,
String? referralCode,
}) async {
int newUserId;
try {
RegisterUserRequestModel registerUserRequestModel =
RegisterUserRequestModel(
driverId: driverId,
name: name,
companyName: companyName,
countryCode: countryCode,
phoneNumber: phoneNumber,
email: email,
dateOfBirth: dateOfBirth,
referralCode: referralCode,
);
newUserId = await kruzr_comm.registerUser(registerUserRequestModel);
return newUserId;
} on PlatformException catch (e) {
if (kDebugMode) {
print(e);
print("PlatformException in registerUser");
}
return Future.error("Unable to register user");
} on Exception catch (e) {
if (kDebugMode) {
print(e);
print("Exception in registerUser");
}
return Future.error("Unable to register user");
}
}