createCampaign function

Future<Campaign> createCampaign(
  1. String campaignName,
  2. String startDate,
  3. String endDate,
  4. String vendor,
)

Implementation

Future<Campaign> createCampaign(String campaignName, String startDate,
    String endDate, String vendor) async {
  HttpOverrides.global = new MyHttpOverrides();
  final response = await http.post(
    Uri.parse('https://192.168.1.106:45455/api/CampaignModels'),
    headers: <String, String>{
      'Content-Type': 'application/json; charset=UTF-8',
    },
    body: jsonEncode(<String, String>{
      'campaignName': campaignName,
      'startDate': startDate,
      'endDate': endDate,
      'vendor': vendor
    }),
  );

  if (response.statusCode == 201) {
    // If the server did return a 201 CREATED response,
    // then parse the JSON.
    return Campaign.fromJson(jsonDecode(response.body));
  } else {
    // If the server did not return a 201 CREATED response,
    // then throw an exception.
    throw Exception('Failed to create Campaign.');
  }
}