outsourced httpRequest method
This commit is contained in:
45
lib/other/methods.dart
Normal file
45
lib/other/methods.dart
Normal file
@@ -0,0 +1,45 @@
|
||||
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;
|
||||
|
||||
Methods(this.httpData);
|
||||
|
||||
void httpRequest() 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);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user