Frezyx / talker

☎️ Advanced error handler and logger for dart and flutter apps
https://pub.dev/packages/talker
MIT License
478 stars 57 forks source link

Not printing header/data #217

Open satishs22 opened 5 months ago

satishs22 commented 5 months ago

Describe the bug The log is not printing header or data when form data is being passed.

To Reproduce Steps to reproduce the behavior:

 Future<void> addLeave({
    required BuildContext context,
    required String token,
    required User userData,
    required Employee employee,
    required String employeeLeaveType,
    required String employeeID,
    required String start_date,
    required String end_date,
    required String leave_reason,
    required String is_half,
    required String halfday_type,
    required String leaveEntitleLeaveID,
    required List<File>? receipt,
  }) async {
      List<dio.MultipartFile> newList = [];
      for (int i = 0; i < (receipt?.length ?? 0); i++) {
        var multipartFile = await dio.MultipartFile.fromFile(receipt![i].path,
            filename: 'medicalCertificate[]');

        newList.add(multipartFile);
      }

      dio.FormData data = dio.FormData.fromMap({
        'employeeLeaveType': employeeLeaveType,
        'employeeID': employeeID,
        'start_date': start_date,
        'end_date': end_date,
        'leave_reason': leave_reason,
        'is_half': is_half,
        'halfday_type': halfday_type,
        'leaveEntitleLeaveID': leaveEntitleLeaveID,
        'medicalCertificate': newList,
      });

      print(data.fields);
      print(data.files);
      final response = await post(
        '/leave/store',
        data: data,
        printRequestData: true,
        printResponseData: true,
      );

      Navigator.pushAndRemoveUntil(
          context,
          MaterialPageRoute(
              builder: (context) => CustomNavigationBar(
                userdata: userData,
                token: token,
                employee: employee,
                currentIndex: 1,
              )),
              (Route<dynamic> route) => false);

  }

Expected behavior Suppose be printing header/form data

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context Add any other context about the problem here.

silvershort commented 5 months ago

If you added a TalkerDioLogger to dio interceptor, check to passed a talker instance in the 'talker' parameter.

satishs22 commented 5 months ago

static talkerInit() {
    final talker = TalkerFlutter.init(
      settings: TalkerSettings(
        colors: {
          TalkerLogType.verbose: AnsiPen()..yellow(),
        },
      ),
    );
    DI.registerSingleton<Talker>(talker);
    talker.verbose('Talker initialization completed');
  }

  post(
    String path, {
    dynamic data,
    Map<String, dynamic>? queryParameters,
    Options? options,
    bool isRaw = false,
    bool isShowLoading = false,
    String? loadingText = "Loading",
    VFMAnimationType? loadingAnimation = VFMAnimationType.circular,
    String? lottieLoadingAsset = "",
    bool isShowResultDialog = false,
    String? message,
    bool printResponseData = false,
    bool printResponseHeaders = false,
    bool printRequestData = true,
    bool printRequestHeaders = true,
  }) async {
    dio.interceptors.clear();
    dio.interceptors.add(customInterceptors(
        isShowLoading, loadingText!, loadingAnimation!, lottieLoadingAsset!));
    dio.interceptors.add(customTalker(
      printResponseHeaders: printRequestHeaders,
      printRequestHeaders: printRequestHeaders,
      printRequestData: printRequestData,
      printResponseData: printResponseData,
    ));
    dio.options.baseUrl = isRaw ? path : baseUrl;
    Options requestOptions = options ?? Options();
    requestOptions.headers = requestOptions.headers ?? {};
    Map<String, dynamic>? authorization = getAuthorizationHeader();
    if (authorization != null) {
      requestOptions.headers!.addAll(authorization);
    }
    var response = await dio.post(
      path,
      data: data,
      queryParameters: queryParameters,
      options: requestOptions,
      cancelToken: cancelToken,
    );
    dio.options.baseUrl = baseUrl;
    return response.data;
  }

TalkerDioLogger customTalker({
  bool printResponseData = false,
  bool printResponseHeaders = false,
  bool printRequestData = true,
  bool printRequestHeaders = true,
}) =>
    TalkerDioLogger(
      talker: DI.get<Talker>(),
      settings: TalkerDioLoggerSettings(
        printResponseData: printResponseData,
        printResponseHeaders: printResponseHeaders,
        printRequestData: printRequestData,
        printRequestHeaders: printRequestHeaders,
      ),
    );

as you can see I added a talker instance, this issue only happens when form data is being pass, it works if normal json data is being pass @silvershort