luc sitzung
This commit is contained in:
@@ -1,45 +1,43 @@
|
||||
import 'dart:convert';
|
||||
// ignore_for_file: avoid_print
|
||||
|
||||
import 'dart:convert';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:fforte/other/db_helper.dart';
|
||||
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class Methods {
|
||||
String httpData;
|
||||
int? _errorCode;
|
||||
|
||||
Methods(this.httpData);
|
||||
|
||||
void httpRequest() async {
|
||||
int get errorCode => _errorCode ?? 0;
|
||||
|
||||
|
||||
Methods();
|
||||
|
||||
|
||||
|
||||
void httpRequest(String httpData) async {
|
||||
// print(jsonEncode(place));
|
||||
|
||||
final dio = Dio();
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
|
||||
dio.options.responseType = ResponseType.plain;
|
||||
Response response =
|
||||
Response(requestOptions: RequestOptions(path: ''), statusCode: 400);
|
||||
Response response = Response(requestOptions: RequestOptions(path: ''), statusCode: 400);
|
||||
|
||||
try {
|
||||
response = await dio.post(prefs.getString('apiAddress') ?? "",
|
||||
data: jsonEncode(httpData));
|
||||
// print(jsonEncode(httpData));
|
||||
} on DioException catch (e) {
|
||||
if (e.response?.statusCode == 500) {
|
||||
print('-------------------------');
|
||||
print('code 500');
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (response.statusCode == 201) {
|
||||
print("------------------");
|
||||
print(response.statusCode);
|
||||
var placeDB = DBHelper();
|
||||
|
||||
await placeDB.updateSent();
|
||||
} else {
|
||||
print("----------------");
|
||||
print("Anderer code");
|
||||
print(response.statusCode);
|
||||
// ignore: unused_catch_clause
|
||||
} on DioException catch (e) {
|
||||
_errorCode = response.statusCode;
|
||||
print('is hier. var: ${_errorCode}');
|
||||
return;
|
||||
}
|
||||
_errorCode = response.statusCode;
|
||||
print('is hier 2. var: ${_errorCode}');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user