import 'dart:convert'; import 'package:provider/provider.dart'; import 'package:teso/Classes/Payload.dart'; import 'package:teso/providers/user_provider.dart'; import 'package:url_launcher/url_launcher.dart'; class NotificationSplitter { static Future getPayload(data, context) async { Payload payload = new Payload(); switch (data["notificationType"]) { case "chats": payload.loadID = "TESN004"; payload.load1 = data["senderID"]; payload.load2 = data["firstname"]; payload.load3 = data["surname"]; return payload; break; case "likes": Provider.of(context, listen: false).pullAds(); payload.loadID = "TESN000"; payload.load1 = data["post"]; return payload; break; case "comments": Provider.of(context, listen: false).pullAds(); payload.loadID = "TESN000"; payload.load1 = data["post"]; return payload; break; case "friendapproval": Provider.of(context, listen: false).loadFriends(); payload.loadID = "TESN000"; return payload; break; case "friendrequest": payload.loadID = "TESN000"; return payload; break; case "gifted": Provider.of(context, listen: false).getCoupons(); payload.loadID = "TESN000"; payload.load1 = data["couponID"]; return payload; break; case "cancellation": Provider.of(context, listen: false).getCoupons(); payload.loadID = "TESN000"; payload.load1 = data["couponID"]; return payload; break; case "personalized": payload.loadID = "TESN000"; payload.load1 = data["coupon"]; payload.load2 = data["notificationType"]; payload.load3 = data["documentRef"]; payload.load4 = data["couponCondition"]; payload.load5 = data["businessName"]; payload.load6 = data["originalPrice"]; payload.load7 = data["productName"]; return payload; break; case "campaign": var coup = jsonDecode(data["campaign"]); payload.loadID = "TESN005"; payload.load1 = coup["businessID"]; payload.load2 = coup["campaignID"]; payload.load3 = coup["campaignDescription"]; payload.load4 = coup["status"]; payload.load5 = coup["targetProduct"]; payload.load6 = coup["title"]; payload.load7 = coup["goldReward"].toString(); payload.load8 = coup["startDate"].toString(); return payload; break; case "reward": payload.loadID = "TESN0R0"; return payload; break; case "expired": Provider.of(context, listen: false).getCoupons(); payload.loadID = "TESN000"; payload.load1 = data["couponID"]; return payload; break; case "refund": Provider.of(context, listen: false).getUserInformation(); payload.loadID = "TESN000"; payload.load1 = data["couponID"]; return payload; break; case "coinpurchase": Provider.of(context, listen: false).getUserInformation(); payload.loadID = "TESN000"; payload.load1 = data["orderID"]; await closeWebView(); return payload; break; default: return payload; break; } } }