I found a case here I tried to change the API to local API but when I GET the data an error occurs as shown and this happens on every page, but when I try to use the live API it's normal, why is this, before it was normal just when you want to use a local API or a live API. Thank you in advance.
and this my code:
class Constant {
// static const String baseURL = 'http://dev.api.app.asdsadsadasd.com/v1';
static const String baseURL = 'http://192.168.1.115:8080/v1';
static const String token = 'access_token';
}
and this api call:
class BiodataProvider extends ChangeNotifier {
Future<UserBiodata> getBiodata() async {
String url = Constant.baseURL;
// String _token = await UtilSharedPreferences.getToken();
//SharedPreferences _pref = await SharedPreferences.getInstance();
String token = await UtilSharedPreferences.getToken();
final response = await http.get(
Uri.parse(
'$url/auth/mhs_siakad/biodata',
),
headers: {
'Authorization': 'Bearer $token',
},
);
print(response.statusCode);
print(response.body);
if (response.statusCode == 200) {
return UserBiodata.fromJson(jsonDecode(response.body));
} else {
throw Exception('Token Expired!');
}
}
}
this call api in widget UI
FutureBuilder<UserBiodata>(
future: biodataProvider.getBiodata(),
builder: (context, snapshot) {
if (snapshot.hasData) {
// return Text(snapshot.data!.status);
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
'assets/images/user_prof.png',
height: 65,
),
const SizedBox(
height: 12,
),
Text(
snapshot.data!.data.name.toString(),
style: bold15,
),
const SizedBox(
height: 2,
),
Text(
snapshot.data!.data.nim,
style: regular5,
),
const SizedBox(
height: 2,
),
Text(
snapshot.data!.data.prodi,
style: regular5,
),
Text(
'IPK ${snapshot.data!.data.ipk}',
style: bold5,
), ...
