auth_service.dart
The following ArgumentError was thrown resolving an I/flutter (11774): Invalid argument(s): No host specified in URI
This my Code pleaseeeeeeeee help meeee
class AuthService {
String baseUrl = 'http://shamo-backend.buildwithangga.id/api';
Future<UserModel?> register({
required String name,
required String username,
required String email,
required String password,
}) async {
// ignore: unused_local_variable
var url = '$baseUrl/register';
var header = {'Content-Type': 'application/json'};
var body = jsonEncode({
'name': name,
'username': username,
'email': email,
'password': password,
});
var response = await http.post(
Uri(),
headers: header,
body: body,
);
print(response.body);
if (response.statusCode == 200) {
var data = jsonDecode(response.body)['data'];
UserModel user = UserModel.fromJson(data['user']);
// ignore: prefer_interpolation_to_compose_strings
user.token = 'Bearer ' + data['access_token'];
return user;
} else {
throw Exception('Gagal Register');
}
}
}
Iwant save like this enter image description here
Please Helpme
2
Answers
You are not passing any url in http.post. Replace
With
Refer this documentation for detail information
Use it like this to resove this issue