Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.8 kB
3
Indexable
Never
  Future<List<Datum>> viewOrderStatus(String status) async {
    try {
      var prefs = await SharedPreferences.getInstance();
      var tokenLogin = prefs.getString('apiKey');
      int? idMerchant = prefs.getInt('idMerchant');
      final url = OrderUrl.transactionOrderStatus +
          'transactions-order?status_prepared=$status&id_merchant=$idMerchant';
      final response = await http.get(Uri.parse(url), headers: {
        'Authorization': 'Bearer ${tokenLogin}',
      });
      // print("response body ${response.body}");
      if (response.statusCode == 200) {
        final jsonList = jsonDecode(response.body);
        final orderResponse = ResponseDisediakan.fromJson(jsonList);
        print("variabel order Response  ${orderResponse}");
        print("status order response ${orderResponse.isSuccess}");
        if (orderResponse.isSuccess) {
          print("data yang di return ${orderResponse.data.data}");
          return orderResponse.data.data;
        } else {
          throw Exception('Failed to load order data');
        }
      } else {
        throw Exception('Failed to load order data');
      }
    } catch (e) {
      throw Exception('Error fetching order data: $e');
    }
  }

Log : 
I/flutter (27831): Error BlocOrderStatus Exception: Error fetching order data: Null check operator used on a null value
I/flutter (27831): Letak Eror #0      ViewOrderStatus.viewOrderStatus (package:riderunnerfood/entity/repository/main_page/Order/view_order_status.dart:36:7)
I/flutter (27831): <asynchronous suspension>
I/flutter (27831): #1      BlocOrderStatus.getOrderData (package:riderunnerfood/bloc/login_page/Order/order_status.dart:63:11)
I/flutter (27831): <asynchronous suspension>
I/flutter (27831): akhir dari data order[]
I/flutter (27831): new Orders []
Leave a Comment