import 'package:http/http.dart' as http; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import "dart:convert"; class User { final int id; String? createdAt; String? updatedAt; String? username; String? email; bool? isVerified; User({ required this.id, this.createdAt, this.updatedAt, this.username, this.email, this.isVerified }); factory User.fromJson(Map json) { return User( id: json["ID"], createdAt: json["CreatedAt"], updatedAt: json["UpdatedAt"], username: json["Username"], email: json["Email"], isVerified: json["IsVerified"] ); } } Future userSignUp(User newUser, String password) async { final res = await http.post( Uri.parse("https://openbills.vidhukant.com/api/auth/signup"), headers: { "Content-Type": "application/json; charset=UTF-8", }, body: jsonEncode( { "Username": newUser.username as String, "Password": password, "Email": newUser.email as String, }), ); final json = jsonDecode(res.body); if (res.statusCode != 200) { switch(res.statusCode) { case 404: throw "This user does not exist"; case 500: throw "Internal Server Error"; default: throw json["error"]; } } return User.fromJson(json["data"]); }