Advertisement
muhaiminurabir

conditional parameter api call flutter

Mar 25th, 2025
546
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.98 KB | None | 0 0
  1.  Future getUserDashboard(
  2.     String status,
  3.     String farmType,
  4.     String farmCategory,
  5.     String dateRange,
  6.   ) async {
  7.     try {
  8.       Map<String, String> params;
  9.       if (dateRange.isNotEmpty) {
  10.         params = {
  11.           "status": status,
  12.           "farm_type": farmType,
  13.           "farm_category": farmCategory,
  14.           "date_range": dateRange,
  15.         };
  16.       } else {
  17.         params = {
  18.           "status": status,
  19.           "farm_type": farmType,
  20.           "farm_category": farmCategory,
  21.         };
  22.       }
  23.       final response = await getDio()!.get(
  24.         ApiUrl.homeUserDashboard,
  25.         queryParameters: params,
  26.       );
  27.       _userDashboardResponse = UserDashboaredResponse.fromJson(response.data);
  28.       notifyListeners();
  29.     } on DioException catch (e) {
  30.       _resMessage = e.message.toString();
  31.       Log().printError(_resMessage);
  32.       notifyListeners();
  33.       Log().showMessageToast(message: AppInterceptors.handleError(e));
  34.     }
  35.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement