Skip to content

Exception has occurred. _TypeError (type 'ApiResponse' is not a subtype of type 'int?') #339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 14 additions & 18 deletions lib/api/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -217,34 +217,30 @@ class ApiSingleton {
}
}

Future<dynamic> createSession(Session session) async {
Future<int?> createSession(Session session) async {
try {
final response = await http
.post(Uri.parse('$serverUrl$sessions'),
headers: headers,
body: json.encode(
session.toJson(),
))
.timeout(
Duration(seconds: _timeoutTimerInSeconds),
onTimeout: () {
print('Request timed out');
return Future.error('Request timed out');
},
);
;

if (response.statusCode != 201) {
print(
'Request: ${response.request.toString()} -> Response: ${response.body}');
return ApiResponse.fromJson(json.decode(response.body));
.timeout(Duration(seconds: _timeoutTimerInSeconds));
if (response.statusCode == 201) {
var body = json.decode(response.body);
return body['id'] as int;
} else {
print("Error: Unexpected response code ${response.statusCode}");
print("Response body: ${response.body}");
}

var body = json.decode(response.body);
return body['id'];
} on TimeoutException {
print("Error: Request timed out.");
} on http.ClientException catch (e) {
print("HTTP Client Exception: $e");
} catch (e) {
return null;
print("Error : ${e}");
}
return null;
}

Future<dynamic> closeSession(Session session) async {
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/Utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class Utils {
session!.id = await ApiSingleton().createSession(session!);
}

if (session!.id != null) {
if (session?.id != null) {
var lang = await UserManager.getLanguage();
var userUUID = await UserManager.getUUID();
report = Report(
Expand Down