register method Null safety

Future<void> register(
  1. {required String username,
  2. required String email,
  3. required String password}
)

Creates a new Pindo account Returns the url to the user's profile

Implementation

Future<void> register({
  required String username,
  required String email,
  required String password,
}) async {
  final uri = Uri.https(authority, '/users/register');
  final payload = {
    'username': username,
    'email': email,
    'password': password
  };
  late Response<Map<String, dynamic>> res;
  try {
    res = await _dio.postUri(uri, data: payload);
  } on DioError catch (e, s) {
    throw PindoError(
      message: (e.response?.data as Map)['message'],
      statusCode: (e.response?.data as Map)['status'] ?? res.statusCode,
      type: e.type.valueToString,
      stackTrace: s,
    );
  } on TypeError {
    throw PindoCastingError();
  } on Exception {
    // If the exception is none of the two above, just rethrow it
    rethrow;
  }
}