// ignore_for_file: avoid_print

import 'dart:convert';
import 'package:dio/dio.dart';

import 'package:shared_preferences/shared_preferences.dart';

class HttpRequest {
  int? _errorCode;


  int get errorCode => _errorCode ?? 0;


  Future<void> httpRequest(String httpData) async {
    // print(jsonEncode(place));

    final dio = Dio();
    final SharedPreferences prefs = await SharedPreferences.getInstance();

    dio.options
    ..connectTimeout = const Duration(seconds: 5)
    ..receiveTimeout = const Duration(seconds: 5)
    ..responseType = ResponseType.plain;
    Response response = Response(requestOptions: RequestOptions(path: ''), statusCode: 400);

    try {
      response = await dio.post(prefs.getString('apiAddress') ?? "",
          data: jsonEncode(httpData));

    // 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');
  }
}


