Future voucherMember() async {
// Future.delayed(Duration(seconds: 1));
// Duration(seconds: 2);
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
email = sharedPreferences.getString('email').toString();
print('1.dart, method voucher member == $email'); // ini muncul emailnya..
try {
var response = await Dio().post('https://impostor.brainwarehub.com/api/vouchermember', data: {
'emailuser': email, //email dari shared preference
// cara dapetkan idmerchant???, sementara di hardcode
//gak usah pakek id merchant juga gpp... yg penting ada 1 parameter
// 'idmerchant': 2,
});
if (response.statusCode == 200) {
//=================================================================
//percobaan ke-1, dari chatgpt ==> Extract JSON Data
//update ==, percobaan ke-1, TAPI adaa looping FOR, jadi versi 1.1
//response.data['data'][0,1,2,3];
dataArray = response.data['data'];
for (var data in dataArray) {
print('Merchant Name: ${data['merchant_name']}');
// dataArray.add(data['merchant_name']);
// print('====');
final vouchers = data['vouchers'];
for (var voucher in vouchers) {
print('Voucher Label: ${voucher['label']}');
print('Voucher Code: ${voucher['kode_voucher']}');
print('Voucher Status: ${voucher['status']}');
print('Voucher Discount Type: ${voucher['disctype']}');
print('Voucher Validity: ${voucher['date_start']} to ${voucher['date_end']}');
}
}
}
} on DioException catch (exception) {
print(exception);
}
// return "kosong";
}