Hello everyone, I’m trying to develop a project with flutter web, but I can’t send a request to the api, it seems that the request has not been sent on the server side and I get the unexpected null value error. I tried many ways but I couldn’t solve it. I use the same services on the flutter side in my mobile application, this web project does not work on the web while the web version of the mobile application works smoothly on mobile.I don’t know if it has anything to do with it, but in the web version, unlike mobile, I use a go router. Thanks for your help
Service Code
List<JobTagsModel> jobTagsList = [];
Dio dio = Dio();
Future getJobTags() async {
try {
final response = await dio.get<dynamic>(
AppService.baseUrl.value + ServicePath.jobTags.value,
options: Options(
headers: {'Authorization': 'Bearer ${AppService.apiToken.value}'},
),
);
if (response.statusCode == HttpStatus.ok) {
jobTagsList.clear();
print("data : ${response.data}");
if (response.data is List) {
for (final element in response.data as List<dynamic>) {
final data = element as Map<String, dynamic>;
jobTagsList.add(JobTagsModel.fromJson(data));
}
return jobTagsList;
}
} else {
if (kDebugMode) {
print("Tagler Getirilemedi ${response.statusCode}");
}
}
} catch (e) {
if (kDebugMode) {
print("Tagler Getirilemedi Catch Hata: $e");
}
}
return [];
}
Json Model
import 'package:json_annotation/json_annotation.dart';
part 'job_tags_model.g.dart';
@JsonSerializable()
class JobTagsModel {
JobTagsModel({required this.tagId, required this.tagName});
factory JobTagsModel.fromJson(Map<String, dynamic> json) =>
_$JobTagsModelFromJson(json);
@JsonKey(name: 'tagId')
final int tagId;
@JsonKey(name: 'tagName')
final String tagName;
@override
String toString() => 'JobTagsModel(tagId: $tagId, tagName: $tagName)';
Map<String, dynamic> toJson() => _$JobTagsModelToJson(this);
}
code to run the service in ui
Future<void> getTags() async {
try {
_viewModel.isLoading.value = true;
await registerService.getJobTags();
} catch (e) {
print("getTags hatası: $e");
} finally {
_viewModel.isLoading.value = false;
}
}
@override
void initState() {
super.initState();
getTags();
}
I want my api request to work, I don’t think there is a problem on the service side because I use the same service in another application without changing any code.