submit method
Creates a Submission
on the Subreddit.
title
is the title of the submission. selftext
is markdown formatted
content for a 'text' submission. Using '' will make a title-only
submission. url
is the URL for a 'link' submission. flairId
is the
flair template to select. If the template's 'flair_text_editable' value
is true, providing flairText
will set the custom text. When resubmit
is set to false, an error will occur if the URL has already been
submitted. When sendReplies
is true, messages will be sent to the
submission creator when comments are made on the submission.
Returns a Submission
for the newly created submission.
Implementation
Future<Submission> submit(String title,
{String? selftext,
String? url,
String? flairId,
String? flairText,
bool resubmit = true,
bool sendReplies = true,
bool nsfw = false,
bool spoiler = false}) async {
if ((selftext == null && url == null) ||
(selftext != null && url != null)) {
throw DRAWArgumentError('One of either selftext or url must be '
'provided');
}
final data = <String, String?>{
'api_type': 'json',
'sr': displayName,
'resubmit': resubmit.toString(),
'sendreplies': sendReplies.toString(),
'title': title,
'nsfw': nsfw.toString(),
'spoiler': spoiler.toString(),
};
if (flairId != null) {
data['flair_id'] = flairId;
}
if (flairText != null) {
data['flair_text'] = flairText;
}
if (selftext != null) {
data['kind'] = 'self';
data['text'] = selftext;
} else {
data['kind'] = 'link';
data['url'] = url;
}
return (await _throwOnInvalidSubreddit(
() async => await reddit.post(apiPath['submit'], data))
as Submission?)!;
}