Skip to content
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

Not printing header/data #217

Open
satishs22 opened this issue Apr 5, 2024 · 2 comments
Open

Not printing header/data #217

satishs22 opened this issue Apr 5, 2024 · 2 comments

Comments

@satishs22
Copy link

satishs22 commented Apr 5, 2024

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):

  • Mac

Smartphone (please complete the following information):

  • Android 13

Additional context
Add any other context about the problem here.

@silvershort
Copy link

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

@satishs22
Copy link
Author

satishs22 commented Apr 9, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants