send method

  1. @override
Future<Response> send({
  1. required String id,
  2. required String apiKey,
  3. required String title,
  4. required String body,
  5. String? url,
  6. String? image,
  7. double imageElevation = 0.0,
  8. Color? backgroundColor,
  9. Color? textColor,
})
override

Implementation

@override
Future<http.Response> send({
  required String id,
  required String apiKey,
  required String title,
  required String body,
  String? url,
  String? image,
  double imageElevation = 0.0,
  Color? backgroundColor,
  Color? textColor,
}) async {
  /**
   * Mandatory parameters
   */
  if (id.isEmpty) {
    throw ('not valid id');
  } else if (apiKey.isEmpty) {
    throw ('not valid apiKey');
  } else if (title.isEmpty) {
    throw ('not valid title');
  } else if (body.isEmpty) {
    throw ('not valid body');
  }

  /**
   * Optional parameters
   */
  if (url != null && url.isEmpty) {
    throw ('not valid url');
  } else if (image != null && image.isEmpty) {
    throw ('not valid url');
  }

  backgroundColor ??= Colors.teal;
  var bgColor = '#${backgroundColor.value.toRadixString(16).substring(2, 8)}';

  textColor ??= Colors.white;
  var tColor = '#${textColor.value.toRadixString(16).substring(2, 8)}';

  return execute('send', <String, dynamic>{
    'id': id,
    'api_key': apiKey,
    'title': title,
    'body': body,
    'url': url,
    'image': image,
    'image_elevation': imageElevation,
    'background_color': bgColor,
    'text_color': tColor,
  });
}