createServiceVariation function

Future<ServiceVariation> createServiceVariation(
  1. String variationName,
  2. String vendor,
  3. String control
)

Implementation

Future<ServiceVariation> createServiceVariation(
    String variationName, String vendor, String control) async {
  HttpOverrides.global = new MyHttpOverrides();
  final response = await http.post(
    Uri.parse('https://192.168.1.106:45455/api/ServiceVariationsModels'),
    headers: <String, String>{
      'Content-Type': 'application/json; charset=UTF-8',
    },
    body: jsonEncode(<String, String>{
      'variationName': variationName,
      'vendor': vendor,
      'control': control
    }),
  );

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